Mercurial > sdl-ios-xcode
annotate src/thread/riscos/SDL_syssem.c @ 1336:3692456e7b0f
Use SDL_ prefixed versions of C library functions.
FIXME:
Change #include <stdlib.h> to #include "SDL_stdlib.h"
Change #include <string.h> to #include "SDL_string.h"
Make sure nothing else broke because of this...
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 07 Feb 2006 06:59:48 +0000 |
parents | c9b51268668f |
children | 604d73db6802 |
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 */ |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
22 |
1099
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
23 /* 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
|
24 |
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 #include <stdlib.h> |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
27 |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
28 #include "SDL_error.h" |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
29 #include "SDL_timer.h" |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
30 #include "SDL_thread.h" |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
31 |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
32 #include "SDL_systhread_c.h" |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
33 |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
34 #ifdef DISABLE_THREADS |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
35 |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
36 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
|
37 { |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
38 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
|
39 return (SDL_sem *)0; |
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 |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
42 void SDL_DestroySemaphore(SDL_sem *sem) |
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 return; |
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 |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
47 int SDL_SemTryWait(SDL_sem *sem) |
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 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
|
50 return -1; |
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 |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
53 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
|
54 { |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
55 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
|
56 return -1; |
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 |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
59 int SDL_SemWait(SDL_sem *sem) |
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 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
|
62 return -1; |
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 |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
65 Uint32 SDL_SemValue(SDL_sem *sem) |
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 return 0; |
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 |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
70 int SDL_SemPost(SDL_sem *sem) |
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 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
|
73 return -1; |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
74 } |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
75 |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
76 #else |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
77 |
1099
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
78 |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
79 #include <stdio.h> |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
80 #include <stdlib.h> |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
81 #include <unistd.h> /* For getpid() */ |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
82 #include <pthread.h> |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
83 #include <semaphore.h> |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
84 |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
85 struct SDL_semaphore { |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
86 sem_t *sem; |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
87 sem_t sem_data; |
955
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
88 }; |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
89 |
1099
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
90 /* 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
|
91 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
|
92 { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
93 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
|
94 if ( sem ) { |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
95 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
|
96 SDL_SetError("sem_init() failed"); |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
97 SDL_free(sem); |
1099
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
98 sem = NULL; |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
99 } else { |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
100 sem->sem = &sem->sem_data; |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
101 } |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
102 } else { |
955
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
103 SDL_OutOfMemory(); |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
104 } |
1099
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
105 return sem; |
955
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
106 } |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
107 |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
108 void SDL_DestroySemaphore(SDL_sem *sem) |
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 if ( sem ) { |
1099
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
111 sem_destroy(sem->sem); |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
112 SDL_free(sem); |
955
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
113 } |
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 |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
116 int SDL_SemTryWait(SDL_sem *sem) |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
117 { |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
118 int retval; |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
119 |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
120 if ( ! sem ) { |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
121 SDL_SetError("Passed a NULL semaphore"); |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
122 return -1; |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
123 } |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
124 retval = SDL_MUTEX_TIMEDOUT; |
1099
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
125 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
|
126 retval = 0; |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
127 } |
1099
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
128 return retval; |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
129 } |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
130 |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
131 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
|
132 { |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
133 int retval; |
955
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
134 |
1099
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
135 if ( ! sem ) { |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
136 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
|
137 return -1; |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
138 } |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
139 |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
140 retval = sem_wait(sem->sem); |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
141 if ( retval < 0 ) { |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
142 SDL_SetError("sem_wait() failed"); |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
143 } |
955
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
144 return 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 |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
147 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
|
148 { |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
149 int retval; |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
150 |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
151 if ( ! sem ) { |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
152 SDL_SetError("Passed a NULL semaphore"); |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
153 return -1; |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
154 } |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
155 |
1099
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
156 /* Try the easy cases first */ |
955
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
157 if ( timeout == 0 ) { |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
158 return SDL_SemTryWait(sem); |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
159 } |
1099
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
160 if ( timeout == SDL_MUTEX_MAXWAIT ) { |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
161 return SDL_SemWait(sem); |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
162 } |
955
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
163 |
1099
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
164 /* 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
|
165 timeout += SDL_GetTicks(); |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
166 do { |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
167 retval = SDL_SemTryWait(sem); |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
168 if ( retval == 0 ) { |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
169 break; |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
170 } |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
171 SDL_Delay(1); |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
172 } while ( SDL_GetTicks() < timeout ); |
955
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
173 |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
174 return retval; |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
175 } |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
176 |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
177 Uint32 SDL_SemValue(SDL_sem *sem) |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
178 { |
1099
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
179 int ret = 0; |
955
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
180 if ( sem ) { |
1099
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
181 sem_getvalue(sem->sem, &ret); |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
182 if ( ret < 0 ) { |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
183 ret = 0; |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
184 } |
955
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 return (Uint32)ret; |
955
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
187 } |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
188 |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
189 int SDL_SemPost(SDL_sem *sem) |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
190 { |
1099
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
191 int retval; |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
192 |
955
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
193 if ( ! sem ) { |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
194 SDL_SetError("Passed a NULL semaphore"); |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
195 return -1; |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
196 } |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
197 |
1099
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
198 retval = sem_post(sem->sem); |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
199 if ( retval < 0 ) { |
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
200 SDL_SetError("sem_post() failed"); |
955
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
201 } |
1099
1ccbb2b7d905
Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
955
diff
changeset
|
202 return retval; |
955
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
203 } |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
204 |
d74fbf56f2f6
Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
205 #endif /* DISABLE_THREADS */ |