2 * Copyright (c) 2007 Malek CHERIER. All rights reserved.
5 /* This program is free software; you can redistribute it and/or modify it
6 * under the terms of the license (GNU LGPL) which comes with this package.
9 #ifndef XBT_WIN_THREAD_H
10 #define XBT_WIN_THREAD_H
13 #include "xbt/sysdep.h"
19 /* type of function pointeur used */
20 typedef DWORD WINAPI (*pfn_start_routine_t)(void*);
23 * This structure represents a windows thread.
25 typedef struct s_win_thread
27 HANDLE handle; /* the win thread handle */
28 unsigned long id; /* the win thread id */
29 }s_win_thread_t,* win_thread_t;
32 * This structure simulates a pthread cond.
42 typedef struct s_win_thread_cond
44 HANDLE events[MAX_EVENTS];
46 unsigned int waiters_count; /* the number of waiters */
47 CRITICAL_SECTION waiters_count_lock;/* protect access to waiters_count */
48 }s_win_thread_cond_t,* win_thread_cond_t;
51 * This structure represents a windows mutext
52 * remark : only encapsulate the mutext handle.
54 typedef struct s_win_thread_mutex
56 CRITICAL_SECTION lock;
57 }s_win_thread_mutex_t,* win_thread_mutex_t;
60 * Windows thread connected functions.
64 * Create a win thread.
65 * @param thread The address of the thread to create
66 * @param start_routine The thread function.
67 * @param param A optional pointer to the thread function parameters.
68 * @return If successful the function returns 0. Otherwise the function
72 win_thread_create(win_thread_t* thread, pfn_start_routine_t start_routine,void* param);
75 * Terminate the win thread.
76 * @param thread An address to the thread to exit.
77 * @param exit_code The exit code returned by the thread.
78 * @return This function always returns 0;
81 win_thread_exit(win_thread_t* thread,unsigned long exit_code);
84 * Return the identifier of the current thread.
87 win_thread_self(void);
90 * Windows mutex connected functions;
94 * Create a windows mutex.
95 * @param mutex The address to the mutex to create.
96 * @return If successful the function returns 0. Otherwise
97 * the function returns 1.
100 win_thread_mutex_init(win_thread_mutex_t* mutex);
103 * Lock a windows mutex.
104 * @param mutex The address to the mutex to lock.
105 * @return If successful the function returns 0.
106 * Otherwise the function return 1.
109 win_thread_mutex_lock(win_thread_mutex_t* mutex);
112 * Unlock a windows mutex.
113 * @param mutex The address to the mutex to unlock.
114 * @return If successful the function returns 0.
115 * Otherwise the function return 1.
118 win_thread_mutex_unlock(win_thread_mutex_t* mutex);
121 * Destroy a windows mutex.
122 * @param mutex The address of the mutex to destroy.
123 * @return If successful the function return 0.
124 * Otherwise the function returns 1.
127 win_thread_mutex_destroy(win_thread_mutex_t* mutex);
130 * Condition connected functions.
134 * Create a condition.
135 * @param cond The address to the condition to create.
136 * @return If successful the function returns 0.
137 * Otherwise the function returns 1.
140 win_thread_cond_init(win_thread_cond_t* cond);
143 * Wait about a condition.
144 * @param cond The address to the condition to wait about.
145 * @param mutex The address to the mutex associated to the condition.
146 * @return If successful the function returns 0.
147 * Otherwise the function return 1.
150 win_thread_cond_wait(win_thread_cond_t* cond,win_thread_mutex_t* mutex);
153 * Signal that a condition is verified.
154 * @param cond The address of the condition concerned by the signal.
155 * @return If successful the function return 0.
156 * Otherwise the function return 1.
159 win_thread_cond_signal(win_thread_cond_t* cond);
162 * Unblock all threads waiting for a condition.
163 * @param cond The address of the condition to broadcast.
164 * @return If successful the function return 0.
165 * Otherwise the function return 1.
169 win_thread_cond_broadcast(win_thread_cond_t* cond);
172 * Destroy a condition.
173 * @param The address to the condition to destroy.
174 * @return If successful the function returns 0.
175 * Otherwise the function return 1.
178 win_thread_cond_destroy(win_thread_cond_t* cond);
185 #endif /* !XBT_WIN_THREAD_H */