@@ -347,15 +347,22 @@ static inline int32_t timerlist_add_duration(struct timerlist *timerlist,
347
347
return (0 );
348
348
}
349
349
350
- static inline void timerlist_del (struct timerlist * timerlist ,
350
+ static inline int32_t timerlist_del (struct timerlist * timerlist ,
351
351
timer_handle _timer_handle )
352
352
{
353
353
struct timerlist_timer * timer = (struct timerlist_timer * )_timer_handle ;
354
354
355
+ if (pthread_mutex_lock (& timerlist -> list_mutex )) {
356
+ return - errno ;
357
+ }
358
+
355
359
memset (timer -> handle_addr , 0 , sizeof (struct timerlist_timer * ));
356
360
357
361
timerlist_heap_delete (timerlist , timer );
358
362
free (timer );
363
+
364
+ pthread_mutex_unlock (& timerlist -> list_mutex );
365
+ return 0 ;
359
366
}
360
367
361
368
static inline uint64_t timerlist_expire_time (struct timerlist
@@ -395,15 +402,29 @@ static inline uint64_t timerlist_msec_duration_to_expire(struct timerlist *timer
395
402
volatile uint64_t current_time ;
396
403
volatile uint64_t msec_duration_to_expire ;
397
404
405
+ /*
406
+ * There is really no reasonable value to return when mutex lock fails
407
+ */
408
+ if (pthread_mutex_lock (& timerlist -> list_mutex )) {
409
+ return (-1 );
410
+ }
411
+
398
412
/*
399
413
* empty list, no expire
400
414
*/
401
415
if (timerlist -> size == 0 ) {
416
+ pthread_mutex_unlock (& timerlist -> list_mutex );
417
+
402
418
return (-1 );
403
419
}
404
420
405
421
timer_from_list = timerlist_heap_entry_get (timerlist , 0 );
406
422
423
+ /*
424
+ * Mutex is no longer needed
425
+ */
426
+ pthread_mutex_unlock (& timerlist -> list_mutex );
427
+
407
428
if (timer_from_list -> is_absolute_timer ) {
408
429
current_time = qb_util_nano_from_epoch_get ();
409
430
} else {
@@ -426,7 +447,7 @@ static inline uint64_t timerlist_msec_duration_to_expire(struct timerlist *timer
426
447
/*
427
448
* Expires any timers that should be expired
428
449
*/
429
- static inline void timerlist_expire (struct timerlist * timerlist )
450
+ static inline int32_t timerlist_expire (struct timerlist * timerlist )
430
451
{
431
452
struct timerlist_timer * timer ;
432
453
uint64_t current_time_from_epoch ;
@@ -436,6 +457,10 @@ static inline void timerlist_expire(struct timerlist *timerlist)
436
457
current_monotonic_time = qb_util_nano_current_get ();
437
458
current_time_from_epoch = qb_util_nano_from_epoch_get ();
438
459
460
+ if (pthread_mutex_lock (& timerlist -> list_mutex )) {
461
+ return - errno ;
462
+ }
463
+
439
464
while (timerlist -> size > 0 ) {
440
465
timer = timerlist_heap_entry_get (timerlist , 0 );
441
466
@@ -455,5 +480,9 @@ static inline void timerlist_expire(struct timerlist *timerlist)
455
480
break ; /* for timer iteration */
456
481
}
457
482
}
483
+
484
+ pthread_mutex_unlock (& timerlist -> list_mutex );
485
+
486
+ return (0 );
458
487
}
459
488
#endif /* QB_TLIST_H_DEFINED */
0 commit comments