annotate src/thread/riscos/SDL_syssem.c @ 1338:604d73db6802

Removed uses of stdlib.h and string.h
author Sam Lantinga <slouken@libsdl.org>
date Tue, 07 Feb 2006 09:29:18 +0000
parents 3692456e7b0f
children c71e05b4dc2e
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
1338
604d73db6802 Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents: 1336
diff changeset
26 #include "SDL_stdlib.h"
955
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
27 #include "SDL_error.h"
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28 #include "SDL_timer.h"
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29 #include "SDL_thread.h"
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30 #include "SDL_systhread_c.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 #ifdef DISABLE_THREADS
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 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
35 {
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36 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
37 return (SDL_sem *)0;
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
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40 void SDL_DestroySemaphore(SDL_sem *sem)
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 return;
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
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
45 int SDL_SemTryWait(SDL_sem *sem)
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 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
48 return -1;
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
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
51 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
52 {
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
53 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
54 return -1;
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
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
57 int SDL_SemWait(SDL_sem *sem)
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 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
60 return -1;
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
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
63 Uint32 SDL_SemValue(SDL_sem *sem)
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 return 0;
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
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
68 int SDL_SemPost(SDL_sem *sem)
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 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
71 return -1;
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
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
74 #else
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
75
1099
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
76
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
77 #include <unistd.h> /* For getpid() */
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
78 #include <pthread.h>
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
79 #include <semaphore.h>
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
80
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
81 struct SDL_semaphore {
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
82 sem_t *sem;
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
83 sem_t sem_data;
955
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
84 };
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
85
1099
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
86 /* 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
87 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
88 {
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
89 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
90 if ( sem ) {
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
91 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
92 SDL_SetError("sem_init() failed");
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
93 SDL_free(sem);
1099
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
94 sem = NULL;
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
95 } else {
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
96 sem->sem = &sem->sem_data;
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
97 }
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
98 } else {
955
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
99 SDL_OutOfMemory();
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
100 }
1099
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
101 return sem;
955
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
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
104 void SDL_DestroySemaphore(SDL_sem *sem)
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
105 {
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
106 if ( sem ) {
1099
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
107 sem_destroy(sem->sem);
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
108 SDL_free(sem);
955
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
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
112 int SDL_SemTryWait(SDL_sem *sem)
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 int retval;
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 if ( ! sem ) {
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
117 SDL_SetError("Passed a NULL semaphore");
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
118 return -1;
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 retval = SDL_MUTEX_TIMEDOUT;
1099
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
121 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
122 retval = 0;
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
123 }
1099
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
124 return retval;
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
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
127 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
128 {
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
129 int retval;
955
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
130
1099
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
131 if ( ! sem ) {
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
132 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
133 return -1;
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
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
136 retval = sem_wait(sem->sem);
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
137 if ( retval < 0 ) {
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
138 SDL_SetError("sem_wait() failed");
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
139 }
955
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
140 return retval;
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
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
143 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
144 {
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
145 int retval;
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 if ( ! sem ) {
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
148 SDL_SetError("Passed a NULL semaphore");
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
149 return -1;
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
1099
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
152 /* Try the easy cases first */
955
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
153 if ( timeout == 0 ) {
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
154 return SDL_SemTryWait(sem);
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 if ( timeout == SDL_MUTEX_MAXWAIT ) {
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
157 return SDL_SemWait(sem);
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
158 }
955
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 /* 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
161 timeout += SDL_GetTicks();
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
162 do {
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
163 retval = SDL_SemTryWait(sem);
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
164 if ( retval == 0 ) {
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
165 break;
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
166 }
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
167 SDL_Delay(1);
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
168 } while ( SDL_GetTicks() < timeout );
955
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
169
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
170 return retval;
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
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
173 Uint32 SDL_SemValue(SDL_sem *sem)
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
174 {
1099
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
175 int ret = 0;
955
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
176 if ( sem ) {
1099
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
177 sem_getvalue(sem->sem, &ret);
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
178 if ( ret < 0 ) {
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
179 ret = 0;
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
180 }
955
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
181 }
1099
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
182 return (Uint32)ret;
955
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
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
185 int SDL_SemPost(SDL_sem *sem)
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
186 {
1099
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
187 int retval;
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
188
955
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
189 if ( ! sem ) {
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
190 SDL_SetError("Passed a NULL semaphore");
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
191 return -1;
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
192 }
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
193
1099
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
194 retval = sem_post(sem->sem);
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
195 if ( retval < 0 ) {
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
196 SDL_SetError("sem_post() failed");
955
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 return retval;
955
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
199 }
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
200
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
201 #endif /* DISABLE_THREADS */