annotate src/thread/riscos/SDL_syssem.c @ 4102:328a3f973890 SDL-1.2

Date: Thu, 15 Nov 2007 10:33:01 +0100 From: "Marco Lopes" Subject: Compiling with Intel compiler fails I~Rve recently bought the Intel Compiler 10 for another project and decided to compile SDL with it as well. I was very surprised when it failed to compile because of the function: Error 5 error: label "endS16" was referenced but not defined ..\..\src\audio\SDL_mixer_MMX_VC.c
author Sam Lantinga <slouken@libsdl.org>
date Fri, 28 Dec 2007 18:07:59 +0000
parents 536b0704b7d8
children c121d94672cb a1b03ba2fcd0
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 */
1851
536b0704b7d8 Make sure sem_wait didn't return early with EINTR. Fixes Bugzilla #231.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
22
536b0704b7d8 Make sure sem_wait didn't return early with EINTR. Fixes Bugzilla #231.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
23 #include <errno.h>
536b0704b7d8 Make sure sem_wait didn't return early with EINTR. Fixes Bugzilla #231.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
24
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1361
diff changeset
25 #include "SDL_config.h"
955
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26
1099
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
27 /* 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
28
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30 #include "SDL_timer.h"
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
31 #include "SDL_thread.h"
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
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
34 #if !SDL_THREADS_DISABLED
955
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 <unistd.h> /* For getpid() */
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
80 #include <pthread.h>
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
81 #include <semaphore.h>
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
82
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
83 struct SDL_semaphore {
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
84 sem_t *sem;
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
85 sem_t sem_data;
955
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
86 };
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
87
1099
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
88 /* 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
89 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
90 {
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
91 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
92 if ( sem ) {
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
93 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
94 SDL_SetError("sem_init() failed");
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
95 SDL_free(sem);
1099
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
96 sem = NULL;
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
97 } else {
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
98 sem->sem = &sem->sem_data;
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
99 }
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
100 } else {
955
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
101 SDL_OutOfMemory();
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
102 }
1099
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
103 return sem;
955
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
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
106 void SDL_DestroySemaphore(SDL_sem *sem)
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 if ( sem ) {
1099
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
109 sem_destroy(sem->sem);
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
110 SDL_free(sem);
955
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 }
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 SDL_SemTryWait(SDL_sem *sem)
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 retval;
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 if ( ! sem ) {
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
119 SDL_SetError("Passed a NULL semaphore");
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
120 return -1;
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
121 }
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
122 retval = SDL_MUTEX_TIMEDOUT;
1099
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
123 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
124 retval = 0;
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
125 }
1099
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
126 return retval;
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
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
129 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
130 {
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
131 int retval;
955
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
132
1099
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
133 if ( ! sem ) {
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
134 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
135 return -1;
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
136 }
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
137
1851
536b0704b7d8 Make sure sem_wait didn't return early with EINTR. Fixes Bugzilla #231.
Ryan C. Gordon <icculus@icculus.org>
parents: 1402
diff changeset
138 while ( ((retval = sem_wait(sem->sem)) == -1) && (errno == EINTR) ) {}
1099
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
139 if ( retval < 0 ) {
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
140 SDL_SetError("sem_wait() failed");
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
141 }
955
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
142 return retval;
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
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
145 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
146 {
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
147 int retval;
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 if ( ! sem ) {
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
150 SDL_SetError("Passed a NULL semaphore");
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
151 return -1;
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
152 }
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
153
1099
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
154 /* Try the easy cases first */
955
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
155 if ( timeout == 0 ) {
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
156 return SDL_SemTryWait(sem);
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
157 }
1099
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
158 if ( timeout == SDL_MUTEX_MAXWAIT ) {
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
159 return SDL_SemWait(sem);
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
160 }
955
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
161
1099
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
162 /* 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
163 timeout += SDL_GetTicks();
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
164 do {
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
165 retval = SDL_SemTryWait(sem);
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
166 if ( retval == 0 ) {
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
167 break;
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
168 }
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
169 SDL_Delay(1);
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
170 } while ( SDL_GetTicks() < timeout );
955
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 return retval;
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
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
175 Uint32 SDL_SemValue(SDL_sem *sem)
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
176 {
1099
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
177 int ret = 0;
955
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
178 if ( sem ) {
1099
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
179 sem_getvalue(sem->sem, &ret);
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
180 if ( ret < 0 ) {
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
181 ret = 0;
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
182 }
955
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
183 }
1099
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
184 return (Uint32)ret;
955
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
185 }
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
186
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
187 int SDL_SemPost(SDL_sem *sem)
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
188 {
1099
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
189 int retval;
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
190
955
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
191 if ( ! sem ) {
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
192 SDL_SetError("Passed a NULL semaphore");
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
193 return -1;
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
194 }
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
195
1099
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
196 retval = sem_post(sem->sem);
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
197 if ( retval < 0 ) {
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
198 SDL_SetError("sem_post() failed");
955
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
199 }
1099
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
200 return retval;
955
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
201 }
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
202
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
203 #endif /* !SDL_THREADS_DISABLED */