1 #define __PTHREAD_EXTRA_INTERNAL
4 #include <pthread_extra.h>
6 //Static array with user data for all thread handles
7 //TODO: perhaps use something more sophisticated like linked list?
8 pthread_user_data_internal_t pthread_user_data
[PTHREAD_XTHREADS_MAX
+1] = {{.tid
=PTHREAD_XNULL
}};
10 //Get pointer to internal record tied to specified thread
11 pthread_user_data_internal_t
* pthread_user_data_internal(pthread_t thread
) {
12 //Return NULL if requested thread handle is NULL
13 if(pthread_equal(thread
, PTHREAD_XNULL
)) return NULL
;
15 //Find if the thread is already registered, add it if not
16 //FIXME: recycle slots of destroyed threads!!!
18 for(i
= 0; i
<PTHREAD_XTHREADS_MAX
; i
++) {
19 if(pthread_equal(pthread_user_data
[i
].tid
, PTHREAD_XNULL
)) {
20 pthread_user_data
[i
].tid
= thread
;
21 pthread_user_data
[i
+1].tid
= PTHREAD_XNULL
;
24 if(pthread_equal(pthread_user_data
[i
].tid
, thread
)) break;
27 return &pthread_user_data
[i
];
30 //Get pointer to user specified pointer of that thread
31 void** pthread_user_data_ptr(pthread_t thread
) {
32 return &pthread_user_data_internal(thread
)->usr
;
35 //Set user specified pointer for thread
36 void pthread_user_data_set(pthread_t thread
, void *usr
) {
37 *(pthread_user_data_ptr(thread
)) = usr
;
40 //Get user specified pointer for thread
41 void* pthread_user_data_get(pthread_t thread
) {
42 return *(pthread_user_data_ptr(thread
));