annotate src/thread/riscos/SDL_syssem.c @ 1266:a7bea6db3c3e

SDL_GetVideoMode, part 3: pixel count compare was failing when only 1 video mode was present
author Patrice Mandin <patmandin@gmail.com>
date Wed, 25 Jan 2006 18:11:56 +0000
parents 1ccbb2b7d905
children c9b51268668f
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
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3 Copyright (C) 1997-2004 Sam Lantinga
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
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6 modify it under the terms of the GNU Library General Public
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
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 version 2 of the License, or (at your option) any later version.
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
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13 Library General Public License for more details.
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15 You should have received a copy of the GNU Library General Public
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
16 License along with this library; if not, write to the Free
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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 #ifdef SAVE_RCSID
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26 static char rcsid =
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
27 "@(#) $Id$";
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28 #endif
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
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
31 #include <stdlib.h>
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 #include "SDL_error.h"
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
34 #include "SDL_timer.h"
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
35 #include "SDL_thread.h"
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
37 #include "SDL_systhread_c.h"
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 #ifdef DISABLE_THREADS
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 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
42 {
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
43 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
44 return (SDL_sem *)0;
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 void SDL_DestroySemaphore(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 return;
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
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
52 int SDL_SemTryWait(SDL_sem *sem)
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
53 {
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
54 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
55 return -1;
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
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
58 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
59 {
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
60 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
61 return -1;
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
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
64 int SDL_SemWait(SDL_sem *sem)
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 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
67 return -1;
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 Uint32 SDL_SemValue(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 return 0;
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
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
75 int SDL_SemPost(SDL_sem *sem)
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
76 {
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
77 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
78 return -1;
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
79 }
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
80
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
81 #else
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
82
1099
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
83
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
84 #include <stdio.h>
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
85 #include <stdlib.h>
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
86 #include <unistd.h> /* For getpid() */
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
87 #include <pthread.h>
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
88 #include <semaphore.h>
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
89
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
90 struct SDL_semaphore {
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
91 sem_t *sem;
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
92 sem_t sem_data;
955
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
93 };
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
94
1099
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
95 /* 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
96 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
97 {
1099
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
98 SDL_sem *sem = (SDL_sem *) malloc(sizeof(SDL_sem));
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
99 if ( sem ) {
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
100 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
101 SDL_SetError("sem_init() failed");
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
102 free(sem);
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
103 sem = NULL;
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
104 } else {
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
105 sem->sem = &sem->sem_data;
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
106 }
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
107 } else {
955
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
108 SDL_OutOfMemory();
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
109 }
1099
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
110 return 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 void SDL_DestroySemaphore(SDL_sem *sem)
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 ) {
1099
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
116 sem_destroy(sem->sem);
955
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
117 free(sem);
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 }
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
120
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
121 int SDL_SemTryWait(SDL_sem *sem)
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
122 {
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
123 int retval;
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
124
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
125 if ( ! sem ) {
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
126 SDL_SetError("Passed a NULL semaphore");
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
127 return -1;
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
128 }
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
129 retval = SDL_MUTEX_TIMEDOUT;
1099
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
130 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
131 retval = 0;
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 return retval;
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 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
137 {
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
138 int retval;
955
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
139
1099
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
140 if ( ! sem ) {
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
141 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
142 return -1;
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
143 }
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
144
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
145 retval = sem_wait(sem->sem);
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
146 if ( retval < 0 ) {
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
147 SDL_SetError("sem_wait() failed");
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
148 }
955
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
149 return 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
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
152 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
153 {
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
154 int retval;
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
155
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
156 if ( ! sem ) {
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
157 SDL_SetError("Passed a NULL semaphore");
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
158 return -1;
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
159 }
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
160
1099
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
161 /* Try the easy cases first */
955
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
162 if ( timeout == 0 ) {
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
163 return SDL_SemTryWait(sem);
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
164 }
1099
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
165 if ( timeout == SDL_MUTEX_MAXWAIT ) {
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
166 return SDL_SemWait(sem);
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
167 }
955
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
168
1099
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
169 /* 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
170 timeout += SDL_GetTicks();
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
171 do {
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
172 retval = SDL_SemTryWait(sem);
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
173 if ( retval == 0 ) {
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
174 break;
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
175 }
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
176 SDL_Delay(1);
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
177 } while ( SDL_GetTicks() < timeout );
955
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
178
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
179 return retval;
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
180 }
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
181
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
182 Uint32 SDL_SemValue(SDL_sem *sem)
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 int ret = 0;
955
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
185 if ( sem ) {
1099
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
186 sem_getvalue(sem->sem, &ret);
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
187 if ( ret < 0 ) {
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
188 ret = 0;
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
189 }
955
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 return (Uint32)ret;
955
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
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
194 int SDL_SemPost(SDL_sem *sem)
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 int retval;
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
197
955
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
198 if ( ! sem ) {
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
199 SDL_SetError("Passed a NULL semaphore");
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
200 return -1;
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
1099
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
203 retval = sem_post(sem->sem);
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
204 if ( retval < 0 ) {
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
205 SDL_SetError("sem_post() failed");
955
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
206 }
1099
1ccbb2b7d905 Date: Fri, 15 Jul 2005 08:29:01 +0100
Sam Lantinga <slouken@libsdl.org>
parents: 955
diff changeset
207 return retval;
955
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
208 }
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
209
d74fbf56f2f6 Date: Fri, 25 Jun 2004 13:29:15 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
210 #endif /* DISABLE_THREADS */