2 * The UCW Library -- Threading Helpers
4 * (c) 2006--2010 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.
10 #ifndef _UCW_THREADS_H
11 #define _UCW_THREADS_H
13 /* This structure holds per-thread data */
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 struct main_context *main_context; // Current context for mainloop.c
21 // Resources and transactions:
22 struct respool *current_respool; // Current resource pool
23 struct mempool *trans_pool; // Transaction mempool
24 struct trans *current_trans; // Currently open transaction
25 struct mempool *exc_pool; // Exception mempool
26 struct exception *current_exc; // Currently active exception
29 #ifdef CONFIG_UCW_THREADS
32 extern __thread struct ucwlib_context ucwlib_context;
33 static inline struct ucwlib_context *ucwlib_thread_context(void) { return &ucwlib_context; }
34 int ucwlib_thread_id(struct ucwlib_context *c);
36 struct ucwlib_context *ucwlib_thread_context(void);
37 static inline int ucwlib_thread_id(struct ucwlib_context *c) { return c->_thread_id; }
40 /* Global lock used for initialization, cleanup and other not so frequently accessed global state */
42 void ucwlib_lock(void);
43 void ucwlib_unlock(void);
45 extern uns ucwlib_thread_stack_size;
49 /* We have no threads, let's simulate the context and locking */
51 extern struct ucwlib_context default_ucwlib_context;
52 static inline struct ucwlib_context *ucwlib_thread_context(void) { return &default_ucwlib_context; }
54 static inline int ucwlib_thread_id(struct ucwlib_context *c UNUSED) { return 0; }
56 static inline void ucwlib_lock(void) { }
57 static inline void ucwlib_unlock(void) { }