2 * The UCW Library -- Threading Helpers
4 * (c) 2006 Martin Mares <mj@ucw.cz>
6 * This software may be freely distributed and used according to the terms
7 * of the GNU Lesser General Public License.
11 #include "lib/threads.h"
13 #ifdef CONFIG_UCW_THREADS
17 static pthread_key_t ucwlib_context_key;
18 static pthread_mutex_t ucwlib_master_mutex;
20 static void CONSTRUCTOR
21 ucwlib_threads_init(void)
23 if (pthread_key_create(&ucwlib_context_key, NULL) < 0)
24 die("Cannot create pthread_key: %m");
25 pthread_mutex_init(&ucwlib_master_mutex, NULL);
28 struct ucwlib_context *
29 ucwlib_thread_context(void)
31 struct ucwlib_context *c = pthread_getspecific(ucwlib_context_key);
34 c = xmalloc_zero(sizeof(*c));
35 pthread_setspecific(ucwlib_context_key, c);
43 pthread_mutex_lock(&ucwlib_master_mutex);
49 pthread_mutex_unlock(&ucwlib_master_mutex);
54 struct ucwlib_context *
55 ucw_thread_context(void)
57 static struct ucwlib_context ucwlib_context;
58 return &ucwlib_context;
79 ucwlib_thread_context();