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