Improve error handling

This commit is contained in:
Christopher Rienzo 2011-12-06 22:36:05 +00:00
parent 4e5560a980
commit 0ed06ad710

View File

@ -82,15 +82,16 @@ static switch_status_t posix_timer_start_interval(interval_timer_t *it, int inte
return SWITCH_STATUS_GENERR;
}
it->users++;
if (it->users > 1) {
return SWITCH_STATUS_SUCCESS;
}
if (it->users <= 0) {
/* reset */
it->tick = 0;
it->users = 0;
/* reuse, if possible */
if (it->mutex == NULL) {
switch_mutex_init(&it->mutex, SWITCH_MUTEX_NESTED, globals.pool);
switch_thread_cond_create(&it->cond, globals.pool);
}
/* create the POSIX timer. Will notify the posix_timer_notify thread on ticks. */
memset(&sigev, 0, sizeof(sigev));
@ -110,7 +111,9 @@ static switch_status_t posix_timer_start_interval(interval_timer_t *it, int inte
if (timer_settime(it->timer, 0, &val, NULL) == -1) {
return SWITCH_STATUS_GENERR;
}
}
it->users++;
return SWITCH_STATUS_SUCCESS;
}
@ -119,12 +122,13 @@ static switch_status_t posix_timer_start_interval(interval_timer_t *it, int inte
*/
static switch_status_t posix_timer_stop_interval(interval_timer_t *it)
{
if (it->users > 0) {
it->users--;
if (it->users > 0)
return SWITCH_STATUS_SUCCESS;
if (it->users == 0) {
timer_delete(it->timer);
memset(&it->timer, 0, sizeof(it->timer));
}
}
return SWITCH_STATUS_SUCCESS;
}