Mercurial > sdl-ios-xcode
comparison src/thread/amigaos/SDL_syssem.c @ 1361:19418e4422cb
New configure-based build system. Still work in progress, but much improved
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 16 Feb 2006 10:11:48 +0000 |
parents | c71e05b4dc2e |
children | d910939febfa |
comparison
equal
deleted
inserted
replaced
1360:70a9cfb4cf1b | 1361:19418e4422cb |
---|---|
27 | 27 |
28 | 28 |
29 struct SDL_semaphore | 29 struct SDL_semaphore |
30 { | 30 { |
31 struct SignalSemaphore Sem; | 31 struct SignalSemaphore Sem; |
32 Uint32 count; | |
33 Uint32 waiters_count; | |
34 SDL_mutex *count_lock; | |
35 SDL_cond *count_nonzero; | |
36 }; | 32 }; |
37 | 33 |
38 #undef D | 34 #undef D |
39 | 35 |
40 #define D(x) | 36 #define D(x) |
96 | 92 |
97 D(bug("WaitTimeout (%ld) semaphore...%lx\n",timeout,sem)); | 93 D(bug("WaitTimeout (%ld) semaphore...%lx\n",timeout,sem)); |
98 | 94 |
99 /* A timeout of 0 is an easy case */ | 95 /* A timeout of 0 is an easy case */ |
100 if ( timeout == 0 ) { | 96 if ( timeout == 0 ) { |
101 return SDL_SemTryWait(sem); | 97 ObtainSemaphore(&sem->Sem); |
98 return 1; | |
102 } | 99 } |
103 /* | |
104 SDL_LockMutex(sem->count_lock); | |
105 ++sem->waiters_count; | |
106 retval = 0; | |
107 while ( (sem->count == 0) && (retval != SDL_MUTEX_TIMEDOUT) ) { | |
108 retval = SDL_CondWaitTimeout(sem->count_nonzero, | |
109 sem->count_lock, timeout); | |
110 } | |
111 --sem->waiters_count; | |
112 --sem->count; | |
113 SDL_UnlockMutex(sem->count_lock); | |
114 */ | |
115 if(!(retval=AttemptSemaphore(&sem->Sem))) | 100 if(!(retval=AttemptSemaphore(&sem->Sem))) |
116 { | 101 { |
117 SDL_Delay(timeout); | 102 SDL_Delay(timeout); |
118 retval=AttemptSemaphore(&sem->Sem); | 103 retval=AttemptSemaphore(&sem->Sem); |
119 } | 104 } |
129 | 114 |
130 int SDL_SemWait(SDL_sem *sem) | 115 int SDL_SemWait(SDL_sem *sem) |
131 { | 116 { |
132 ObtainSemaphore(&sem->Sem); | 117 ObtainSemaphore(&sem->Sem); |
133 return 0; | 118 return 0; |
134 // return SDL_SemWaitTimeout(sem, SDL_MUTEX_MAXWAIT); | |
135 } | 119 } |
136 | 120 |
137 Uint32 SDL_SemValue(SDL_sem *sem) | 121 Uint32 SDL_SemValue(SDL_sem *sem) |
138 { | 122 { |
139 Uint32 value; | 123 Uint32 value; |
143 #ifdef STORMC4_WOS | 127 #ifdef STORMC4_WOS |
144 value = sem->Sem.ssppc_SS.ss_NestCount; | 128 value = sem->Sem.ssppc_SS.ss_NestCount; |
145 #else | 129 #else |
146 value = sem->Sem.ss_NestCount; | 130 value = sem->Sem.ss_NestCount; |
147 #endif | 131 #endif |
148 // SDL_UnlockMutex(sem->count_lock); | |
149 } | 132 } |
150 return value; | 133 return value; |
151 } | 134 } |
152 | 135 |
153 int SDL_SemPost(SDL_sem *sem) | 136 int SDL_SemPost(SDL_sem *sem) |
157 return -1; | 140 return -1; |
158 } | 141 } |
159 D(bug("SemPost semaphore...%lx\n",sem)); | 142 D(bug("SemPost semaphore...%lx\n",sem)); |
160 | 143 |
161 ReleaseSemaphore(&sem->Sem); | 144 ReleaseSemaphore(&sem->Sem); |
162 #if 0 | |
163 SDL_LockMutex(sem->count_lock); | |
164 if ( sem->waiters_count > 0 ) { | |
165 SDL_CondSignal(sem->count_nonzero); | |
166 } | |
167 ++sem->count; | |
168 SDL_UnlockMutex(sem->count_lock); | |
169 #endif | |
170 return 0; | 145 return 0; |
171 } | 146 } |
172 | 147 |