00001 #ifndef _ddekit_thread_h 00002 #define _ddekit_thread_h 00003 00004 /** \defgroup DDEKit_threads */ 00005 00006 #include <l4/dde/ddekit/lock.h> 00007 00008 struct ddekit_thread; 00009 typedef struct ddekit_thread ddekit_thread_t; 00010 00011 /** Create thread 00012 * 00013 * \ingroup DDEKit_threads 00014 * 00015 * Create a new thread running the specified thread function with the specified 00016 * arguments. The thread is assigned the given internal name. 00017 * 00018 * Additionally, DDEKit threads possess a thread-local storage area where they 00019 * may store arbitrary data. 00020 * 00021 * \param fun thread function 00022 * \param arg optional argument to thread function, set to NULL if not needed 00023 * \param name internal thread name 00024 */ 00025 ddekit_thread_t *ddekit_thread_create(void (*fun)(void *), void *arg, const char *name); 00026 00027 /** Reference to own DDEKit thread id. 00028 * 00029 * \ingroup DDEKit_threads 00030 */ 00031 ddekit_thread_t *ddekit_thread_myself(void); 00032 00033 /** Initialize thread with given name. 00034 * 00035 * \ingroup DDEKit_threads 00036 * 00037 * This function may be used by threads that were not created using 00038 * \ref ddekit_thread_create. This enables such threads to be handled as if they 00039 * were DDEKit threads. 00040 */ 00041 ddekit_thread_t *ddekit_thread_setup_myself(const char *name); 00042 00043 /** Get TLS data for a specific thread. 00044 * 00045 * \ingroup DDEKit_threads 00046 * 00047 * \return Pointer to TLS data of this thread. 00048 */ 00049 void *ddekit_thread_get_data(ddekit_thread_t *thread); 00050 00051 /** Get TLS data for current thread. 00052 * 00053 * \ingroup DDEKit_threads 00054 * 00055 * Same as calling \ref ddekit_thread_get_data with \ref ddekit_thread_myself 00056 * as parameter. 00057 * 00058 * \return Pointer to TLS data of current thread. 00059 */ 00060 void *ddekit_thread_get_my_data(void); 00061 00062 /** Set TLS data for specific thread. 00063 * 00064 * \ingroup DDEKit_threads 00065 * 00066 * \param thread DDEKit thread 00067 * \param data pointer to thread data 00068 */ 00069 void ddekit_thread_set_data(ddekit_thread_t *thread, void *data); 00070 00071 /** Set TLS data for current thread. 00072 * 00073 * \ingroup DDEKit_threads 00074 * 00075 * \param data pointer to thread data 00076 */ 00077 void ddekit_thread_set_my_data(void *data); 00078 00079 /** Sleep for some miliseconds. 00080 * 00081 * \ingroup DDEKit_threads 00082 * 00083 * \param msecs time to sleep in ms. 00084 */ 00085 void ddekit_thread_msleep(unsigned long msecs); 00086 00087 /** Sleep for some microseconds. 00088 * 00089 * \ingroup DDEKit_threads 00090 * 00091 * \param usecs time to sleep in µs. 00092 */ 00093 void ddekit_thread_usleep(unsigned long usecs); 00094 00095 /** Sleep for some nanoseconds. 00096 * 00097 * \ingroup DDEKit_threads 00098 * 00099 * \param usecs time to sleep in ns. 00100 */ 00101 void ddekit_thread_nsleep(unsigned long nsecs); 00102 00103 /** Sleep until a lock becomes unlocked. 00104 * 00105 * \ingroup DDEKit_threads 00106 */ 00107 void ddekit_thread_sleep(ddekit_lock_t *lock); 00108 00109 /** Wakeup a waiting thread. 00110 * 00111 * \ingroup DDEKit_threads 00112 */ 00113 void ddekit_thread_wakeup(ddekit_thread_t *thread); 00114 00115 /** Terminate a thread 00116 * 00117 * \ingroup DDEKit_threads 00118 */ 00119 void ddekit_thread_exit(void) __attribute__((noreturn)); 00120 00121 /** Terminate a thread 00122 * 00123 * \ingroup DDEKit_threads 00124 */ 00125 void ddekit_thread_terminate(ddekit_thread_t *thread); 00126 00127 /** Get the name, a thread registered with DDEKit. 00128 * 00129 * \ingroup DDEKit_threads 00130 */ 00131 const char *ddekit_thread_get_name(ddekit_thread_t *thread); 00132 00133 /** Get unique ID of a DDEKit thread. 00134 * 00135 * \ingroup DDEKit_threads 00136 * 00137 * DDEKit does not allow direct access to the thread data 00138 * structure, since this struct contains L4-specific data types. 00139 * However, applications might want to get some kind of ID related 00140 * to a ddekit_thread, for instance to use it as a Linux-like PID. 00141 */ 00142 int ddekit_thread_get_id(ddekit_thread_t *thread); 00143 00144 /** Hint that this thread is done and may be scheduled somehow. 00145 * 00146 * \ingroup DDEKit_threads 00147 */ 00148 void ddekit_thread_schedule(void); 00149 00150 /** Hint that this thread is done and may be scheduled somehow. 00151 * 00152 * \ingroup DDEKit_threads 00153 */ 00154 void ddekit_yield(void); 00155 00156 /** Initialize DDEKit thread subsystem. 00157 * 00158 * \ingroup DDEKit_threads 00159 */ 00160 void ddekit_init_threads(void); 00161 00162 #endif
1.5.6