/simpletypesystem/trunk

To get this branch, use:
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
BEGIN_DECLS
79 by Gustav Hartvigsson
* Clean up of SMap's for each code.
9
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
89 by Gustav Hartvigsson
* Started working on Threads
43
/* ****************************************************************************
44
 ********************************** SMutex ************************************
45
 **************************************************************************** */
46
47
/**
77 by Gustav Hartvigsson
* More work on SStream... Requiers Mutex suppert :-)
48
 * @defgroup Mutex Mutex
49
 * @addtogroup Mutex
50
 * @{
51
 */
52
53
/**
54
 * An SMutex is an opaque data type that handles the platform specifics of the
55
 * Mutex, if it exists. If not we roll our own.
56
 */
57
typedef struct SMutex SMutex;
58
59
/**
60
 * Create a new SMutex;
61
 */
62
SMutex *
63
s_mutex_new ();
64
65
/**
66
 * Free the mutex.
67
 */
68
void
69
s_mutex_free (SMutex * self);
70
71
/**
72
 * Lock the mutex.
73
 *
74
 * Returns a key used to unlock the mutex.
75
 */
76
sint
89 by Gustav Hartvigsson
* Started working on Threads
77
s_mutex_lock (SMutex * self);
77 by Gustav Hartvigsson
* More work on SStream... Requiers Mutex suppert :-)
78
79
/**
80
 * unlock the mutex.
81
 *
82
 * @param self The mutex to unlock;
83
 * @param key The key used to unlock the mutex.
84
 */
85
sint
89 by Gustav Hartvigsson
* Started working on Threads
86
s_mutex_unlock (SMutex * self);
88 by Gustav Hartvigsson
* Made the SMutex code compile.
87
77 by Gustav Hartvigsson
* More work on SStream... Requiers Mutex suppert :-)
88
/**
89
 * Check if a mutex is locked.
87 by Gustav Hartvigsson
I have no idea why this is not working...0_o...
90
 *
91
 * Note that this operation is non-atomic and may be wrong. 
92
 */
77 by Gustav Hartvigsson
* More work on SStream... Requiers Mutex suppert :-)
93
sboolean
94
s_mutex_check_lock (SMutex * self);
95
96
/** @} */
97
98
/* ****************************************************************************
89 by Gustav Hartvigsson
* Started working on Threads
99
 ********************************** SThread ***********************************
100
 **************************************************************************** */
101
102
/**
103
 * @defgroup SThread SThread
104
 * @addtogroup SThread
105
 * @{
106
 */
107
108
/**
109
 * An opaque data type representing a Thread.
110
 */
111
typedef struct SThread SThread;
112
113
/**
114
 * Creat a now Thread.
115
 */
116
SThread *
117
s_thread_new (RunFunc func);
118
119
/**
120
 * Free the thread object.
121
 */
122
void
123
s_thread_free (SThread * self);
124
125
/**
126
 * Run the thread.
127
 */
128
sboolean
129
s_thread_run (SThread * self, spointer user_data);
130
131
132
/** @} */
133
134
/** @} */
77 by Gustav Hartvigsson
* More work on SStream... Requiers Mutex suppert :-)
135
136
END_DECLS
79 by Gustav Hartvigsson
* Clean up of SMap's for each code.
137
#endif /* __H_THREAD__ */
77 by Gustav Hartvigsson
* More work on SStream... Requiers Mutex suppert :-)
138