pthread_spin.h File Reference

Spin locks. More...

Detailed Description

Note
Do not include this header file directly, but pthread.h.
Warning
Spinlocks should be avoided. They will burn away the battery needlessly, and may not work because RIOT is tickless. Use irq_disable() and irq_restore() for shortterm locks instead.

Definition in file pthread_spin.h.

#include <stdatomic.h>
+ Include dependency graph for pthread_spin.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  pthread_spinlock_t
 A spinlock. More...
 

Functions

int pthread_spin_init (pthread_spinlock_t *lock, int pshared)
 Intializes a spinlock. More...
 
int pthread_spin_destroy (pthread_spinlock_t *lock)
 Destroys a spinlock. More...
 
int pthread_spin_lock (pthread_spinlock_t *lock)
 Lock a spinlock. More...
 
int pthread_spin_trylock (pthread_spinlock_t *lock)
 Tries to lock a spinlock, returns immediately if already locked. More...
 
int pthread_spin_unlock (pthread_spinlock_t *lock)
 Releases a spinlock. More...
 

Function Documentation

◆ pthread_spin_destroy()

int pthread_spin_destroy ( pthread_spinlock_t lock)
Warning
See the warning in pthread_spinlock_t.

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

Parameters
[in,out]lockDatum to destroy.
Returns
0 on success. EINVAL if lock == NULL.

◆ pthread_spin_init()

int pthread_spin_init ( pthread_spinlock_t lock,
int  pshared 
)
Warning
See the warning in pthread_spinlock_t.

A zeroed out datum is initialized.

Parameters
[in,out]lockDatum to initialize.
[in]psharedUnused.
Returns
0 on success. EINVAL if lock == NULL.

◆ pthread_spin_lock()

int pthread_spin_lock ( pthread_spinlock_t lock)
Warning
See the warning in pthread_spinlock_t.
Parameters
[in,out]lockLock to acquire.
Returns
0 on success. EINVAL if lock == NULL.

◆ pthread_spin_trylock()

int pthread_spin_trylock ( pthread_spinlock_t lock)
Warning
See the warning in pthread_spinlock_t.
Parameters
[in,out]lockLock to acquire.
Returns
0 on success. EBUSY if the lock was already locked. EINVAL if lock == NULL.

◆ pthread_spin_unlock()

int pthread_spin_unlock ( pthread_spinlock_t lock)
Warning
See the warning in pthread_spinlock_t.
Parameters
[in,out]lockLock to release
Returns
0 on success. EPERM if the lock was not locked. EINVAL if lock == NULL.