4 mutex.c - Imager's mutex API.
18 CRITICAL_SECTION section;
23 =category Mutex functions
24 =synopsis i_mutex_t m = i_mutex_new();
29 If a critical section cannot be created for whatever reason, Imager
39 m = malloc(sizeof(*m));
41 i_fatal(3, "Cannot allocate mutex object");
42 InitializeCriticalSection(&(m->section));
48 =item i_mutex_destroy(m)
49 =category Mutex functions
50 =synopsis i_mutex_destroy(m);
58 i_mutex_destroy(i_mutex_t m) {
59 DeleteCriticalSection(&(m->section));
65 =category Mutex functions
66 =synopsis i_mutex_lock(m);
68 Lock the mutex, waiting if another thread has the mutex locked.
74 i_mutex_lock(i_mutex_t m) {
75 EnterCriticalSection(&(m->section));
79 =item i_mutex_unlock(m)
80 =category Mutex functions
81 =synopsis i_mutex_unlock(m);
85 The behavior of releasing a mutex you don't hold is unspecified.
91 i_mutex_unlock(i_mutex_t m) {
92 LeaveCriticalSection(&(m->section));