Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
update the double extern declaration bis
[simgrid.git] / src / xbt / win_thread.h
1 /* 
2  * Copyright (c) 2007 Malek CHERIER. All rights reserved.                                       
3  */
4
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.     
7  */
8  
9 #ifndef XBT_WIN_THREAD_H
10 #define XBT_WIN_THREAD_H
11
12 #include <windows.h>
13 #include "xbt/sysdep.h"
14
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18
19 /* type of function pointeur used */
20 typedef  DWORD WINAPI (*pfn_start_routine_t)(void*);
21
22 /*
23  * This structure represents a windows thread.
24  */
25 typedef struct s_win_thread
26 {
27         HANDLE handle;                  /* the win thread handle        */
28         unsigned long id;               /* the win thread id            */      
29 }s_win_thread_t,* win_thread_t;
30
31 /*
32  * This structure simulates a pthread cond.
33  */
34
35  enum
36  {
37     SIGNAL = 0,
38     BROADCAST = 1,
39     MAX_EVENTS = 2
40  };
41
42 typedef struct s_win_thread_cond
43 {
44         HANDLE events[MAX_EVENTS];
45
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;
49
50 /*
51  * This structure represents a windows mutext
52  * remark : only encapsulate the mutext handle.
53  */
54 typedef struct s_win_thread_mutex
55 {
56         CRITICAL_SECTION lock;
57 }s_win_thread_mutex_t,* win_thread_mutex_t;
58
59 /*
60  * Windows thread connected functions.
61  */
62
63 /*
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
69  *  return 1.
70  */ 
71 int
72 win_thread_create(win_thread_t* thread, pfn_start_routine_t start_routine,void* param);
73
74 /*
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;
79  */ 
80 int
81 win_thread_exit(win_thread_t* thread,unsigned long exit_code);
82
83 /*
84  * Return the identifier of the current thread.
85  */
86 unsigned long
87 win_thread_self(void);
88
89 /*
90  * Windows mutex connected functions;
91  */
92  
93 /*
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.
98  */
99 int
100 win_thread_mutex_init(win_thread_mutex_t* mutex);
101
102 /*
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.
107  */
108 int
109 win_thread_mutex_lock(win_thread_mutex_t* mutex);
110
111 /*
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.
116  */
117 int
118 win_thread_mutex_unlock(win_thread_mutex_t* mutex);
119
120 /* 
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.
125  */
126 int
127 win_thread_mutex_destroy(win_thread_mutex_t* mutex);
128
129 /*
130  * Condition connected functions.
131  */
132
133 /*
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.
138  */
139 int
140 win_thread_cond_init(win_thread_cond_t* cond);
141
142 /*
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.
148  */
149 int
150 win_thread_cond_wait(win_thread_cond_t* cond,win_thread_mutex_t* mutex);
151
152 /*
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.
157  */
158 int
159 win_thread_cond_signal(win_thread_cond_t* cond);
160
161 /*
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.
166  */
167
168 int 
169 win_thread_cond_broadcast(win_thread_cond_t* cond);
170
171 /*
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.
176  */
177 int
178 win_thread_cond_destroy(win_thread_cond_t* cond);
179
180 #ifdef __cplusplus
181 extern }
182 #endif
183
184
185 #endif /* !XBT_WIN_THREAD_H */