Loading...
Searching...
No Matches
pthread_spin.h File Reference

Spin locks. More...

Detailed Description

Spin locks.

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...
 
int pthread_spin_init (pthread_spinlock_t *lock, int pshared)
 Initializes a spinlock.
 
int pthread_spin_destroy (pthread_spinlock_t *lock)
 Destroys a spinlock.
 
int pthread_spin_lock (pthread_spinlock_t *lock)
 Lock a spinlock.
 
int pthread_spin_trylock (pthread_spinlock_t *lock)
 Tries to lock a spinlock, returns immediately if already locked.
 
int pthread_spin_unlock (pthread_spinlock_t *lock)
 Releases a spinlock.
 

Function Documentation

◆ pthread_spin_destroy()

int pthread_spin_destroy ( pthread_spinlock_t lock)

Destroys a spinlock.

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 
)

Initializes a spinlock.

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)

Lock a spinlock.

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)

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

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)

Releases a spinlock.

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.