X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;ds=sidebyside;f=ucw%2Fthreads.h;h=7f100b20b2dc79882fb11a4f03250022f560a44b;hb=a1fdee4766b969fd0786e3286ce878a2a1142bbd;hp=5644d152ce9b6fe1fb71ce29c5de940a0e2f25da;hpb=e8060fa4647c5c4ccf07efb91a35f65c543dfc4f;p=libucw.git diff --git a/ucw/threads.h b/ucw/threads.h index 5644d152..7f100b20 100644 --- a/ucw/threads.h +++ b/ucw/threads.h @@ -1,7 +1,7 @@ /* * The UCW Library -- Threading Helpers * - * (c) 2006 Martin Mares + * (c) 2006--2010 Martin Mares * * This software may be freely distributed and used according to the terms * of the GNU Lesser General Public License. @@ -13,22 +13,41 @@ /* This structure holds per-thread data */ struct ucwlib_context { - int thread_id; // Thread ID (either kernel tid or a counter) + int _thread_id; // Thread ID (either kernel tid or a counter, use ucwlib_thread_id()) int temp_counter; // Counter for fb-temp.c struct asio_queue *io_queue; // Async I/O queue for fb-direct.c ucw_sighandler_t *signal_handlers; // Signal handlers for sighandler.c }; +#ifdef CONFIG_UCW_THREADS + +#ifdef CONFIG_UCW_TLS +extern __thread struct ucwlib_context ucwlib_context; +static inline struct ucwlib_context *ucwlib_thread_context(void) { return &ucwlib_context; } +int ucwlib_thread_id(struct ucwlib_context *c); +#else struct ucwlib_context *ucwlib_thread_context(void); +static inline int ucwlib_thread_id(struct ucwlib_context *c) { return c->_thread_id; } +#endif /* Global lock used for initialization, cleanup and other not so frequently accessed global state */ void ucwlib_lock(void); void ucwlib_unlock(void); -#ifdef CONFIG_UCW_THREADS +extern uns ucwlib_thread_stack_size; + +#else + +/* We have no threads, let's simulate the context and locking */ + +extern struct ucwlib_context default_ucwlib_context; +static inline struct ucwlib_context *ucwlib_thread_context(void) { return &default_ucwlib_context; } + +static inline int ucwlib_thread_id(struct ucwlib_context *c UNUSED) { return 0; } -extern uns default_thread_stack_size; +static inline void ucwlib_lock(void) { } +static inline void ucwlib_unlock(void) { } #endif