3.3. Threads utilitiesΒΆ
Thread utilities functions.
DefinesTypedefsTHREAD_CANCELED
Thread return value when canceled.
MUTEX_INIT
Mutex static initializer.
RWLOCK_INIT
Read-write lock static initializer.
Enumstypedef pthread_t thread_t
Opaque thread type.
typedef pthread_mutex_t mutex_t
Opaque mutex type.
typedef pthread_spinlock_t spinlock_t
Opaque spinlock type.
typedef pthread_rwlock_t rwlock_t
Opaque read-write lock type.
typedef sem_t semaphore_t
Opaque semaphore type.
typedef pthread_barrier_t barrier_t
Opaque barrier type.
typedef pthread_key_t local_storage_t
Opaque local storage type.
typedef uint32 atomic_t
32 bit atomic opaque type.
typedef uint64 atomic64_t
64 bit atomic opaque type.
Functionsthread_cancel_t enum
Thread cancel mode.
Values:
- THREAD_CANCEL_DEFERRED -
Deferred mode.
- THREAD_CANCEL_ASYNCHRONOUS -
Asynchronous mode.
int thread_get_packet_capture_cpu_count()Get the number of thread to be used by the application for packet capture.
void thread_set_packet_capture_cpu_count(int count)Set the number of thread to be used by the application for packet capture.
- Parameters
- count -
Number of thread to use for capture.
int thread_get_cpu_count()Get the number of CPUs.
Start a new thread.
thread_t thread_current()Get the current thread.
Join a thread.
Cancel a running thread.
int thread_getid()Get current thread id.
void thread_setid(int id)Set current thread id.
- Parameters
- id -
New thread identifier.
bool thread_sigmask(int how, sigset_t * set, sigset_t * oldset)Set signal mask on a thread.
Send a signal to the given thread.
Change thread support for cancel.
bool thread_setcanceltype(enum thread_cancel_t type)Change thread cancel mode.
void thread_testcancel()Check for cancel.
void thread_protect(void(*)(void *) run, void * runarg, void(*)(void *) finish, void * finisharg)Run a function in protected mode. If a cancel is raised, then a cleanup function is called before leaving the thread.
thread_t thread_main()Get the main thread handle.
thread_t thread_self()Get the current thread.
Check if two threads are the same.
Raise a signal on the given thread.
bool spinlock_init(spinlock_t * lock)bool spinlock_destroy(spinlock_t * lock)bool spinlock_lock(spinlock_t * lock)bool spinlock_trylock(spinlock_t * lock)bool spinlock_unlock(spinlock_t * lock)
bool semaphore_destroy(semaphore_t * semaphore)bool semaphore_wait(semaphore_t * semaphore)bool semaphore_post(semaphore_t * semaphore)
bool local_storage_init(local_storage_t * key, void(*)(void *) destructor)Initialize thread local storage. The parameter destructor allows to set a cleanup function to call when the storage is destroyed.
- Return
- True on success. Use clear_error() to get details about the error.
bool local_storage_destroy(local_storage_t * key)Destroy a thread local storage.
- Return
- True on success. Use clear_error() to get details about the error.
void * local_storage_get(local_storage_t * key)Get the value of the thread local storage.
- Return
- The value associated with the current thread.
bool local_storage_set(local_storage_t * key, const void * value)Set the value of the thread local storage.
- Return
- True on success. Use clear_error() to get details about the error.
Increment an atomic counter.
- Return
- The new value after increment.
Decrement an atomic counter.
- Return
- The new value after decrement.
Get the value of an atomic counter.
Set the current value of an atomic counter.
INLINE void atomic64_set(atomic64_t * v, uint64 x)Set the current value of a 64 bit atomic counter.
INLINE void atomic64_init(atomic64_t * v, uint64 x)Initialize a 64 bit atomic counter.
INLINE void atomic64_destroy(atomic64_t * v)Destroy a 64 bit atomic counter.
INLINE uint64 atomic64_inc(atomic64_t * v)Increment a 64 bit atomic counter.
- Return
- The new value after increment.
INLINE uint64 atomic64_dec(atomic64_t * v)Decrement a 64 bit atomic counter.
- Return
- The new value after decrement.
INLINE uint64 atomic64_get(atomic64_t * v)Get the value of a 64 bit atomic counter.