1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
|
//============================================================
//
// sdlsync.h - SDL core synchronization functions
//
// Copyright (c) 1996-2007, Nicola Salmoria and the MAME Team.
// Visit http://mamedev.org for licensing and usage restrictions.
//
// SDLMAME by Olivier Galibert and R. Belmont
//
//============================================================
#ifndef __SDLSYNC__
#define __SDLSYNC__
/***************************************************************************
SYNCHRONIZATION INTERFACES - Events
***************************************************************************/
/* osd_event is an opaque type which represents a setable/resetable event */
typedef struct _osd_event osd_event;
/*-----------------------------------------------------------------------------
osd_lock_event_alloc: allocate a new event
Parameters:
manualreset - boolean. If true, the event will be automatically set
to non-signalled after a thread successfully waited for
it.
initialstate - boolean. If true, the event is signalled initially.
Return value:
A pointer to the allocated event.
-----------------------------------------------------------------------------*/
osd_event *osd_event_alloc(int manualreset, int initialstate);
/*-----------------------------------------------------------------------------
osd_event_wait: wait for an event to be signalled
Parameters:
event - The event to wait for. If the event is in signalled state, the
function returns immediately. If not it will wait for the event
to become signalled.
timeout - timeout in osd_ticks
Return value:
TRUE: The event was signalled
FALSE: A timeout occurred
-----------------------------------------------------------------------------*/
int osd_event_wait(osd_event *event, osd_ticks_t timeout);
/*-----------------------------------------------------------------------------
osd_event_reset: reset an event to non-signalled state
Parameters:
event - The event to set to non-signalled state
Return value:
None
-----------------------------------------------------------------------------*/
void osd_event_reset(osd_event *event);
/*-----------------------------------------------------------------------------
osd_event_set: set an event to signalled state
Parameters:
event - The event to set to signalled state
Return value:
None
Notes:
All threads waiting for the event will be signalled.
-----------------------------------------------------------------------------*/
void osd_event_set(osd_event *event);
/*-----------------------------------------------------------------------------
osd_event_free: free the memory and resources associated with an osd_event
Parameters:
event - a pointer to a previously allocated osd_event.
Return value:
None.
-----------------------------------------------------------------------------*/
void osd_event_free(osd_event *event);
/***************************************************************************
SYNCHRONIZATION INTERFACES - Threads
***************************************************************************/
/* osd_thread is an opaque type which represents a thread */
typedef struct _osd_thread osd_thread;
/* osd_thread_callback is a callback function that will be called from the thread */
typedef void *(*osd_thread_callback)(void *param);
/*-----------------------------------------------------------------------------
osd_thread_create: create a new thread
Parameters:
callback - The callback function to be called once the thread is up
cbparam - The parameter to pass to the callback function.
Return value:
A pointer to the created thread.
-----------------------------------------------------------------------------*/
osd_thread *osd_thread_create(osd_thread_callback callback, void *cbparam);
/*-----------------------------------------------------------------------------
osd_thread_adjust_priority: adjust priority of a thread
Parameters:
thread - A pointer to a previously created thread.
adjust - signed integer to add to the thread priority
Return value:
TRUE on success, FALSE on failure
-----------------------------------------------------------------------------*/
int osd_thread_adjust_priority(osd_thread *thread, int adjust);
/*-----------------------------------------------------------------------------
osd_thread_cpu_affinity: change cpu affinity of a thread
Parameters:
thread - A pointer to a previously created thread
or NULL for main thread
mask - bitmask to which cpus to bind
i.e. 0x01 1st cpu, 0x02, 2nd cpu, 0x04 3rd cpu
Return value:
TRUE on success, FALSE on failure
-----------------------------------------------------------------------------*/
int osd_thread_cpu_affinity(osd_thread *thread, UINT32 mask);
/*-----------------------------------------------------------------------------
osd_thread_wait_free: wait for thread to finish and free resources
Parameters:
thread - A pointer to a previously created thread.
Return value:
None.
-----------------------------------------------------------------------------*/
void osd_thread_wait_free(osd_thread *thread);
//============================================================
// Scalable Locks
//============================================================
typedef struct _osd_scalable_lock osd_scalable_lock;
osd_scalable_lock *osd_scalable_lock_alloc(void);
INT32 osd_scalable_lock_acquire(osd_scalable_lock *lock);
void osd_scalable_lock_release(osd_scalable_lock *lock, INT32 myslot);
void osd_scalable_lock_free(osd_scalable_lock *lock);
#endif /* __SDLSYNC__ */
|