comparison src/thread/pth/SDL_syscond.c @ 1662:782fd950bd46 SDL-1.3

Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API. WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid. The code is now run through a consistent indent format: indent -i4 -nut -nsc -br -ce The headers are being converted to automatically generate doxygen documentation.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 28 May 2006 13:04:16 +0000
parents d910939febfa
children 4da1ee79c9af
comparison
equal deleted inserted replaced
1661:281d3f4870e5 1662:782fd950bd46
32 #include "SDL_thread.h" 32 #include "SDL_thread.h"
33 #include "SDL_sysmutex_c.h" 33 #include "SDL_sysmutex_c.h"
34 34
35 struct SDL_cond 35 struct SDL_cond
36 { 36 {
37 pth_cond_t condpth_p; 37 pth_cond_t condpth_p;
38 }; 38 };
39 39
40 /* Create a condition variable */ 40 /* Create a condition variable */
41 SDL_cond * SDL_CreateCond(void) 41 SDL_cond *
42 SDL_CreateCond (void)
42 { 43 {
43 SDL_cond *cond; 44 SDL_cond *cond;
44 45
45 cond = (SDL_cond *) SDL_malloc(sizeof(SDL_cond)); 46 cond = (SDL_cond *) SDL_malloc (sizeof (SDL_cond));
46 if ( cond ) { 47 if (cond) {
47 if ( pth_cond_init(&(cond->condpth_p)) < 0 ) { 48 if (pth_cond_init (&(cond->condpth_p)) < 0) {
48 SDL_SetError("pthread_cond_init() failed"); 49 SDL_SetError ("pthread_cond_init() failed");
49 SDL_free(cond); 50 SDL_free (cond);
50 cond = NULL; 51 cond = NULL;
51 } 52 }
52 } else { 53 } else {
53 SDL_OutOfMemory(); 54 SDL_OutOfMemory ();
54 } 55 }
55 return(cond); 56 return (cond);
56 } 57 }
57 58
58 /* Destroy a condition variable */ 59 /* Destroy a condition variable */
59 void SDL_DestroyCond(SDL_cond *cond) 60 void
61 SDL_DestroyCond (SDL_cond * cond)
60 { 62 {
61 if ( cond ) { 63 if (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 ( pth_cond_notify(&(cond->condpth_p), FALSE) != 0 ) { 80 if (pth_cond_notify (&(cond->condpth_p), FALSE) != 0) {
78 SDL_SetError("pth_cond_notify() failed"); 81 SDL_SetError ("pth_cond_notify() 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 ( pth_cond_notify(&(cond->condpth_p), TRUE) != 0 ) { 99 if (pth_cond_notify (&(cond->condpth_p), TRUE) != 0) {
96 SDL_SetError("pth_cond_notify() failed"); 100 SDL_SetError ("pth_cond_notify() failed");
97 retval = -1; 101 retval = -1;
98 } 102 }
99 return retval; 103 return retval;
100 } 104 }
101 105
102 /* Wait on the condition variable for at most 'ms' milliseconds. 106 /* Wait on the condition variable for at most 'ms' milliseconds.
103 The mutex must be locked before entering this function! 107 The mutex must be locked before entering this function!
104 The mutex is unlocked during the wait, and locked again after the wait. 108 The mutex is unlocked during the wait, and locked again after the wait.
117 ... 121 ...
118 condition = true; 122 condition = true;
119 ... 123 ...
120 SDL_UnlockMutex(lock); 124 SDL_UnlockMutex(lock);
121 */ 125 */
122 int SDL_CondWaitTimeout(SDL_cond *cond, SDL_mutex *mutex, Uint32 ms) 126 int
127 SDL_CondWaitTimeout (SDL_cond * cond, SDL_mutex * mutex, Uint32 ms)
123 { 128 {
124 int retval; 129 int retval;
125 pth_event_t ev; 130 pth_event_t ev;
126 int sec; 131 int sec;
127 132
128 if ( ! cond ) { 133 if (!cond) {
129 SDL_SetError("Passed a NULL condition variable"); 134 SDL_SetError ("Passed a NULL condition variable");
130 return -1; 135 return -1;
131 } 136 }
132 137
133 retval = 0; 138 retval = 0;
134 139
135 sec = ms/1000; 140 sec = ms / 1000;
136 ev = pth_event(PTH_EVENT_TIME, pth_timeout(sec,(ms-sec*1000)*1000)); 141 ev = pth_event (PTH_EVENT_TIME,
142 pth_timeout (sec, (ms - sec * 1000) * 1000));
137 143
138 if ( pth_cond_await(&(cond->condpth_p), &(mutex->mutexpth_p), ev) != 0 ) { 144 if (pth_cond_await (&(cond->condpth_p), &(mutex->mutexpth_p), ev) != 0) {
139 SDL_SetError("pth_cond_await() failed"); 145 SDL_SetError ("pth_cond_await() failed");
140 retval = -1; 146 retval = -1;
141 } 147 }
142 148
143 pth_event_free(ev, PTH_FREE_ALL); 149 pth_event_free (ev, PTH_FREE_ALL);
144 150
145 return retval; 151 return retval;
146 } 152 }
147 153
148 /* Wait on the condition variable forever */ 154 /* Wait on the condition variable forever */
149 int SDL_CondWait(SDL_cond *cond, SDL_mutex *mutex) 155 int
156 SDL_CondWait (SDL_cond * cond, SDL_mutex * mutex)
150 { 157 {
151 int retval; 158 int retval;
152 159
153 if ( ! cond ) { 160 if (!cond) {
154 SDL_SetError("Passed a NULL condition variable"); 161 SDL_SetError ("Passed a NULL condition variable");
155 return -1; 162 return -1;
156 } 163 }
157 164
158 retval = 0; 165 retval = 0;
159 if ( pth_cond_await(&(cond->condpth_p), &(mutex->mutexpth_p), NULL) != 0 ) { 166 if (pth_cond_await (&(cond->condpth_p), &(mutex->mutexpth_p), NULL) != 0) {
160 SDL_SetError("pth_cond_await() failed"); 167 SDL_SetError ("pth_cond_await() failed");
161 retval = -1; 168 retval = -1;
162 } 169 }
163 return retval; 170 return retval;
164 } 171 }
172
173 /* vi: set ts=4 sw=4 expandtab: */