1 #ifndef __PTHREAD_EXTRA_H__
2 #define __PTHREAD_EXTRA_H__
10 #define PTHREAD_XTIME_NOBLOCK (&(struct timespec){ .tv_sec = 0, .tv_nsec = 0 })
11 #define PTHREAD_XTIME_FOREVER NULL
15 #define PTHREAD_XTHREADS_MAX 65535
16 #define PTHREAD_XNULL ((pthread_t)NULL)
18 #ifdef __PTHREAD_EXTRA_INTERNAL
19 typedef struct pthread_user_data_internal_t
{
20 pthread_t tid
; //Thread ID
21 void *usr
; //User pointer
22 //Internaly used members:
23 sig_atomic_t running
; //pthread_pause
24 } pthread_user_data_internal_t
;
26 pthread_user_data_internal_t
* pthread_user_data_internal(pthread_t thread
);
27 int pthread_user_data_lock();
28 int pthread_user_data_unlock();
29 #endif //__PTHREAD_EXTRA_INTERNAL
31 void** pthread_user_data_ptr(pthread_t thread
);
32 void* pthread_user_data_get(pthread_t thread
);
33 void pthread_user_data_set(pthread_t thread
, void *usr
);
34 void pthread_user_data_cleanup(void * arg
);
35 int pthread_user_data_internal_iterate(int (*routine
)(pthread_t
), void *arg
);
39 //GDB: handle SIG34 nostop noprint
40 #define PTHREAD_XSIG_STOP (SIGRTMIN+0)
41 #define PTHREAD_XSIG_CONT (SIGRTMIN+1)
42 #define PTHREAD_XSIGRTMIN (SIGRTMIN+2) //First unused RT signal
44 int pthread_extra_create(pthread_t
*restrict thread
,
45 const pthread_attr_t
*restrict attr
,
46 void *(*start_routine
)(void *),
48 void pthread_unpause_handler();
49 void pthread_pause_handler();
50 void pthread_pause_enable();
51 void pthread_pause_disable();
52 int pthread_pause(pthread_t thread
);
53 int pthread_unpause(pthread_t thread
);
54 int pthread_pause_all();
55 int pthread_unpause_all();
56 int pthread_pause_reschedule(pthread_t thread
);
57 int pthread_extra_yield();
59 // Pause compatible sleeps
61 void pthread_nanosleep(struct timespec t
);
62 void pthread_nsleep(time_t s
, long ns
);
63 void pthread_sleep(time_t s
);
68 typedef uint8_t pthread_mq_flags_t
;
69 #define PTHREAD_XMQ_NONE 0 ///< No flags specified (default behaviour)
70 #define PTHREAD_XMQ_FRONT 1 ///< Send to front of the queue (scheduled for next receive)
71 #define PTHREAD_XMQ_BACK PTHREAD_XMQ_NONE ///< Send to back of the queue (default)
72 #define PTHREAD_XMQ_PEEK 2 ///< Only peek, do not remove received item
73 #define PTHREAD_XMQ_RECV PTHREAD_XMQ_NONE ///< Remove received item from queue (default)
74 #define PTHREAD_XMQ_OVERW 4 ///< Overwrite item if queue full
76 typedef struct pthread_mq_t
{
78 pthread_cond_t cond_readable
;
79 pthread_cond_t cond_writable
;
88 bool pthread_mq_init(pthread_mq_t
*mq
, size_t msg_size
, size_t msg_count_max
);
89 void pthread_mq_free(pthread_mq_t
*mq
);
91 bool pthread_mq_reset(pthread_mq_t
*mq
);
92 bool pthread_mq_send_generic(pthread_mq_t
*mq
, void * data
, pthread_mq_flags_t flags
, const struct timespec
*restrict abs_timeout
);
93 bool pthread_mq_receive_generic(pthread_mq_t
*mq
, void * data
, pthread_mq_flags_t flags
, const struct timespec
*restrict abs_timeout
);
95 size_t pthread_mq_waiting(pthread_mq_t
*mq
);
96 size_t pthread_mq_vacant(pthread_mq_t
*mq
);
98 // Multi mutex locking
100 #define pthread_mutex_swap(a, b) { pthread_mutex_t *s; s = (a); a = (b); b = s; }
102 #define pthread_mutex_lock_two(a,b) pthread_mutex_timedlock_multi_generic((pthread_mutex_t *[2]){(a), (b)}, 2, true, NULL)
103 #define pthread_mutex_timedlock_two(a,b,tm) pthread_mutex_timedlock_multi_generic((pthread_mutex_t *[2]){(a), (b)}, 2, true, (tm))
104 #define pthread_mutex_trylock_two(a,b) pthread_mutex_timedlock_multi_generic((pthread_mutex_t *[2]){(a), (b)}, 2, false, NULL)
106 #define pthread_mutex_lock_multi(lcks,cnt) pthread_mutex_timedlock_multi_generic((lcks),(cnt),true,NULL)
107 #define pthread_mutex_timedlock_multi(lcks,cnt,tm) pthread_mutex_timedlock_multi_generic((lcks),(cnt),true,(tm))
108 #define pthread_mutex_trylock_multi(lcks,cnt) pthread_mutex_timedlock_multi_generic((lcks),(cnt),false,NULL)
110 int pthread_mutex_timedlock_multi_generic(pthread_mutex_t
**lck
, int cnt
, bool block
, const struct timespec
*restrict abs_timeout
);
113 #endif //__PTHREAD_EXTRA_H__