Back to index

glibc  2.9
Functions
pspinlock.c File Reference
#include <errno.h>
#include <pthread.h>
#include "internals.h"

Go to the source code of this file.

Functions

int __pthread_spin_lock (pthread_spinlock_t *lock)
 weak_alias (__pthread_spin_lock, pthread_spin_lock)
 weak_alias (__pthread_spin_trylock, pthread_spin_trylock)
 weak_alias (__pthread_spin_unlock, pthread_spin_unlock)
 weak_alias (__pthread_spin_init, pthread_spin_init)

Function Documentation

int __pthread_spin_lock ( pthread_spinlock_t *  lock)

Definition at line 34 of file pspinlock.c.

{
  asm volatile
    ("\n"
     "1:\n\t"
     "lock; decl %0\n\t"
     "js 2f\n\t"
     ".section .text.spinlock,\"ax\"\n"
     "2:\n\t"
     "cmpl $0,%0\n\t"
     "rep; nop\n\t"
     "jle 2b\n\t"
     "jmp 1b\n\t"
     ".previous"
     : "=m" (*lock));
  return 0;
}

Definition at line 51 of file pspinlock.c.

{
  int oldval;

  asm volatile
    ("xchgl %0,%1"
     : "=r" (oldval), "=m" (*lock)
     : "0" (0));
  return oldval > 0 ? 0 : EBUSY;
}

Definition at line 65 of file pspinlock.c.

{
  asm volatile
    ("movl $1,%0"
     : "=m" (*lock));
  return 0;
}

Definition at line 76 of file pspinlock.c.

{
  /* We can ignore the `pshared' parameter.  Since we are busy-waiting
     all processes which can access the memory location `lock' points
     to can use the spinlock.  */
  *lock = 1;
  return 0;
}

Definition at line 88 of file pspinlock.c.

{
  /* Nothing to do.  */
  return 0;
}