bzr branch
http://gegoxaren.bato24.eu/bzr/simpletypesystem/trunk
77
by Gustav Hartvigsson
* More work on SStream... Requiers Mutex suppert :-) |
1 |
#pragma once
|
129
by Gustav Hartvigsson
* Missed one. |
2 |
|
77
by Gustav Hartvigsson
* More work on SStream... Requiers Mutex suppert :-) |
3 |
#include "defs.h" |
4 |
#include "utils.h" |
|
5 |
#include "Func.h" |
|
89
by Gustav Hartvigsson
* Started working on Threads |
6 |
|
87
by Gustav Hartvigsson
I have no idea why this is not working...0_o... |
7 |
S_BEGIN_DECLS
|
110
by Gustav Hartvigsson
* added S_ prifix to my macros. I should not be a scrub. |
8 |
|
79
by Gustav Hartvigsson
* Clean up of SMap's for each code. |
9 |
#include "config.h" |
88
by Gustav Hartvigsson
* Made the SMutex code compile. |
10 |
|
11 |
//#if !__STDC_NO_ATOMICS__
|
|
151.1.1
by Gustav Hartvigsson
* fixed... sort of... the Meson Build system... Still buggy. |
12 |
//#include <stdatomic.h>
|
13 |
//#else
|
|
14 |
#include "external/stdatomic.h" |
|
87
by Gustav Hartvigsson
I have no idea why this is not working...0_o... |
15 |
//#endif
|
151.1.1
by Gustav Hartvigsson
* fixed... sort of... the Meson Build system... Still buggy. |
16 |
|
87
by Gustav Hartvigsson
I have no idea why this is not working...0_o... |
17 |
//#if !__STDC_NO_THREADS__
|
151.1.1
by Gustav Hartvigsson
* fixed... sort of... the Meson Build system... Still buggy. |
18 |
//#include <threads.h>
|
19 |
//#else
|
|
20 |
#include "external/tinycthread.h" |
|
128
by Gustav Hartvigsson
* Removed blasted #pragma message s from Thread.h |
21 |
//#endif
|
151.1.1
by Gustav Hartvigsson
* fixed... sort of... the Meson Build system... Still buggy. |
22 |
|
87
by Gustav Hartvigsson
I have no idea why this is not working...0_o... |
23 |
|
24 |
/**
|
|
77
by Gustav Hartvigsson
* More work on SStream... Requiers Mutex suppert :-) |
25 |
* @defgroup Threading Threading
|
26 |
* @addtogroup Threading
|
|
27 |
* @{
|
|
28 |
*/
|
|
29 |
||
30 |
||
31 |
/**
|
|
32 |
* Sleep for a set amount of micro seconds.
|
|
87
by Gustav Hartvigsson
I have no idea why this is not working...0_o... |
33 |
*/
|
77
by Gustav Hartvigsson
* More work on SStream... Requiers Mutex suppert :-) |
34 |
S_EXPORTED
|
119
by Gustav Hartvigsson
* added S_EXPERTED to public functions. |
35 |
void
|
77
by Gustav Hartvigsson
* More work on SStream... Requiers Mutex suppert :-) |
36 |
s_usleep (slong us); |
37 |
||
38 |
/** @brief
|
|
116.1.4
by Gustav Hartvigsson
* Removed stupid, non-sense error from SLinkedList. |
39 |
* The status of the thread.
|
40 |
*
|
|
41 |
* These values are equivalent to the value defined my the threads.h. They are
|
|
42 |
* offten used as return values for different fuctions.
|
|
43 |
*/
|
|
44 |
typedef enum { |
|
45 |
S_THREAD_STATUS_SUCCESS = thrd_success, /**< Succes*/ |
|
151.1.1
by Gustav Hartvigsson
* fixed... sort of... the Meson Build system... Still buggy. |
46 |
S_THREAD_STATUS_TIMEOUT = thrd_timedout, /**< Timedout*/ |
47 |
S_THREAD_STATUS_ERROR = thrd_error, /**< Error */ |
|
48 |
S_THREAD_STATUS_BUSY = thrd_busy, /**< Busy */ |
|
49 |
S_THREAD_STATUS_NO_MEM = thrd_nomem, /**< No memory*/ |
|
50 |
S_THREAD_STATUS_LAST /**< Not used */ |
|
51 |
} SThreadStatus; |
|
116.1.4
by Gustav Hartvigsson
* Removed stupid, non-sense error from SLinkedList. |
52 |
|
53 |
/**
|
|
54 |
* @see SThreadStatus
|
|
55 |
*/
|
|
56 |
S_UNUSED static |
|
57 |
schar * SThreadStatusName[] = { |
|
58 |
"Succes", |
|
59 |
"Timedout", |
|
128
by Gustav Hartvigsson
* Removed blasted #pragma message s from Thread.h |
60 |
"Error", |
116.1.4
by Gustav Hartvigsson
* Removed stupid, non-sense error from SLinkedList. |
61 |
"Busy", |
62 |
"No Momory", |
|
63 |
"INVALID", |
|
64 |
0x0, |
|
65 |
0x0 |
|
66 |
};
|
|
67 |
||
68 |
/** @brief
|
|
69 |
* Get the status name.
|
|
70 |
*
|
|
71 |
* For use in bindings.
|
|
72 |
*
|
|
73 |
* @see SThreadStatus
|
|
74 |
* @see SThreadStatusName
|
|
75 |
*/
|
|
76 |
S_EXPORTED
|
|
119
by Gustav Hartvigsson
* added S_EXPERTED to public functions. |
77 |
char * |
116.1.4
by Gustav Hartvigsson
* Removed stupid, non-sense error from SLinkedList. |
78 |
s_thread_status_get_name (SThreadStatus status); |
79 |
||
89
by Gustav Hartvigsson
* Started working on Threads |
80 |
/**
|
128
by Gustav Hartvigsson
* Removed blasted #pragma message s from Thread.h |
81 |
* The flags used when creating threads.
|
82 |
* These map 1:1 to the C11 flags.
|
|
83 |
*/
|
|
84 |
typedef enum { |
|
85 |
S_MUTEX_FLAG_PLAIN = mtx_plain, /**< Plain mutex */ |
|
151.1.1
by Gustav Hartvigsson
* fixed... sort of... the Meson Build system... Still buggy. |
86 |
S_MUTEX_FLAG_TIMED = mtx_timed, /**< Timed mutex */ |
87 |
S_MUTEX_FLAG_RECURSIVE = mtx_recursive, /**< Recursive mutex */ |
|
128
by Gustav Hartvigsson
* Removed blasted #pragma message s from Thread.h |
88 |
S_MUTEX_FLAG_LAST |
89 |
} SMutexFlag; |
|
90 |
||
91 |
/**
|
|
92 |
* @see SMutexFlag
|
|
93 |
*/
|
|
94 |
S_UNUSED static |
|
95 |
schar * SMutexFlagName[] = { |
|
96 |
"Plain", |
|
97 |
"Timed", |
|
98 |
"Recursive", |
|
99 |
"INVALID", |
|
130
by Gustav Hartvigsson
* woops! |
100 |
0x0, |
128
by Gustav Hartvigsson
* Removed blasted #pragma message s from Thread.h |
101 |
0x0 |
102 |
};
|
|
103 |
||
104 |
/** @brief
|
|
105 |
* Get the name of the mutex flag.
|
|
106 |
*
|
|
107 |
* For use in bindings.
|
|
108 |
*/
|
|
109 |
schar * |
|
110 |
s_mutex_flag_get_name (SMutexFlag flag); |
|
111 |
||
112 |
/* ****************************************************************************
|
|
89
by Gustav Hartvigsson
* Started working on Threads |
113 |
********************************** SMutex ************************************
|
114 |
**************************************************************************** */
|
|
115 |
||
116 |
/**
|
|
77
by Gustav Hartvigsson
* More work on SStream... Requiers Mutex suppert :-) |
117 |
* @defgroup SMutex SMutex
|
116.1.4
by Gustav Hartvigsson
* Removed stupid, non-sense error from SLinkedList. |
118 |
* @addtogroup SMutex
|
119 |
* @{
|
|
77
by Gustav Hartvigsson
* More work on SStream... Requiers Mutex suppert :-) |
120 |
*/
|
121 |
||
122 |
||
116.1.4
by Gustav Hartvigsson
* Removed stupid, non-sense error from SLinkedList. |
123 |
/**
|
77
by Gustav Hartvigsson
* More work on SStream... Requiers Mutex suppert :-) |
124 |
* An SMutex is an opaque data type that handles the platform specifics of the
|
125 |
* Mutex, if it exists. If not we roll our own.
|
|
126 |
*/
|
|
127 |
typedef struct SMutex SMutex; |
|
128 |
||
129 |
/**
|
|
130 |
* Create a new SMutex;
|
|
131 |
*/
|
|
132 |
S_EXPORTED
|
|
119
by Gustav Hartvigsson
* added S_EXPERTED to public functions. |
133 |
SMutex * |
77
by Gustav Hartvigsson
* More work on SStream... Requiers Mutex suppert :-) |
134 |
s_mutex_new (); |
135 |
||
136 |
/**
|
|
137 |
* Free the mutex.
|
|
138 |
*/
|
|
139 |
S_EXPORTED
|
|
119
by Gustav Hartvigsson
* added S_EXPERTED to public functions. |
140 |
void
|
77
by Gustav Hartvigsson
* More work on SStream... Requiers Mutex suppert :-) |
141 |
s_mutex_free (SMutex * self); |
142 |
||
143 |
/**
|
|
144 |
* Lock the mutex.
|
|
145 |
*
|
|
146 |
* Returns a key used to unlock the mutex.
|
|
147 |
*/
|
|
148 |
S_EXPORTED
|
|
119
by Gustav Hartvigsson
* added S_EXPERTED to public functions. |
149 |
SThreadStatus
|
116.1.4
by Gustav Hartvigsson
* Removed stupid, non-sense error from SLinkedList. |
150 |
s_mutex_lock (SMutex * self); |
77
by Gustav Hartvigsson
* More work on SStream... Requiers Mutex suppert :-) |
151 |
|
152 |
/**
|
|
153 |
* unlock the mutex.
|
|
154 |
*
|
|
155 |
* @param self The mutex to unlock;
|
|
156 |
* @param key The key used to unlock the mutex.
|
|
157 |
*/
|
|
158 |
S_EXPORTED
|
|
119
by Gustav Hartvigsson
* added S_EXPERTED to public functions. |
159 |
SThreadStatus
|
116.1.4
by Gustav Hartvigsson
* Removed stupid, non-sense error from SLinkedList. |
160 |
s_mutex_unlock (SMutex * self); |
88
by Gustav Hartvigsson
* Made the SMutex code compile. |
161 |
|
77
by Gustav Hartvigsson
* More work on SStream... Requiers Mutex suppert :-) |
162 |
/**
|
163 |
* Check if a mutex is locked.
|
|
87
by Gustav Hartvigsson
I have no idea why this is not working...0_o... |
164 |
*
|
165 |
* Note that this operation is non-atomic and may be wrong.
|
|
151.1.1
by Gustav Hartvigsson
* fixed... sort of... the Meson Build system... Still buggy. |
166 |
*/
|
77
by Gustav Hartvigsson
* More work on SStream... Requiers Mutex suppert :-) |
167 |
S_EXPORTED
|
119
by Gustav Hartvigsson
* added S_EXPERTED to public functions. |
168 |
SThreadStatus
|
116.1.4
by Gustav Hartvigsson
* Removed stupid, non-sense error from SLinkedList. |
169 |
s_mutex_check_lock (SMutex * self); |
77
by Gustav Hartvigsson
* More work on SStream... Requiers Mutex suppert :-) |
170 |
|
171 |
/** @} */
|
|
172 |
||
173 |
/* ****************************************************************************
|
|
89
by Gustav Hartvigsson
* Started working on Threads |
174 |
********************************** SThread ***********************************
|
175 |
**************************************************************************** */
|
|
176 |
||
177 |
/**
|
|
178 |
* @defgroup SThread SThread
|
|
179 |
* @addtogroup SThread
|
|
180 |
* @{
|
|
181 |
*/
|
|
182 |
||
183 |
/**
|
|
184 |
* An opaque data type representing a Thread.
|
|
185 |
*/
|
|
186 |
typedef struct SThread SThread; |
|
187 |
||
188 |
/**
|
|
189 |
* Creat a now Thread.
|
|
190 |
*/
|
|
191 |
S_EXPORTED
|
|
119
by Gustav Hartvigsson
* added S_EXPERTED to public functions. |
192 |
SThread * |
89
by Gustav Hartvigsson
* Started working on Threads |
193 |
s_thread_new (RunFunc func); |
194 |
||
195 |
/**
|
|
196 |
* Free the thread object.
|
|
197 |
*/
|
|
198 |
S_EXPORTED
|
|
119
by Gustav Hartvigsson
* added S_EXPERTED to public functions. |
199 |
void
|
89
by Gustav Hartvigsson
* Started working on Threads |
200 |
s_thread_free (SThread * self); |
201 |
||
202 |
/**
|
|
203 |
* Run the thread.
|
|
204 |
*
|
|
151.1.1
by Gustav Hartvigsson
* fixed... sort of... the Meson Build system... Still buggy. |
205 |
* @note You must pass the self object as part of the user_data object, or have
|
206 |
* the self object globally avalible. Otherwise you will not be able to
|
|
207 |
* stop the thread using s_thread_stop.
|
|
208 |
*/
|
|
89
by Gustav Hartvigsson
* Started working on Threads |
209 |
S_EXPORTED
|
119
by Gustav Hartvigsson
* added S_EXPERTED to public functions. |
210 |
SThreadStatus
|
150
by Gustav Hartvigsson
* Fixed the tests in the CMake file |
211 |
s_thread_run (SThread * self, spointer user_data); |
89
by Gustav Hartvigsson
* Started working on Threads |
212 |
|
213 |
||
214 |
S_EXPORTED
|
|
150
by Gustav Hartvigsson
* Fixed the tests in the CMake file |
215 |
void
|
216 |
s_thread_stop (SThread * self, sint res); |
|
217 |
||
218 |
||
219 |
/** @} */
|
|
89
by Gustav Hartvigsson
* Started working on Threads |
220 |
|
221 |
/** @} */
|
|
77
by Gustav Hartvigsson
* More work on SStream... Requiers Mutex suppert :-) |
222 |
|
223 |
S_END_DECLS
|
|
110
by Gustav Hartvigsson
* added S_ prifix to my macros. I should not be a scrub. |
224 |