Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
change free by xbt_free_f
[simgrid.git] / win32_test_app / include / TThreadDynarray.h
1 #ifndef __THREAD_DYNARRAY_H__
2 #define __THREAD_DYNARRAY_H__
3
4 #include <stddef.h> 
5 #include <stdlib.h> 
6 #include <string.h>    
7 #include <windows.h>
8 #include <TTestCaseContext.h>
9
10
11 typedef struct s_ThreadEntry
12 {
13         HANDLE hThread;
14     DWORD threadId;
15         TestCaseContext_t context;
16 }s_ThreadEntry_t,* ThreadEntry_t;       
17 /*
18  * s_ThreadDynarray struct declaration.
19  */
20  
21 typedef struct s_ThreadDynarray
22 {
23         /* threads */
24         ThreadEntry_t threads;
25         /* thread count */
26         unsigned long count;
27         /* Storage capacity */
28         unsigned long capacity;
29         CRITICAL_SECTION cs;
30         bool is_locked;
31
32 }s_ThreadDynarray_t,* ThreadDynarray_t;
33
34 /*
35  * Constructs a ThreadDynarray with the specified capacity.
36  */
37  ThreadDynarray_t ThreadDynarray_new(unsigned long capacity);
38
39 /* 
40  * Destroy the ThreadDynarray 
41  */
42  void ThreadDynarray_destroy(ThreadDynarray_t ptr);
43
44 /*
45  * Returns an const pointer THREAD_entry pointed to by index.
46  */
47  ThreadEntry_t const ThreadDynarray_at(ThreadDynarray_t ptr, unsigned long index);   
48
49 /*
50  * Fill the content of the entry addressed by the __entry with the content
51  * of the entry pointed to by index.
52  */
53  void ThreadDynarray_get(ThreadDynarray_t ptr, unsigned long index, ThreadEntry_t const __entry);
54
55 /* 
56  * Fill the content of the entry pointed to by index with the content of
57  * the entry addressed by __entry.
58  */
59  void ThreadDynarray_set(ThreadDynarray_t ptr, unsigned long index, ThreadEntry_t const __entry);
60
61 /*
62  * Returns a const pointer to the first entry.
63  */
64 ThreadEntry_t const ThreadDynarray_getFront(ThreadDynarray_t ptr);
65
66 /*
67  * Returns a const pointer to the last entry.
68  */
69  ThreadEntry_t const ThreadDynarray_getBack(ThreadDynarray_t ptr);
70
71 /*
72  * Inserts a copy of __entry at the front
73  */
74  void ThreadDynarray_pushFront(ThreadDynarray_t ptr, ThreadEntry_t const __entry);
75
76 /*
77  * Appends a copy of __entry to the end.
78  */
79  void ThreadDynarray_pushBack(ThreadDynarray_t ptr, ThreadEntry_t const __entry);
80
81 /* 
82  * Inserts __entry at the position pointed to by index.
83  */
84  void ThreadDynarray_insert(ThreadDynarray_t ptr, unsigned long index, ThreadEntry_t const __entry);
85
86 /*
87  * Deletes the entry pointed to by index. If __entry is not NULL the
88  * fuction saves the entry threads at this address before.
89  */
90  void ThreadDynarray_erase(ThreadDynarray_t ptr, unsigned long index,ThreadEntry_t const __entry);
91
92 /*
93  * Find the first entry with the same content of the entry addressed by
94  * __entry.The function returns the index of the founded entry, -1 if
95  * no entry is founded.
96  */
97  long ThreadDynarray_getIndex(ThreadDynarray_t ptr, ThreadEntry_t const __entry);
98
99 /* 
100  * Returns true if the entry exist.
101  */
102  bool ThreadDynarray_exist(ThreadDynarray_t ptr, ThreadEntry_t const __entry);
103
104 /* Deletes the first entry with the same content of the entry addressed
105  * by __entry.The function returns true if the entry is deleted, false
106  * if no entry is founded.
107  */
108  bool ThreadDynarray_remove(ThreadDynarray_t ptr, ThreadEntry_t const __entry);
109
110 /*
111  * Erase all elements of the self.
112  */
113  void ThreadDynarray_clear(ThreadDynarray_t ptr);
114
115 /*
116  * Resets entry count to zero.
117  */
118  void ThreadDynarray_reset(ThreadDynarray_t ptr);
119
120 /*
121  * Moves count elements from src index to dst index.
122  */
123  void ThreadDynarray_move(ThreadDynarray_t ptr, const unsigned long dst,const unsigned long src,unsigned long count);
124
125 /* Compare the content of the entry pointed to by index with the content of
126  * the entry addressed by __entry. The function returns true if the contents
127  * are same.
128  */
129  bool ThreadDynarray_compare(ThreadDynarray_t ptr, const unsigned long index,ThreadEntry_t const __entry);
130
131 /*
132  * Returns a reference to a new ThreadDynarray new set is a clone of the self.
133  */
134  ThreadDynarray_t ThreadDynarray_clone(ThreadDynarray_t ptr);
135
136 /*
137  * Extends the capacity when the container is full.
138  */
139  void ThreadDynarray_resize(ThreadDynarray_t ptr);
140
141 /*
142  * Returns the number of elements.
143  */
144  unsigned long ThreadDynarray_getCount(ThreadDynarray_t ptr);
145
146 /*
147  * Returns the current storage capacity of the ThreadDynarray. This is guaranteed
148  * to be at least as large as count().
149  */
150  unsigned long ThreadDynarray_getCapacity(ThreadDynarray_t ptr); 
151
152 /*
153  * Returns upper bound of self (max index).
154  */
155  unsigned long ThreadDynarray_getUpperBound(ThreadDynarray_t ptr);
156
157 /*
158  * Returns lower bound of self (always zero).
159  */
160  unsigned long ThreadDynarray_getLowerBound(ThreadDynarray_t ptr); 
161
162 /*
163  * Returns the size of the elements.
164  */
165  unsigned long ThreadDynarray_getElementSize(ThreadDynarray_t ptr);
166
167 /*
168  * Returns true if the size of self is zero.
169  */
170  bool ThreadDynarray_isEmpty(ThreadDynarray_t ptr);
171
172 /*
173  * Returns true if capacity available.
174  */
175  bool ThreadDynarray(ThreadDynarray_t ptr);
176
177 /*
178  * Returns true if the container is full.
179  */
180  bool ThreadDynarray_is_full(ThreadDynarray_t ptr); 
181
182  /*
183  * Returns true if capacity available.
184  */
185 bool ThreadDynarray_getCapacityAvailable(ThreadDynarray_t ptr);
186
187 /* 
188  * Assignement.
189  */
190 ThreadDynarray_t ThreadDynarray_assign(ThreadDynarray_t src,ThreadDynarray_t dst);
191
192 /* 
193  * Returns true if the dynamic arrays are equal.
194  */ 
195  bool ThreadDynarray_areEquals(ThreadDynarray_t ptr1,ThreadDynarray_t ptr2);
196
197 /* 
198  * Returns true if the dynamic arrays are not equal.
199  */ 
200 bool ThreadDynarray_areNotEquals(ThreadDynarray_t ptr1,ThreadDynarray_t ptr2);
201  
202 void ThreadDynarray_lock(ThreadDynarray_t ptr);
203
204 void ThreadDynarray_unlock(ThreadDynarray_t ptr);
205
206
207 #endif /* #ifndef __THREAD_DYNARRAY_H__ */