pthread_pause pthread_unpause
[mirrors/Programs.git] / c / pthread_extra / pthread_extra.h
index 84cba0654b60d7aa7ee5d018440fcf0589f151b0..bd1baad3b8e1270495b616ccd1b458fe568fd761 100644 (file)
@@ -5,10 +5,24 @@
 #include <time.h>
 #include <stdbool.h>
 #include <stdint.h>
+#include <signal.h>
 
 #define PTHREAD_XTIME_NOBLOCK (&(struct timespec){ .tv_sec = 0, .tv_nsec = 0 })
 #define PTHREAD_XTIME_FOREVER NULL
 
+//Pausing
+
+#define PTHREAD_XSIG_STOP (SIGRTMIN+0)
+#define PTHREAD_XSIG_CONT (SIGRTMIN+1)
+#define PTHREAD_XSIGRTMIN (SIGRTMIN+2) //First unused RT signal
+
+#define pthread_pause(t)   (pthread_kill((t), PTHREAD_XSIG_STOP));
+#define pthread_unpause(t) (pthread_kill((t), PTHREAD_XSIG_CONT));
+
+void pthread_unpause_handler();
+void pthread_pause_handler();
+void pthread_pause_enable();
+
 // Message queues
 
 #define PTHREAD_XMQ_FRONT true
@@ -21,7 +35,7 @@ typedef struct pthread_mq_t {
        pthread_mutex_t lock;
        pthread_cond_t cond_readable;
        pthread_cond_t cond_writable;
-       void * data;
+       uint8_t * data;
        size_t msg_size;
        size_t msg_count;
        size_t msg_count_max;
@@ -38,7 +52,7 @@ bool pthread_mq_receive_generic(pthread_mq_t *mq, void * data, bool peek, const
 
 // Multi mutex locking
 
-#define pthread_mutex_swap(a, b) ({ pthread_mutex_t *s; s = (a); a = (b); b = s; })
+#define pthread_mutex_swap(a, b) { pthread_mutex_t *s; s = (a); a = (b); b = s; }
 
 #define pthread_mutex_lock_two(a,b) pthread_mutex_timedlock_multi_generic((pthread_mutex_t *[2]){(a), (b)}, 2, true, NULL)
 #define pthread_mutex_timedlock_two(a,b,tm) pthread_mutex_timedlock_multi_generic((pthread_mutex_t *[2]){(a), (b)}, 2, true, (tm))
This page took 0.140834 seconds and 4 git commands to generate.