Yalu X. schrieb:
> Wieso willst du __STDC_NO_THREADS__ undefinen? Meinst du, wenn du es
> undefinest, ist der Thread-Support auf einmal da? ;-)
Nein, ich kümmere mich da ja darum, dass die Funktionen nachher zur
Verfügung stehen. Bis jetzt habe ich folgendes:
1 | #if !defined(THREAD_FALLBACK) && defined(__STDC_NO_THREADS__)
|
2 | #define THREAD_FALLBACK
|
3 | //#ifdef __STDC_NO_THREADS__
|
4 | //#undef __STDC_NO_THREADS__
|
5 |
|
6 | #include <pthread.h>
|
7 | #include <errno.h>
|
8 |
|
9 | #define thrd_t pthread_t
|
10 | #define thrd_create( thr, func, arg ) pthread_create( thr, 0x0, func, arg )
|
11 | #define thrd_equal( lhs, rhs ) pthread_equal( lhs, rhs )
|
12 | #define thrd_current() pthread_self()
|
13 | #define thrd_sleep( time_point, remaining ) nanosleep( time_point, remaining )
|
14 | #define thrd_yield() sched_yield()
|
15 | #define thrd_exit( res ) pthread_exit( res )
|
16 | #define thrd_detach( thr ) pthread_detach( thr )
|
17 |
|
18 | #define mtx_t mutex_wrapper_t
|
19 | #define mtx_lock( mutex ) pthread_mutex_lock( mutex.mutex )
|
20 | #define mtx_trylock( mutex ) mtx_trylock( mutex.mutex )
|
21 | #define mtx_unlock( mutex ) pthread_mutex_unlock( mutex.mutex )
|
22 | #define mtx_destroy( mutex ) ((mutex.type&&pthread_mutexattr_destroy( mutex.attribute )),pthread_mutex_destroy( mutex.mutex ))
|
23 |
|
24 | enum {
|
25 | thrd_success = 0,
|
26 | thrd_nomem = EAGAIN,
|
27 | thrd_timedout = ETIMEDOUT,
|
28 | thrd_busy = EBUSY,
|
29 | thrd_error = ~0
|
30 | };
|
31 |
|
32 | typedef struct {
|
33 | pthread_mutex_t mutex;
|
34 | pthread_mutexattr_t attribute;
|
35 | int type;
|
36 | } mutex_wrapper_t;
|
37 |
|
38 | enum {
|
39 | mtx_plain = (1<<1),
|
40 | mtx_recursive = (1<<2),
|
41 | mtx_timed = (1<<3)
|
42 | };
|
43 |
|
44 | inline int mtx_init( mtx_t* mutex, int type ){
|
45 | mutex->type = type;
|
46 | switch(type){
|
47 | case 0: break;
|
48 | case mtx_plain:
|
49 | case mtx_recursive:
|
50 | case mtx_timed:
|
51 | pthread_mutexattr_init( &mutex->attribute );
|
52 | break;
|
53 | default: return -1;
|
54 | }
|
55 | pthread_mutex_init( &mutex->mutex, &mutex->attribute );
|
56 | }
|
57 |
|
58 | #endif
|
Das ist zwar noch unvollständig, aber da danach die Funktionen ja zur
Verfügung stehen, würde ich gerne dieses makro un-definieren. Ausserdem
frage ich mich, wieso dass nicht geht?
> Lass es doch einfach definiert.
Das wird wohl die einzige Möglichkeit sein...