]> mj.ucw.cz Git - libucw.git/blob - ucw/threads.h
Implemented a new growing array module
[libucw.git] / ucw / threads.h
1 /*
2  *      The UCW Library -- Threading Helpers
3  *
4  *      (c) 2006--2010 Martin Mares <mj@ucw.cz>
5  *
6  *      This software may be freely distributed and used according to the terms
7  *      of the GNU Lesser General Public License.
8  */
9
10 #ifndef _UCW_THREAD_H
11 #define _UCW_THREAD_H
12
13 /* This structure holds per-thread data */
14
15 struct ucwlib_context {
16   int _thread_id;                       // Thread ID (either kernel tid or a counter, use ucwlib_thread_id())
17   int temp_counter;                     // Counter for fb-temp.c
18   struct asio_queue *io_queue;          // Async I/O queue for fb-direct.c
19   ucw_sighandler_t *signal_handlers;    // Signal handlers for sighandler.c
20 };
21
22 #ifdef CONFIG_UCW_THREADS
23
24 #ifdef CONFIG_UCW_TLS
25 extern __thread struct ucwlib_context ucwlib_context;
26 static inline struct ucwlib_context *ucwlib_thread_context(void) { return &ucwlib_context; }
27 int ucwlib_thread_id(struct ucwlib_context *c);
28 #else
29 struct ucwlib_context *ucwlib_thread_context(void);
30 static inline int ucwlib_thread_id(struct ucwlib_context *c) { return c->_thread_id; }
31 #endif
32
33 /* Global lock used for initialization, cleanup and other not so frequently accessed global state */
34
35 void ucwlib_lock(void);
36 void ucwlib_unlock(void);
37
38 extern uns ucwlib_thread_stack_size;
39
40 #else
41
42 /* We have no threads, let's simulate the context and locking */
43
44 extern struct ucwlib_context default_ucwlib_context;
45 static inline struct ucwlib_context *ucwlib_thread_context(void) { return &default_ucwlib_context; }
46
47 static inline int ucwlib_thread_id(struct ucwlib_context *c UNUSED) { return 0; }
48
49 static inline void ucwlib_lock(void) { }
50 static inline void ucwlib_unlock(void) { }
51
52 #endif
53
54 #endif