X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/007e84eaf7247e8987d9cf6f795cb4a93ea66aa5..079fc72766f21657cb49d9a183f0e35c0223e0f1:/src/xbt/win_thread.h diff --git a/src/xbt/win_thread.h b/src/xbt/win_thread.h index f6c47e6d9f..536d2b20c0 100644 --- a/src/xbt/win_thread.h +++ b/src/xbt/win_thread.h @@ -19,15 +19,44 @@ extern "C" { /* 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. */ @@ -47,6 +76,24 @@ typedef struct s_win_thread_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. @@ -83,7 +130,7 @@ win_thread_exit(win_thread_t* thread,unsigned long exit_code); /* * Return the identifier of the current thread. */ -unsigned long +win_thread_t win_thread_self(void); /* @@ -183,6 +230,52 @@ win_thread_cond_destroy(win_thread_cond_t* cond); 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