comparison src/thread/riscos/SDL_syscond.c @ 1895:c121d94672cb

SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 10 Jul 2006 21:04:37 +0000
parents d910939febfa
children 99210400e8b9
comparison
equal deleted inserted replaced
1894:c69cee13dd76 1895:c121d94672cb
33 #include "SDL_thread.h" 33 #include "SDL_thread.h"
34 #include "SDL_sysmutex_c.h" 34 #include "SDL_sysmutex_c.h"
35 35
36 struct SDL_cond 36 struct SDL_cond
37 { 37 {
38 pthread_cond_t cond; 38 pthread_cond_t cond;
39 }; 39 };
40 40
41 /* Create a condition variable */ 41 /* Create a condition variable */
42 SDL_cond * SDL_CreateCond(void) 42 SDL_cond *
43 SDL_CreateCond(void)
43 { 44 {
44 SDL_cond *cond; 45 SDL_cond *cond;
45 46
46 cond = (SDL_cond *) SDL_malloc(sizeof(SDL_cond)); 47 cond = (SDL_cond *) SDL_malloc(sizeof(SDL_cond));
47 if ( cond ) { 48 if (cond) {
48 if ( pthread_cond_init(&cond->cond, NULL) < 0 ) { 49 if (pthread_cond_init(&cond->cond, NULL) < 0) {
49 SDL_SetError("pthread_cond_init() failed"); 50 SDL_SetError("pthread_cond_init() failed");
50 SDL_free(cond); 51 SDL_free(cond);
51 cond = NULL; 52 cond = NULL;
52 } 53 }
53 } 54 }
54 return(cond); 55 return (cond);
55 } 56 }
56 57
57 /* Destroy a condition variable */ 58 /* Destroy a condition variable */
58 void SDL_DestroyCond(SDL_cond *cond) 59 void
60 SDL_DestroyCond(SDL_cond * cond)
59 { 61 {
60 if ( cond ) { 62 if (cond) {
61 pthread_cond_destroy(&cond->cond); 63 pthread_cond_destroy(&cond->cond);
62 SDL_free(cond); 64 SDL_free(cond);
63 } 65 }
64 } 66 }
65 67
66 /* Restart one of the threads that are waiting on the condition variable */ 68 /* Restart one of the threads that are waiting on the condition variable */
67 int SDL_CondSignal(SDL_cond *cond) 69 int
70 SDL_CondSignal(SDL_cond * cond)
68 { 71 {
69 int retval; 72 int retval;
70 73
71 if ( ! cond ) { 74 if (!cond) {
72 SDL_SetError("Passed a NULL condition variable"); 75 SDL_SetError("Passed a NULL condition variable");
73 return -1; 76 return -1;
74 } 77 }
75 78
76 retval = 0; 79 retval = 0;
77 if ( pthread_cond_signal(&cond->cond) != 0 ) { 80 if (pthread_cond_signal(&cond->cond) != 0) {
78 SDL_SetError("pthread_cond_signal() failed"); 81 SDL_SetError("pthread_cond_signal() failed");
79 retval = -1; 82 retval = -1;
80 } 83 }
81 return retval; 84 return retval;
82 } 85 }
83 86
84 /* Restart all threads that are waiting on the condition variable */ 87 /* Restart all threads that are waiting on the condition variable */
85 int SDL_CondBroadcast(SDL_cond *cond) 88 int
89 SDL_CondBroadcast(SDL_cond * cond)
86 { 90 {
87 int retval; 91 int retval;
88 92
89 if ( ! cond ) { 93 if (!cond) {
90 SDL_SetError("Passed a NULL condition variable"); 94 SDL_SetError("Passed a NULL condition variable");
91 return -1; 95 return -1;
92 } 96 }
93 97
94 retval = 0; 98 retval = 0;
95 if ( pthread_cond_broadcast(&cond->cond) != 0 ) { 99 if (pthread_cond_broadcast(&cond->cond) != 0) {
96 SDL_SetError("pthread_cond_broadcast() failed"); 100 SDL_SetError("pthread_cond_broadcast() failed");
97 retval = -1; 101 retval = -1;
98 } 102 }
99 return retval; 103 return retval;
100 } 104 }
101 105
102 int SDL_CondWaitTimeout(SDL_cond *cond, SDL_mutex *mutex, Uint32 ms) 106 int
107 SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms)
103 { 108 {
104 int retval; 109 int retval;
105 struct timeval delta; 110 struct timeval delta;
106 struct timespec abstime; 111 struct timespec abstime;
107 112
108 if ( ! cond ) { 113 if (!cond) {
109 SDL_SetError("Passed a NULL condition variable"); 114 SDL_SetError("Passed a NULL condition variable");
110 return -1; 115 return -1;
111 } 116 }
112 117
113 gettimeofday(&delta, NULL); 118 gettimeofday(&delta, NULL);
114 119
115 abstime.tv_sec = delta.tv_sec + (ms/1000); 120 abstime.tv_sec = delta.tv_sec + (ms / 1000);
116 abstime.tv_nsec = (delta.tv_usec + (ms%1000) * 1000) * 1000; 121 abstime.tv_nsec = (delta.tv_usec + (ms % 1000) * 1000) * 1000;
117 if ( abstime.tv_nsec > 1000000000 ) { 122 if (abstime.tv_nsec > 1000000000) {
118 abstime.tv_sec += 1; 123 abstime.tv_sec += 1;
119 abstime.tv_nsec -= 1000000000; 124 abstime.tv_nsec -= 1000000000;
120 } 125 }
121 126
122 tryagain: 127 tryagain:
123 retval = pthread_cond_timedwait(&cond->cond, &mutex->id, &abstime); 128 retval = pthread_cond_timedwait(&cond->cond, &mutex->id, &abstime);
124 switch (retval) { 129 switch (retval) {
125 case EINTR: 130 case EINTR:
126 goto tryagain; 131 goto tryagain;
127 break; 132 break;
128 case ETIMEDOUT: 133 case ETIMEDOUT:
129 retval = SDL_MUTEX_TIMEDOUT; 134 retval = SDL_MUTEX_TIMEDOUT;
130 break; 135 break;
131 case 0: 136 case 0:
132 break; 137 break;
133 default: 138 default:
134 SDL_SetError("pthread_cond_timedwait() failed"); 139 SDL_SetError("pthread_cond_timedwait() failed");
135 retval = -1; 140 retval = -1;
136 break; 141 break;
137 } 142 }
138 return retval; 143 return retval;
139 } 144 }
140 145
141 /* Wait on the condition variable, unlocking the provided mutex. 146 /* Wait on the condition variable, unlocking the provided mutex.
142 The mutex must be locked before entering this function! 147 The mutex must be locked before entering this function!
143 */ 148 */
144 int SDL_CondWait(SDL_cond *cond, SDL_mutex *mutex) 149 int
150 SDL_CondWait(SDL_cond * cond, SDL_mutex * mutex)
145 { 151 {
146 int retval; 152 int retval;
147 153
148 if ( ! cond ) { 154 if (!cond) {
149 SDL_SetError("Passed a NULL condition variable"); 155 SDL_SetError("Passed a NULL condition variable");
150 return -1; 156 return -1;
151 } 157 }
152 158
153 retval = 0; 159 retval = 0;
154 if ( pthread_cond_wait(&cond->cond, &mutex->id) != 0 ) { 160 if (pthread_cond_wait(&cond->cond, &mutex->id) != 0) {
155 SDL_SetError("pthread_cond_wait() failed"); 161 SDL_SetError("pthread_cond_wait() failed");
156 retval = -1; 162 retval = -1;
157 } 163 }
158 return retval; 164 return retval;
159 } 165 }
160 #endif 166 #endif
167 /* vi: set ts=4 sw=4 expandtab: */