Product SiteDocumentation Site

Name

tc_mutex_init, tc_mutex_lock, tc_mutex_unlock, tc_mutex_destroy, tc_mutex_trylock — libtcr mutex functions

Synopsis

#include <tc/threaded_cr.h>

void tc_mutex_init(struct tc_mutex *m);

enum tc_rv tc_mutex_lock(struct tc_mutex *m);

void tc_mutex_unlock(struct tc_mutex *m);

enum tc_rv tc_mutex_trylock(struct tc_mutex *m);

void tc_mutex_destroy(struct tc_mutex *m);

Description

A struct tc_mutex objects needs to be initialized by a call to tc_mutex_init() before it might be passed to any of the other tc_mutex_*() functions. It might not be used after destruction with a call to tc_mutex_destroy().
A call to tc_mutex_lock() locks the mutex, and returns immediately if the mutex was unlocked before. If the mutex was locked, the call blocks until the mutex gets unlocked by an other tc_thread. I.e. only one tc_thread can hold the mutex lock at a time.
tc_mutex_unlock() unlocks a mutex, thus may allow an other tc_thread to proceed.
tc_mutex_trylock() locks unlocked mutexes, and always returns immediately.

Return value

tc_mutex_lock() returns RV_OK upon successful acquisition of the lock and RV_INTR if the call was interrupted by a tc_signal.
tc_mutex_trylock() returns RV_OK upon successful acquisition of the lock and RV_FAILED if the mutex is already locked.

Author

Philipp Reisner