Mercurial > sdl-ios-xcode
annotate src/thread/riscos/SDL_syssem.c @ 1514:e9d781fca1ae
Added SDL_iconv.c to the Embedded Visual C++ projects
Added missing target configurations
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 13 Mar 2006 02:35:32 +0000 |
parents | d910939febfa |
children | 782fd950bd46 536b0704b7d8 |
rev | line source |
---|---|
955
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1 /* |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
2 SDL - Simple DirectMedia Layer |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1099
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
955
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
4 |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
5 This library is free software; you can redistribute it and/or |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1099
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
955
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
7 License as published by the Free Software Foundation; either |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1099
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
955
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
9 |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
10 This library is distributed in the hope that it will be useful, |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1099
diff
changeset
|
13 Lesser General Public License for more details. |
955
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1099
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1099
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
1099
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
955
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
18 |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
19 Sam Lantinga |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
20 slouken@libsdl.org |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
21 */ |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
22 #include "SDL_config.h" |
955
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
23 |
1099
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
24 /* RISC OS semiphores based on linux code */ |
955
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
25 |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
26 |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
27 #include "SDL_timer.h" |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
28 #include "SDL_thread.h" |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
29 #include "SDL_systhread_c.h" |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
30 |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
31 #if !SDL_THREADS_DISABLED |
955
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
32 |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
33 SDL_sem *SDL_CreateSemaphore(Uint32 initial_value) |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
34 { |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
35 SDL_SetError("SDL not configured with thread support"); |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
36 return (SDL_sem *)0; |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
37 } |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
38 |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
39 void SDL_DestroySemaphore(SDL_sem *sem) |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
40 { |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
41 return; |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
42 } |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
43 |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
44 int SDL_SemTryWait(SDL_sem *sem) |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
45 { |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
46 SDL_SetError("SDL not configured with thread support"); |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
47 return -1; |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
48 } |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
49 |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
50 int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout) |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
51 { |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
52 SDL_SetError("SDL not configured with thread support"); |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
53 return -1; |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
54 } |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
55 |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
56 int SDL_SemWait(SDL_sem *sem) |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
57 { |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
58 SDL_SetError("SDL not configured with thread support"); |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
59 return -1; |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
60 } |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
61 |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
62 Uint32 SDL_SemValue(SDL_sem *sem) |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
63 { |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
64 return 0; |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
65 } |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
66 |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
67 int SDL_SemPost(SDL_sem *sem) |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
68 { |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
69 SDL_SetError("SDL not configured with thread support"); |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
70 return -1; |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
71 } |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
72 |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
73 #else |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
74 |
1099
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
75 |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
76 #include <unistd.h> /* For getpid() */ |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
77 #include <pthread.h> |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
78 #include <semaphore.h> |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
79 |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
80 struct SDL_semaphore { |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
81 sem_t *sem; |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
82 sem_t sem_data; |
955
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
83 }; |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
84 |
1099
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
85 /* Create a semaphore, initialized with value */ |
955
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
86 SDL_sem *SDL_CreateSemaphore(Uint32 initial_value) |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
87 { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
88 SDL_sem *sem = (SDL_sem *) SDL_malloc(sizeof(SDL_sem)); |
1099
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
89 if ( sem ) { |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
90 if ( sem_init(&sem->sem_data, 0, initial_value) < 0 ) { |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
91 SDL_SetError("sem_init() failed"); |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
92 SDL_free(sem); |
1099
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
93 sem = NULL; |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
94 } else { |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
95 sem->sem = &sem->sem_data; |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
96 } |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
97 } else { |
955
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
98 SDL_OutOfMemory(); |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
99 } |
1099
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
100 return sem; |
955
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
101 } |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
102 |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
103 void SDL_DestroySemaphore(SDL_sem *sem) |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
104 { |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
105 if ( sem ) { |
1099
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
106 sem_destroy(sem->sem); |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
107 SDL_free(sem); |
955
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
108 } |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
109 } |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
110 |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
111 int SDL_SemTryWait(SDL_sem *sem) |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
112 { |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
113 int retval; |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
114 |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
115 if ( ! sem ) { |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
116 SDL_SetError("Passed a NULL semaphore"); |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
117 return -1; |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
118 } |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
119 retval = SDL_MUTEX_TIMEDOUT; |
1099
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
120 if ( sem_trywait(sem->sem) == 0 ) { |
955
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
121 retval = 0; |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
122 } |
1099
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
123 return retval; |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
124 } |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
125 |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
126 int SDL_SemWait(SDL_sem *sem) |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
127 { |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
128 int retval; |
955
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
129 |
1099
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
130 if ( ! sem ) { |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
131 SDL_SetError("Passed a NULL semaphore"); |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
132 return -1; |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
133 } |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
134 |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
135 retval = sem_wait(sem->sem); |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
136 if ( retval < 0 ) { |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
137 SDL_SetError("sem_wait() failed"); |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
138 } |
955
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
139 return retval; |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
140 } |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
141 |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
142 int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout) |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
143 { |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
144 int retval; |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
145 |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
146 if ( ! sem ) { |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
147 SDL_SetError("Passed a NULL semaphore"); |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
148 return -1; |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
149 } |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
150 |
1099
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
151 /* Try the easy cases first */ |
955
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
152 if ( timeout == 0 ) { |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
153 return SDL_SemTryWait(sem); |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
154 } |
1099
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
155 if ( timeout == SDL_MUTEX_MAXWAIT ) { |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
156 return SDL_SemWait(sem); |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
157 } |
955
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
158 |
1099
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
159 /* Ack! We have to busy wait... */ |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
160 timeout += SDL_GetTicks(); |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
161 do { |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
162 retval = SDL_SemTryWait(sem); |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
163 if ( retval == 0 ) { |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
164 break; |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
165 } |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
166 SDL_Delay(1); |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
167 } while ( SDL_GetTicks() < timeout ); |
955
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
168 |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
169 return retval; |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
170 } |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
171 |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
172 Uint32 SDL_SemValue(SDL_sem *sem) |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
173 { |
1099
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
174 int ret = 0; |
955
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
175 if ( sem ) { |
1099
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
176 sem_getvalue(sem->sem, &ret); |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
177 if ( ret < 0 ) { |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
178 ret = 0; |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
179 } |
955
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
180 } |
1099
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
181 return (Uint32)ret; |
955
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
182 } |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
183 |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
184 int SDL_SemPost(SDL_sem *sem) |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
185 { |
1099
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
186 int retval; |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
187 |
955
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
188 if ( ! sem ) { |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
189 SDL_SetError("Passed a NULL semaphore"); |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
190 return -1; |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
191 } |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
192 |
1099
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
193 retval = sem_post(sem->sem); |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
194 if ( retval < 0 ) { |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
195 SDL_SetError("sem_post() failed"); |
955
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
196 } |
1099
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
197 return retval; |
955
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
198 } |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
199 |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
200 #endif /* !SDL_THREADS_DISABLED */ |