Mercurial > sdl-ios-xcode
comparison src/thread/dc/SDL_syssem.c @ 1662:782fd950bd46 SDL-1.3
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid.
The code is now run through a consistent indent format:
indent -i4 -nut -nsc -br -ce
The headers are being converted to automatically generate doxygen documentation.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 28 May 2006 13:04:16 +0000 |
parents | d910939febfa |
children | 4da1ee79c9af |
comparison
equal
deleted
inserted
replaced
1661:281d3f4870e5 | 1662:782fd950bd46 |
---|---|
28 #include "SDL_systhread_c.h" | 28 #include "SDL_systhread_c.h" |
29 | 29 |
30 | 30 |
31 #if SDL_THREADS_DISABLED | 31 #if SDL_THREADS_DISABLED |
32 | 32 |
33 SDL_sem *SDL_CreateSemaphore(Uint32 initial_value) | 33 SDL_sem * |
34 SDL_CreateSemaphore (Uint32 initial_value) | |
34 { | 35 { |
35 SDL_SetError("SDL not configured with thread support"); | 36 SDL_SetError ("SDL not configured with thread support"); |
36 return (SDL_sem *)0; | 37 return (SDL_sem *) 0; |
37 } | 38 } |
38 | 39 |
39 void SDL_DestroySemaphore(SDL_sem *sem) | 40 void |
41 SDL_DestroySemaphore (SDL_sem * sem) | |
40 { | 42 { |
41 return; | 43 return; |
42 } | 44 } |
43 | 45 |
44 int SDL_SemTryWait(SDL_sem *sem) | 46 int |
47 SDL_SemTryWait (SDL_sem * sem) | |
45 { | 48 { |
46 SDL_SetError("SDL not configured with thread support"); | 49 SDL_SetError ("SDL not configured with thread support"); |
47 return -1; | 50 return -1; |
48 } | 51 } |
49 | 52 |
50 int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout) | 53 int |
54 SDL_SemWaitTimeout (SDL_sem * sem, Uint32 timeout) | |
51 { | 55 { |
52 SDL_SetError("SDL not configured with thread support"); | 56 SDL_SetError ("SDL not configured with thread support"); |
53 return -1; | 57 return -1; |
54 } | 58 } |
55 | 59 |
56 int SDL_SemWait(SDL_sem *sem) | 60 int |
61 SDL_SemWait (SDL_sem * sem) | |
57 { | 62 { |
58 SDL_SetError("SDL not configured with thread support"); | 63 SDL_SetError ("SDL not configured with thread support"); |
59 return -1; | 64 return -1; |
60 } | 65 } |
61 | 66 |
62 Uint32 SDL_SemValue(SDL_sem *sem) | 67 Uint32 |
68 SDL_SemValue (SDL_sem * sem) | |
63 { | 69 { |
64 return 0; | 70 return 0; |
65 } | 71 } |
66 | 72 |
67 int SDL_SemPost(SDL_sem *sem) | 73 int |
74 SDL_SemPost (SDL_sem * sem) | |
68 { | 75 { |
69 SDL_SetError("SDL not configured with thread support"); | 76 SDL_SetError ("SDL not configured with thread support"); |
70 return -1; | 77 return -1; |
71 } | 78 } |
72 | 79 |
73 #else | 80 #else |
74 | 81 |
75 #include <kos/sem.h> | 82 #include <kos/sem.h> |
76 | 83 |
77 struct SDL_semaphore | 84 struct SDL_semaphore |
78 { | 85 { |
79 semaphore_t sem; | 86 semaphore_t sem; |
80 }; | 87 }; |
81 | 88 |
82 SDL_sem *SDL_CreateSemaphore(Uint32 initial_value) | 89 SDL_sem * |
90 SDL_CreateSemaphore (Uint32 initial_value) | |
83 { | 91 { |
84 return (SDL_sem *)sem_create(initial_value); | 92 return (SDL_sem *) sem_create (initial_value); |
85 } | 93 } |
86 | 94 |
87 /* WARNING: | 95 /* WARNING: |
88 You cannot call this function when another thread is using the semaphore. | 96 You cannot call this function when another thread is using the semaphore. |
89 */ | 97 */ |
90 void SDL_DestroySemaphore(SDL_sem *sem) | 98 void |
99 SDL_DestroySemaphore (SDL_sem * sem) | |
91 { | 100 { |
92 if ( ! sem ) { | 101 if (!sem) { |
93 SDL_SetError("Passed a NULL semaphore"); | 102 SDL_SetError ("Passed a NULL semaphore"); |
94 return; | 103 return; |
95 } | 104 } |
96 | 105 |
97 sem_destroy(&sem->sem); | 106 sem_destroy (&sem->sem); |
98 } | 107 } |
99 | 108 |
100 int SDL_SemTryWait(SDL_sem *sem) | 109 int |
110 SDL_SemTryWait (SDL_sem * sem) | |
101 { | 111 { |
102 int retval; | 112 int retval; |
103 | 113 |
104 if ( ! sem ) { | 114 if (!sem) { |
105 SDL_SetError("Passed a NULL semaphore"); | 115 SDL_SetError ("Passed a NULL semaphore"); |
106 return -1; | 116 return -1; |
107 } | 117 } |
108 | 118 |
109 retval = sem_trywait(&sem->sem); | 119 retval = sem_trywait (&sem->sem); |
110 if (retval==0) return 0; | 120 if (retval == 0) |
111 else return SDL_MUTEX_TIMEDOUT; | 121 return 0; |
122 else | |
123 return SDL_MUTEX_TIMEDOUT; | |
112 | 124 |
113 return retval; | 125 return retval; |
114 } | 126 } |
115 | 127 |
116 int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout) | 128 int |
129 SDL_SemWaitTimeout (SDL_sem * sem, Uint32 timeout) | |
117 { | 130 { |
118 int retval; | 131 int retval; |
119 | 132 |
120 if ( ! sem ) { | 133 if (!sem) { |
121 SDL_SetError("Passed a NULL semaphore"); | 134 SDL_SetError ("Passed a NULL semaphore"); |
122 return -1; | 135 return -1; |
123 } | 136 } |
124 | 137 |
125 /* A timeout of 0 is an easy case */ | 138 /* A timeout of 0 is an easy case */ |
126 if ( timeout == 0 ) { | 139 if (timeout == 0) { |
127 return SDL_SemTryWait(sem); | 140 return SDL_SemTryWait (sem); |
128 } | 141 } |
129 | 142 |
130 retval = sem_wait_timed(&sem->sem,timeout); | 143 retval = sem_wait_timed (&sem->sem, timeout); |
131 if (retval==-1) retval= SDL_MUTEX_TIMEDOUT; | 144 if (retval == -1) |
145 retval = SDL_MUTEX_TIMEDOUT; | |
132 | 146 |
133 return retval; | 147 return retval; |
134 } | 148 } |
135 | 149 |
136 int SDL_SemWait(SDL_sem *sem) | 150 int |
151 SDL_SemWait (SDL_sem * sem) | |
137 { | 152 { |
138 if ( ! sem ) { | 153 if (!sem) { |
139 SDL_SetError("Passed a NULL semaphore"); | 154 SDL_SetError ("Passed a NULL semaphore"); |
140 return -1; | 155 return -1; |
141 } | 156 } |
142 | 157 |
143 sem_wait(&sem->sem); | 158 sem_wait (&sem->sem); |
144 return 0; | 159 return 0; |
145 } | 160 } |
146 | 161 |
147 Uint32 SDL_SemValue(SDL_sem *sem) | 162 Uint32 |
163 SDL_SemValue (SDL_sem * sem) | |
148 { | 164 { |
149 if ( ! sem ) { | 165 if (!sem) { |
150 SDL_SetError("Passed a NULL semaphore"); | 166 SDL_SetError ("Passed a NULL semaphore"); |
151 return -1; | 167 return -1; |
152 } | 168 } |
153 | 169 |
154 return sem_count(&sem->sem); | 170 return sem_count (&sem->sem); |
155 } | 171 } |
156 | 172 |
157 int SDL_SemPost(SDL_sem *sem) | 173 int |
174 SDL_SemPost (SDL_sem * sem) | |
158 { | 175 { |
159 if ( ! sem ) { | 176 if (!sem) { |
160 SDL_SetError("Passed a NULL semaphore"); | 177 SDL_SetError ("Passed a NULL semaphore"); |
161 return -1; | 178 return -1; |
162 } | 179 } |
163 | 180 |
164 sem_signal(&sem->sem); | 181 sem_signal (&sem->sem); |
165 return 0; | 182 return 0; |
166 } | 183 } |
167 | 184 |
168 #endif /* SDL_THREADS_DISABLED */ | 185 #endif /* SDL_THREADS_DISABLED */ |
186 /* vi: set ts=4 sw=4 expandtab: */ |