comparison src/thread/beos/SDL_syssem.c @ 1668:4da1ee79c9af SDL-1.3

more tweaking indent options
author Sam Lantinga <slouken@libsdl.org>
date Mon, 29 May 2006 04:04:35 +0000
parents 782fd950bd46
children
comparison
equal deleted inserted replaced
1667:1fddae038bc8 1668:4da1ee79c9af
33 sem_id id; 33 sem_id id;
34 }; 34 };
35 35
36 /* Create a counting semaphore */ 36 /* Create a counting semaphore */
37 SDL_sem * 37 SDL_sem *
38 SDL_CreateSemaphore (Uint32 initial_value) 38 SDL_CreateSemaphore(Uint32 initial_value)
39 { 39 {
40 SDL_sem *sem; 40 SDL_sem *sem;
41 41
42 sem = (SDL_sem *) SDL_malloc (sizeof (*sem)); 42 sem = (SDL_sem *) SDL_malloc(sizeof(*sem));
43 if (sem) { 43 if (sem) {
44 sem->id = create_sem (initial_value, "SDL semaphore"); 44 sem->id = create_sem(initial_value, "SDL semaphore");
45 if (sem->id < B_NO_ERROR) { 45 if (sem->id < B_NO_ERROR) {
46 SDL_SetError ("create_sem() failed"); 46 SDL_SetError("create_sem() failed");
47 SDL_free (sem); 47 SDL_free(sem);
48 sem = NULL; 48 sem = NULL;
49 } 49 }
50 } else { 50 } else {
51 SDL_OutOfMemory (); 51 SDL_OutOfMemory();
52 } 52 }
53 return (sem); 53 return (sem);
54 } 54 }
55 55
56 /* Free the semaphore */ 56 /* Free the semaphore */
57 void 57 void
58 SDL_DestroySemaphore (SDL_sem * sem) 58 SDL_DestroySemaphore(SDL_sem * sem)
59 { 59 {
60 if (sem) { 60 if (sem) {
61 if (sem->id >= B_NO_ERROR) { 61 if (sem->id >= B_NO_ERROR) {
62 delete_sem (sem->id); 62 delete_sem(sem->id);
63 } 63 }
64 SDL_free (sem); 64 SDL_free(sem);
65 } 65 }
66 } 66 }
67 67
68 int 68 int
69 SDL_SemWaitTimeout (SDL_sem * sem, Uint32 timeout) 69 SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout)
70 { 70 {
71 int32 val; 71 int32 val;
72 int retval; 72 int retval;
73 73
74 if (!sem) { 74 if (!sem) {
75 SDL_SetError ("Passed a NULL semaphore"); 75 SDL_SetError("Passed a NULL semaphore");
76 return -1; 76 return -1;
77 } 77 }
78 78
79 tryagain: 79 tryagain:
80 if (timeout == SDL_MUTEX_MAXWAIT) { 80 if (timeout == SDL_MUTEX_MAXWAIT) {
81 val = acquire_sem (sem->id); 81 val = acquire_sem(sem->id);
82 } else { 82 } else {
83 timeout *= 1000; /* BeOS uses a timeout in microseconds */ 83 timeout *= 1000; /* BeOS uses a timeout in microseconds */
84 val = acquire_sem_etc (sem->id, 1, B_RELATIVE_TIMEOUT, timeout); 84 val = acquire_sem_etc(sem->id, 1, B_RELATIVE_TIMEOUT, timeout);
85 } 85 }
86 switch (val) { 86 switch (val) {
87 case B_INTERRUPTED: 87 case B_INTERRUPTED:
88 goto tryagain; 88 goto tryagain;
89 case B_NO_ERROR: 89 case B_NO_ERROR:
94 break; 94 break;
95 case B_WOULD_BLOCK: 95 case B_WOULD_BLOCK:
96 retval = SDL_MUTEX_TIMEDOUT; 96 retval = SDL_MUTEX_TIMEDOUT;
97 break; 97 break;
98 default: 98 default:
99 SDL_SetError ("acquire_sem() failed"); 99 SDL_SetError("acquire_sem() failed");
100 retval = -1; 100 retval = -1;
101 break; 101 break;
102 } 102 }
103 103
104 return retval; 104 return retval;
105 } 105 }
106 106
107 int 107 int
108 SDL_SemTryWait (SDL_sem * sem) 108 SDL_SemTryWait(SDL_sem * sem)
109 { 109 {
110 return SDL_SemWaitTimeout (sem, 0); 110 return SDL_SemWaitTimeout(sem, 0);
111 } 111 }
112 112
113 int 113 int
114 SDL_SemWait (SDL_sem * sem) 114 SDL_SemWait(SDL_sem * sem)
115 { 115 {
116 return SDL_SemWaitTimeout (sem, SDL_MUTEX_MAXWAIT); 116 return SDL_SemWaitTimeout(sem, SDL_MUTEX_MAXWAIT);
117 } 117 }
118 118
119 /* Returns the current count of the semaphore */ 119 /* Returns the current count of the semaphore */
120 Uint32 120 Uint32
121 SDL_SemValue (SDL_sem * sem) 121 SDL_SemValue(SDL_sem * sem)
122 { 122 {
123 int32 count; 123 int32 count;
124 Uint32 value; 124 Uint32 value;
125 125
126 value = 0; 126 value = 0;
127 if (sem) { 127 if (sem) {
128 get_sem_count (sem->id, &count); 128 get_sem_count(sem->id, &count);
129 if (count > 0) { 129 if (count > 0) {
130 value = (Uint32) count; 130 value = (Uint32) count;
131 } 131 }
132 } 132 }
133 return value; 133 return value;
134 } 134 }
135 135
136 /* Atomically increases the semaphore's count (not blocking) */ 136 /* Atomically increases the semaphore's count (not blocking) */
137 int 137 int
138 SDL_SemPost (SDL_sem * sem) 138 SDL_SemPost(SDL_sem * sem)
139 { 139 {
140 if (!sem) { 140 if (!sem) {
141 SDL_SetError ("Passed a NULL semaphore"); 141 SDL_SetError("Passed a NULL semaphore");
142 return -1; 142 return -1;
143 } 143 }
144 144
145 if (release_sem (sem->id) != B_NO_ERROR) { 145 if (release_sem(sem->id) != B_NO_ERROR) {
146 SDL_SetError ("release_sem() failed"); 146 SDL_SetError("release_sem() failed");
147 return -1; 147 return -1;
148 } 148 }
149 return 0; 149 return 0;
150 } 150 }
151 151