/* type of function pointeur used */
typedef DWORD WINAPI (*pfn_start_routine_t)(void*);
+typedef struct s_win_thread_key s_win_thread_key_t,* win_thread_key_t;
+typedef struct s_win_thread_keys s_win_thread_keys_t,* win_thread_keys_t;
+
/*
* This structure represents a windows thread.
*/
typedef struct s_win_thread
{
HANDLE handle; /* the win thread handle */
- unsigned long id; /* the win thread id */
+ unsigned long id; /* the win thread id */
+ win_thread_keys_t keys;
}s_win_thread_t,* win_thread_t;
+struct s_win_thread_keys
+{
+ win_thread_key_t* keys;
+ win_thread_key_t front;
+ win_thread_key_t back;
+};
+
+typedef struct s_win_thread_entry
+{
+ HANDLE handle;
+ win_thread_t thread;
+ win_thread_t next;
+ win_thread_t prev;
+}s_win_thread_entry_t,win_thread_entry_t;
+
+typedef struct s_win_threads
+{
+ win_thread_entry_t* threads;
+ win_thread_entry_t front;
+ win_thread_entry_t back;
+ unsigned int size;
+ CRITICAL_SECTION lock;
+}s_win_threads_t,* win_threads_t;
+
+
/*
* This structure simulates a pthread cond.
*/
CRITICAL_SECTION waiters_count_lock;/* protect access to waiters_count */
}s_win_thread_cond_t,* win_thread_cond_t;
+
+/* type of pointer function used by the
+ * win_thread_key_create() function.
+ */
+typedef void (*pfn_key_dstr_func_t) (void*);
+
+/*
+ * This structure represents a windows key
+ */
+struct s_win_thread_key
+{
+ unsigned long value; /* the key value */
+ pfn_key_dstr_func_t dstr_func; /* the pointer to the destruction function */
+ win_thread_key_t next;
+ win_thread_key_t prev;
+};
+
+
/*
* This structure represents a windows mutext
* remark : only encapsulate the mutext handle.
/*
* Return the identifier of the current thread.
*/
-unsigned long
+win_thread_t
win_thread_self(void);
/*
void
win_thread_yield(void);
+
+/*
+ * windows thread key connected functions
+ */
+
+/*
+ * Create a windows thread key.
+ * @param key The pointer to the key to create.
+ * @param dstr_func The pointer to the cleanup function.
+ * @return If successful the function returns .Otherwise
+ * the function returns 1.
+ */
+int
+win_thread_key_create(win_thread_key_t* key, pfn_key_dstr_func_t dstr_func);
+/*
+ * Destroy a key.
+ * @param key The key to delete.
+ * @return If successful the function returns 0.
+ * Otherwise the function returns 1.
+ */
+int
+win_thread_key_delete(win_thread_key_t key);
+
+/*
+ * Update or set the value associated to a key.
+ * @param key The key concerned by the operation.
+ * @param value The value to set or update.
+ * @return If successful the function returns 0.
+ * Otherwise the function returns 1.
+ */
+int
+win_thread_setspecific(win_thread_key_t key, const void* p);
+
+/*
+ * Return the value associated to a key.
+ * @param key The key concerned by the operation.
+ * @return If successful the function returns the value.
+ * Otherwise the function returns NULL.
+ */
+void*
+win_thread_getspecific(win_thread_key_t key);
+
+
+
+
+
#ifdef __cplusplus
extern }
#endif