pthread_spin.h

Spin locks.

Note

Do not include this header file directly, but pthread.h.

int pthread_spin_init(pthread_spinlock_t * lock, int pshared)

Intializes a spinlock.

A zeroed out datum is initialized.

Parameters

lock:Datum to initialize.
pshared:Unused.

Return values

  • 0 on success. EINVAL if lock == NULL.
int pthread_spin_destroy(pthread_spinlock_t * lock)

Destroys a spinlock.

Destroying a spinlock while a thread is waiting for it causes undefined behavior. This is a no-op.

Parameters

lock:Datum to destroy.

Return values

  • 0 on success. EINVAL if lock == NULL.
int pthread_spin_lock(pthread_spinlock_t * lock)

Lock a spinlock.

Parameters

lock:Lock to acquire.

Return values

  • 0 on success. EINVAL if lock == NULL.
int pthread_spin_trylock(pthread_spinlock_t * lock)

Tries to lock a spinlock, returns immediately if already locked.

Parameters

lock:Lock to acquire.

Return values

  • 0 on success. EBUSY if the lock was already locked. EINVAL if lock == NULL.
int pthread_spin_unlock(pthread_spinlock_t * lock)

Releases a spinlock.

Parameters

lock:Lock to release

Return values

  • 0 on success. EPERM if the lock was not locked. EINVAL if lock == NULL.
struct pthread_spinlock_t

A spinlock.

atomic_flag flag

Current lock state.