comparison src/thread/pth/SDL_syscond.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
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 * 41 SDL_cond *
42 SDL_CreateCond (void) 42 SDL_CreateCond(void)
43 { 43 {
44 SDL_cond *cond; 44 SDL_cond *cond;
45 45
46 cond = (SDL_cond *) SDL_malloc (sizeof (SDL_cond)); 46 cond = (SDL_cond *) SDL_malloc(sizeof(SDL_cond));
47 if (cond) { 47 if (cond) {
48 if (pth_cond_init (&(cond->condpth_p)) < 0) { 48 if (pth_cond_init(&(cond->condpth_p)) < 0) {
49 SDL_SetError ("pthread_cond_init() failed"); 49 SDL_SetError("pthread_cond_init() failed");
50 SDL_free (cond); 50 SDL_free(cond);
51 cond = NULL; 51 cond = NULL;
52 } 52 }
53 } else { 53 } else {
54 SDL_OutOfMemory (); 54 SDL_OutOfMemory();
55 } 55 }
56 return (cond); 56 return (cond);
57 } 57 }
58 58
59 /* Destroy a condition variable */ 59 /* Destroy a condition variable */
60 void 60 void
61 SDL_DestroyCond (SDL_cond * cond) 61 SDL_DestroyCond(SDL_cond * cond)
62 { 62 {
63 if (cond) { 63 if (cond) {
64 SDL_free (cond); 64 SDL_free(cond);
65 } 65 }
66 } 66 }
67 67
68 /* 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 */
69 int 69 int
70 SDL_CondSignal (SDL_cond * cond) 70 SDL_CondSignal(SDL_cond * cond)
71 { 71 {
72 int retval; 72 int retval;
73 73
74 if (!cond) { 74 if (!cond) {
75 SDL_SetError ("Passed a NULL condition variable"); 75 SDL_SetError("Passed a NULL condition variable");
76 return -1; 76 return -1;
77 } 77 }
78 78
79 retval = 0; 79 retval = 0;
80 if (pth_cond_notify (&(cond->condpth_p), FALSE) != 0) { 80 if (pth_cond_notify(&(cond->condpth_p), FALSE) != 0) {
81 SDL_SetError ("pth_cond_notify() failed"); 81 SDL_SetError("pth_cond_notify() failed");
82 retval = -1; 82 retval = -1;
83 } 83 }
84 return retval; 84 return retval;
85 } 85 }
86 86
87 /* Restart all threads that are waiting on the condition variable */ 87 /* Restart all threads that are waiting on the condition variable */
88 int 88 int
89 SDL_CondBroadcast (SDL_cond * cond) 89 SDL_CondBroadcast(SDL_cond * cond)
90 { 90 {
91 int retval; 91 int retval;
92 92
93 if (!cond) { 93 if (!cond) {
94 SDL_SetError ("Passed a NULL condition variable"); 94 SDL_SetError("Passed a NULL condition variable");
95 return -1; 95 return -1;
96 } 96 }
97 97
98 retval = 0; 98 retval = 0;
99 if (pth_cond_notify (&(cond->condpth_p), TRUE) != 0) { 99 if (pth_cond_notify(&(cond->condpth_p), TRUE) != 0) {
100 SDL_SetError ("pth_cond_notify() failed"); 100 SDL_SetError("pth_cond_notify() failed");
101 retval = -1; 101 retval = -1;
102 } 102 }
103 return retval; 103 return retval;
104 } 104 }
105 105
122 condition = true; 122 condition = true;
123 ... 123 ...
124 SDL_UnlockMutex(lock); 124 SDL_UnlockMutex(lock);
125 */ 125 */
126 int 126 int
127 SDL_CondWaitTimeout (SDL_cond * cond, SDL_mutex * mutex, Uint32 ms) 127 SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms)
128 { 128 {
129 int retval; 129 int retval;
130 pth_event_t ev; 130 pth_event_t ev;
131 int sec; 131 int sec;
132 132
133 if (!cond) { 133 if (!cond) {
134 SDL_SetError ("Passed a NULL condition variable"); 134 SDL_SetError("Passed a NULL condition variable");
135 return -1; 135 return -1;
136 } 136 }
137 137
138 retval = 0; 138 retval = 0;
139 139
140 sec = ms / 1000; 140 sec = ms / 1000;
141 ev = pth_event (PTH_EVENT_TIME, 141 ev = pth_event(PTH_EVENT_TIME,
142 pth_timeout (sec, (ms - sec * 1000) * 1000)); 142 pth_timeout(sec, (ms - sec * 1000) * 1000));
143 143
144 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) {
145 SDL_SetError ("pth_cond_await() failed"); 145 SDL_SetError("pth_cond_await() failed");
146 retval = -1; 146 retval = -1;
147 } 147 }
148 148
149 pth_event_free (ev, PTH_FREE_ALL); 149 pth_event_free(ev, PTH_FREE_ALL);
150 150
151 return retval; 151 return retval;
152 } 152 }
153 153
154 /* Wait on the condition variable forever */ 154 /* Wait on the condition variable forever */
155 int 155 int
156 SDL_CondWait (SDL_cond * cond, SDL_mutex * mutex) 156 SDL_CondWait(SDL_cond * cond, SDL_mutex * mutex)
157 { 157 {
158 int retval; 158 int retval;
159 159
160 if (!cond) { 160 if (!cond) {
161 SDL_SetError ("Passed a NULL condition variable"); 161 SDL_SetError("Passed a NULL condition variable");
162 return -1; 162 return -1;
163 } 163 }
164 164
165 retval = 0; 165 retval = 0;
166 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) {
167 SDL_SetError ("pth_cond_await() failed"); 167 SDL_SetError("pth_cond_await() failed");
168 retval = -1; 168 retval = -1;
169 } 169 }
170 return retval; 170 return retval;
171 } 171 }
172 172