Changeset 3843
- Timestamp:
- 03/01/06 19:39:17 (3 years ago)
- Files:
-
- libwired/trunk/libwired/thread/wi-timer.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
libwired/trunk/libwired/thread/wi-timer.c
r3834 r3843 124 124 uint32_t i = 0; 125 125 126 pthread_cleanup_push(wi_crash, NULL);127 128 126 pool = wi_pool_init(wi_pool_alloc()); 129 127 130 wi_log_debug(WI_STR(">>> enter _wi_timer_thread()"));131 132 128 while(true) { 133 129 if(!pool) … … 140 136 141 137 if(!timer) { 142 wi_log_debug(WI_STR(">>> got no timers, waiting forever"));143 138 wi_condition_lock_lock_when_condition(_wi_timer_lock, 1, 0.0); 144 wi_log_debug(WI_STR(">>> locked in thread"));145 139 146 140 timer = wi_list_first_data(_wi_timers); 147 141 interval = wi_time_interval(); 148 149 if(timer)150 wi_log_debug(WI_STR(">>> got timer, fire in %.2f"), timer->fire - interval);151 142 152 143 if(timer && timer->fire - interval <= _WI_TIMER_EPSILON) … … 156 147 157 148 if(diff <= _WI_TIMER_EPSILON) { 158 wi_log_debug(WI_STR(">>> got timer, can fire immediately"));159 160 149 fire_timer = timer; 161 150 162 151 locked = false; 163 152 } else { 164 wi_log_debug(WI_STR(">>> got timer, waiting for %.2f"), diff); 165 if(!wi_condition_lock_lock_when_condition(_wi_timer_lock, 1, timer->fire)) { 153 if(!wi_condition_lock_lock_when_condition(_wi_timer_lock, 1, timer->fire)) 166 154 fire_timer = wi_list_first_data(_wi_timers); 167 wi_log_debug(WI_STR(">>> finished waiting, got %@"), fire_timer);168 }169 else170 wi_log_debug(WI_STR(">>> interrupted while waiting, rechecking"));171 wi_log_debug(WI_STR(">>> locked in thread"));172 155 } 173 156 } 174 175 wi_log_debug(WI_STR(">>> firing %@"), fire_timer);176 157 177 158 if(fire_timer) { … … 184 165 } 185 166 186 if(locked) {167 if(locked) 187 168 wi_condition_lock_unlock_with_condition(_wi_timer_lock, 0); 188 wi_log_debug(WI_STR(">>> unlocked in thread"));189 }190 169 191 170 if(++i % 100 == 0) { … … 195 174 } 196 175 197 wi_log_debug(WI_STR(">>> exit _wi_timer_thread()"));198 199 176 wi_release(pool); 200 201 pthread_cleanup_pop(1);202 177 } 203 178 … … 285 260 pthread_once(&_wi_timer_once_control, _wi_timer_create_thread); 286 261 287 if(!timer->incallback) { 288 wi_log_debug(WI_STR("--- locking in schedule")); 262 if(!timer->incallback) 289 263 wi_condition_lock_lock(_wi_timer_lock); 290 }291 264 292 265 _wi_timer_schedule(timer); 293 266 294 if(!timer->incallback) { 295 wi_log_debug(WI_STR("--- unlocking in schedule")); 267 if(!timer->incallback) 296 268 wi_condition_lock_unlock_with_condition(_wi_timer_lock, 1); 297 }298 269 } 299 270 } … … 307 278 _wi_timer_invalidate(timer); 308 279 309 if(!timer->incallback) { 310 wi_log_debug(WI_STR("+++ locking in reschedule")); 280 if(!timer->incallback) 311 281 wi_condition_lock_lock(_wi_timer_lock); 312 }313 282 314 283 _wi_timer_schedule(timer); 315 284 316 if(!timer->incallback) { 317 wi_log_debug(WI_STR("+++ unlocking in reschedule")); 285 if(!timer->incallback) 318 286 wi_condition_lock_unlock_with_condition(_wi_timer_lock, 1); 319 }320 287 } 321 288 … … 332 299 void wi_timer_invalidate(wi_timer_t *timer) { 333 300 if(timer->scheduled) { 334 if(!timer->incallback) { 335 wi_log_debug(WI_STR("*** locking in invalidate")); 301 if(!timer->incallback) 336 302 wi_condition_lock_lock(_wi_timer_lock); 337 }338 303 339 304 _wi_timer_invalidate(timer); 340 305 341 if(!timer->incallback) { 342 wi_log_debug(WI_STR("*** unlocking in invalidate")); 306 if(!timer->incallback) 343 307 wi_condition_lock_unlock_with_condition(_wi_timer_lock, 1); 344 }345 308 } 346 309 }
