]> git.lizzy.rs Git - dragonstd.git/blobdiff - flag.h
Add flag_sub and flag_uns
[dragonstd.git] / flag.h
diff --git a/flag.h b/flag.h
index 78c5ac14e91b51d58f7e4ac46bf666e0c5776cf0..ba6a859e644a91ec449d5d7f0b9f9a3f258f0549 100644 (file)
--- a/flag.h
+++ b/flag.h
 #include <pthread.h>   // for pthread_mutex_t, pthread_cond_t
 #include <stdatomic.h> // for atomic_bool
 #include <stdbool.h>   // for bool
+#include "list.h"      // for List
 
 typedef struct {
        /* protected */
        atomic_bool set;     // whether the flag is set
        /* private */
-       pthread_cond_t cnd;  // condition variable used for waiting
-       pthread_mutex_t mtx; // mutex to protect the condition variable
+       pthread_cond_t cnd;  // main condition variable
+       pthread_mutex_t mtx; // mutex to protect the main condition variable
+       List cvs;            // condition variables
 } Flag;
 
 void flag_ini(Flag *flag);
@@ -38,6 +40,22 @@ void flag_dst(Flag *flag);
        The refcount is unusable until reinitialized afterwards.
 */
 
+void flag_sub(Flag *flag, pthread_cond_t *cnd);
+/*
+       [Thread Safe]
+       Subscribe condition variable cnd to flag.
+
+       The condition variable will be triggered when the flag is set.
+*/
+
+void flag_uns(Flag *flag, pthread_cond_t *cnd);
+/*
+       [Thread Safe]
+       Unsubscribe condition variable cnd from flag.
+
+       The condition variable will no longer be triggered when the flag is set.
+*/
+
 void flag_set(Flag *flag);
 /*
        [Thread Safe]