1 /* This is the supporting header file for POSIX threads.
2 * We need the following globals:
4 * 1) THREAD_PROTECT(varname)
5 * = a pseudo code NOT TERMINATED BY A SEMICOLON. After this point all
6 * code until a THREAD_UNPROTECT is executed by one thread at once.
7 * This may be done by a call to a semaphore action or something else.
8 * THREAD_PROTECT and THREAD_UNPROTECT define a C block logically.
9 * varname ist a variable created by PROTECTION_VAR()
10 * 2) THREAD_UNPROTECT(varname)
12 * 3) PROTECTION_VAR(varname)
13 * = a pseudo code NOT TERMINATED BY A SEMICOLON. This define will
14 * create and initialize a local variable which may be used by
15 * THREAD_PROTECT and THREAD_UNPROTECT.
16 * Typical examples are the protection of static local variables.
17 * 4) GLOBAL_PROTECTION_VAR(varname)
18 * = a pseudo code NOT TERMINATED BY A SEMICOLON. This define will
19 * create and initialize a global variable which may be used by
20 * THREAD_PROTECT and THREAD_UNPROTECT.
21 * Typical examples are the usage of the parser or global variables
22 * like macro_serialno.
23 * 5) EXPORT_GLOBAL_PROTECTION_VAR(varname)
24 * = a pseudo code NOT TERMINATED BY A SEMICOLON. This define will
25 * export the varname in header files. There must exist one declaration
26 * of the variable done by GLOBAL_PROTECTION_VAR.
27 * 6) GLOBAL_ENTRY_POINT()
28 * = initializes the process specific data and the thread specific data.
29 * This pseudo function is only called by those functions which are
30 * external (rexxsaa.h).
31 * It should return (tsd_t *) of the current thread.
32 * 7) __regina_get_tsd()
33 * = pointer to a variable of type tsd_t.
34 * This may only exist after a GLOBAL_ENTRY_POINT()-call and must then
40 # error This file should included by mt.h, only.
45 #define THREAD_PROTECT(varname) pthread_cleanup_push((void (*)(void *)) \
46 pthread_mutex_unlock,&varname); \
47 pthread_mutex_lock(&varname);
48 #define THREAD_UNPROTECT(varname) pthread_cleanup_pop(1);
50 #define PROTECTION_VAR(varname) static pthread_mutex_t varname = \
51 PTHREAD_MUTEX_INITIALIZER;
53 #define EXPORT_GLOBAL_PROTECTION_VAR(varname) extern pthread_mutex_t varname;
54 #define GLOBAL_PROTECTION_VAR(varname) pthread_mutex_t varname = \
55 PTHREAD_MUTEX_INITIALIZER;
58 tsd_t
*ReginaInitializeThread(void);
59 #define GLOBAL_ENTRY_POINT() ReginaInitializeThread()
61 /* we need a pointer to tsd_t sometimes: */
62 tsd_t
*__regina_get_tsd(void);
64 /* NEVER USE __regina_get_tsd() IF YOU CAN GET THE VALUE FROM SOMEWHERE ELSE.
65 * IT REDUCES THE EXECUTION SPEED SIGNIFICANTLY. TAKE THE VALUE FROM THE CALLER
66 * WHERE IT IS POSSIBLE.