]> git.lizzy.rs Git - dragonstd.git/blobdiff - flag.c
Add flag_sub and flag_uns
[dragonstd.git] / flag.c
diff --git a/flag.c b/flag.c
index 9cc386dd81d50c0e3f1b2a376caf4e8d65d32f56..a8bb87888f5ee67f3b7752f80269718fe1d108ea 100644 (file)
--- a/flag.c
+++ b/flag.c
@@ -5,19 +5,39 @@ void flag_ini(Flag *flag)
        flag->set = false;
        pthread_cond_init(&flag->cnd, NULL);
        pthread_mutex_init(&flag->mtx, NULL);
+       list_ini(&flag->cvs);
+       flag_sub(flag, &flag->cnd);
 }
 
 void flag_dst(Flag *flag)
 {
        pthread_cond_destroy(&flag->cnd);
        pthread_mutex_destroy(&flag->mtx);
+       list_clr(&flag->cvs, NULL, NULL, NULL);
+}
+
+void flag_sub(Flag *flag, pthread_cond_t *cnd)
+{
+       pthread_mutex_lock(&flag->mtx);
+       list_add(&flag->cvs, cnd, &cmp_ref, NULL);
+       pthread_mutex_unlock(&flag->mtx);
+}
+
+void flag_uns(Flag *flag, pthread_cond_t *cnd)
+{
+       pthread_mutex_lock(&flag->mtx);
+       list_del(&flag->cvs, cnd, &cmp_ref, NULL);
+       pthread_mutex_unlock(&flag->mtx);
 }
 
 void flag_set(Flag *flag)
 {
        pthread_mutex_lock(&flag->mtx);
        flag->set = true;
-       pthread_cond_broadcast(&flag->cnd);
+
+       LIST_ITERATE(&flag->cvs, node)
+               pthread_cond_broadcast(node->dat);
+
        pthread_mutex_unlock(&flag->mtx);
 }