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 |
void
|
40 |
s_usleep (slong us); |
|
41 |
||
42 |
/** @brief
|
|
|
116.1.4
by Gustav Hartvigsson
* Removed stupid, non-sense error from SLinkedList. |
43 |
* The status of the thread.
|
44 |
*
|
|
45 |
* These values are equivalent to the value defined my the threads.h. They are
|
|
46 |
* offten used as return values for different fuctions.
|
|
47 |
*/
|
|
48 |
typedef enum { |
|
49 |
S_THREAD_STATUS_SUCCESS = thrd_success, /*< Succes*/ |
|
50 |
S_THREAD_STATUS_TIMEOUT = thrd_timeout, /*< Timeout*/ |
|
51 |
S_THREAD_STATUS_ERROR = thrd_error, /*< Error */ |
|
52 |
S_THREAD_STATUS_BUSY = thrd_busy, /*< Busy */ |
|
53 |
S_THREAD_STATUS_NO_MEM = thrd_nomem, /*< No memory*/ |
|
54 |
S_THREAD_STATUS_LAST /*< Not used */ |
|
55 |
} SThreadStatus; |
|
56 |
||
57 |
/**
|
|
58 |
* @see SThreadStatus
|
|
59 |
*/
|
|
60 |
S_UNUSED static |
|
61 |
schar * SThreadStatusName[] = { |
|
62 |
"Succes", |
|
63 |
"Timeout", |
|
64 |
"Error", |
|
65 |
"Busy", |
|
66 |
"No Momory", |
|
67 |
"INVALID", |
|
68 |
0x0, |
|
69 |
0x0 |
|
70 |
};
|
|
71 |
||
72 |
/** @brief
|
|
73 |
* Get the status name.
|
|
74 |
*
|
|
75 |
* For use in bindings.
|
|
76 |
*
|
|
77 |
* @see SThreadStatus
|
|
78 |
* @see SThreadStatusName
|
|
79 |
*/
|
|
80 |
||
81 |
char * |
|
82 |
s_thread_status_get_name (SThreadStatus status); |
|
83 |
||
|
89
by Gustav Hartvigsson
* Started working on Threads |
84 |
/* ****************************************************************************
|
85 |
********************************** SMutex ************************************
|
|
86 |
**************************************************************************** */
|
|
87 |
||
88 |
/**
|
|
|
77
by Gustav Hartvigsson
* More work on SStream... Requiers Mutex suppert :-) |
89 |
* @defgroup SMutex SMutex
|
|
116.1.4
by Gustav Hartvigsson
* Removed stupid, non-sense error from SLinkedList. |
90 |
* @addtogroup SMutex
|
91 |
* @{
|
|
|
77
by Gustav Hartvigsson
* More work on SStream... Requiers Mutex suppert :-) |
92 |
*/
|
93 |
||
94 |
||
|
116.1.4
by Gustav Hartvigsson
* Removed stupid, non-sense error from SLinkedList. |
95 |
/**
|
|
77
by Gustav Hartvigsson
* More work on SStream... Requiers Mutex suppert :-) |
96 |
* An SMutex is an opaque data type that handles the platform specifics of the
|
97 |
* Mutex, if it exists. If not we roll our own.
|
|
98 |
*/
|
|
99 |
typedef struct SMutex SMutex; |
|
100 |
||
101 |
/**
|
|
102 |
* Create a new SMutex;
|
|
103 |
*/
|
|
104 |
SMutex * |
|
105 |
s_mutex_new (); |
|
106 |
||
107 |
/**
|
|
108 |
* Free the mutex.
|
|
109 |
*/
|
|
110 |
void
|
|
111 |
s_mutex_free (SMutex * self); |
|
112 |
||
113 |
/**
|
|
114 |
* Lock the mutex.
|
|
115 |
*
|
|
116 |
* Returns a key used to unlock the mutex.
|
|
117 |
*/
|
|
118 |
SThreadStatus
|
|
|
116.1.4
by Gustav Hartvigsson
* Removed stupid, non-sense error from SLinkedList. |
119 |
s_mutex_lock (SMutex * self); |
|
77
by Gustav Hartvigsson
* More work on SStream... Requiers Mutex suppert :-) |
120 |
|
121 |
/**
|
|
122 |
* unlock the mutex.
|
|
123 |
*
|
|
124 |
* @param self The mutex to unlock;
|
|
125 |
* @param key The key used to unlock the mutex.
|
|
126 |
*/
|
|
127 |
SThreadStatus
|
|
|
116.1.4
by Gustav Hartvigsson
* Removed stupid, non-sense error from SLinkedList. |
128 |
s_mutex_unlock (SMutex * self); |
|
88
by Gustav Hartvigsson
* Made the SMutex code compile. |
129 |
|
|
77
by Gustav Hartvigsson
* More work on SStream... Requiers Mutex suppert :-) |
130 |
/**
|
131 |
* Check if a mutex is locked.
|
|
|
87
by Gustav Hartvigsson
I have no idea why this is not working...0_o... |
132 |
*
|
133 |
* Note that this operation is non-atomic and may be wrong.
|
|
134 |
*/
|
|
|
77
by Gustav Hartvigsson
* More work on SStream... Requiers Mutex suppert :-) |
135 |
SThreadStatus
|
|
116.1.4
by Gustav Hartvigsson
* Removed stupid, non-sense error from SLinkedList. |
136 |
s_mutex_check_lock (SMutex * self); |
|
77
by Gustav Hartvigsson
* More work on SStream... Requiers Mutex suppert :-) |
137 |
|
138 |
/** @} */
|
|
139 |
||
140 |
/* ****************************************************************************
|
|
|
89
by Gustav Hartvigsson
* Started working on Threads |
141 |
********************************** SThread ***********************************
|
142 |
**************************************************************************** */
|
|
143 |
||
144 |
/**
|
|
145 |
* @defgroup SThread SThread
|
|
146 |
* @addtogroup SThread
|
|
147 |
* @{
|
|
148 |
*/
|
|
149 |
||
150 |
/**
|
|
151 |
* An opaque data type representing a Thread.
|
|
152 |
*/
|
|
153 |
typedef struct SThread SThread; |
|
154 |
||
155 |
/**
|
|
156 |
* Creat a now Thread.
|
|
157 |
*/
|
|
158 |
SThread * |
|
159 |
s_thread_new (RunFunc func); |
|
160 |
||
161 |
/**
|
|
162 |
* Free the thread object.
|
|
163 |
*/
|
|
164 |
void
|
|
165 |
s_thread_free (SThread * self); |
|
166 |
||
167 |
/**
|
|
168 |
* Run the thread.
|
|
169 |
*/
|
|
170 |
sboolean
|
|
171 |
s_thread_run (SThread * self, spointer user_data); |
|
172 |
||
173 |
||
174 |
/** @} */
|
|
175 |
||
176 |
/** @} */
|
|
|
77
by Gustav Hartvigsson
* More work on SStream... Requiers Mutex suppert :-) |
177 |
|
178 |
S_END_DECLS
|
|
|
110
by Gustav Hartvigsson
* added S_ prifix to my macros. I should not be a scrub. |
179 |
#endif /* __H_THREAD__ */ |
|
77
by Gustav Hartvigsson
* More work on SStream... Requiers Mutex suppert :-) |
180 |