]> git.lizzy.rs Git - dragonstd.git/blob - flag.c
Fix typo in refcount.h
[dragonstd.git] / flag.c
1 #include "flag.h"
2
3 void flag_ini(Flag *flag)
4 {
5         flag->set = false;
6         pthread_cond_init(&flag->cnd, NULL);
7         pthread_mutex_init(&flag->mtx, NULL);
8 }
9
10 void flag_dst(Flag *flag)
11 {
12         pthread_cond_destroy(&flag->cnd);
13         pthread_mutex_destroy(&flag->mtx);
14 }
15
16 void flag_set(Flag *flag)
17 {
18         pthread_mutex_lock(&flag->mtx);
19         flag->set = true;
20         pthread_cond_broadcast(&flag->cnd);
21         pthread_mutex_unlock(&flag->mtx);
22 }
23
24 void flag_slp(Flag *flag)
25 {
26         pthread_mutex_lock(&flag->mtx);
27         if (! flag->set)
28                 pthread_cond_wait(&flag->cnd, &flag->mtx);
29         pthread_mutex_unlock(&flag->mtx);
30 }