unsigned pthread_alarm(unsigned sec) { int ret = 0; pthread_t self = pthread_self(); if (sec == 0) { /* cancel pending alarm */ self->alarm_timeout = 0; if (self->alarm_timer) DosStopTimer(self->alarm_timer); if (self->alarm_event) DosPostEventSem(self->alarm_event); } else if (sec > 0) { if (self->alarm_timer && self->alarm_thread) { DosStopTimer(self->alarm_timer); } else { DosCreateEventSem(NULL,&self->alarm_event,DC_SEM_SHARED,FALSE); pthread_create(&self->alarm_thread,NULL,_alarm_thread,(void *)self); } DosAsyncTimer(sec * 1000L,(HSEM)self->alarm_event,&self->alarm_timer); self->alarm_timeout = sec; } else { ret = EINVAL; errno = EINVAL; } return (ret); }
void vlc_timer_destroy (vlc_timer_t timer) { if (timer->htimer != NULLHANDLE) DosStopTimer (timer->htimer); timer->quit = true; DosPostEventSem (timer->hev); DosWaitThread (&timer->tid, DCWW_WAIT); DosCloseEventSem (timer->hev); free (timer); }
void vlc_timer_schedule (vlc_timer_t timer, bool absolute, mtime_t value, mtime_t interval) { if (timer->htimer != NULLHANDLE) { DosStopTimer (timer->htimer); timer->htimer = NULLHANDLE; timer->interval = 0; } if (value == 0) return; /* Disarm */ if (absolute) value -= mdate (); value = (value + 999) / 1000; interval = (interval + 999) / 1000; timer->interval = interval; if (DosAsyncTimer (value, (HSEM)timer->hev, &timer->htimer)) abort (); }
void DosAsyncTimerHandler_9(int signo, siginfo_t *info, void *context) { SAVEENV; /* check that the timer actually expired */ if (info->si_code != SI_TIMER) { return; } /* check that the timerslot is valid */ if (DosLinuxStruct.timerslot[9] == NULL) { return; } DosPostEventSem(DosLinuxStruct.timerslot[9]->hSem); if (DosLinuxStruct.timerslot[9]->oneshot) { DosStopTimer((HTIMER)DosLinuxStruct.timerslot[9]); } RESTOREENV; return; }
int main(VOID) { HEV hevEvent1 = 0; /* Event semaphore handle */ HTIMER htimerEvent1 = 0; /* Timer handle */ APIRET rc = NO_ERROR; /* Return code */ ULONG ulPostCount = 0; /* Semaphore post count */ ULONG i = 0; /* A loop index */ rc = DosCreateEventSem(NULL, /* Unnamed semaphore */ &hevEvent1, /* Handle of semaphore returned */ DC_SEM_SHARED, /* Indicate a shared semaphore */ FALSE); /* Put in RESET state */ if (rc != NO_ERROR) { printf("DosCreateEventSem error: return code = %u\n", rc); return 1; } rc = DosStartTimer(2000L, /* 2 second interval */ (HSEM) hevEvent1, /* Semaphore to post */ &htimerEvent1); /* Timer handler (returned) */ if (rc != NO_ERROR) { printf("DosStartTimer error: return code = %u\n", rc); return 1; } for (i = 1 ; i < 6 ; i++) { rc = DosWaitEventSem(hevEvent1,15000L); /* Wait 15 seconds for timer */ if (rc != NO_ERROR) { printf("DosWaitEventSem error: return code = %u\n", rc); return 1; } rc = DosResetEventSem(hevEvent1, /* Reset the semaphore */ &ulPostCount); /* And get count (should be 1) */ if (rc != NO_ERROR) { printf("DosWaitEventSem error: return code = %u\n", rc); return 1; } printf("Iteration %u: ulPostCount = %u\n", i, ulPostCount); } /* for loop */ rc = DosStopTimer(htimerEvent1); /* Stop the timer */ if (rc != NO_ERROR) { printf("DosCloseEventSem error: return code = %u\n", rc); return 1; } rc = DosCloseEventSem(hevEvent1); /* Get rid of semaphore */ if (rc != NO_ERROR) { printf("DosCloseEventSem error: return code = %u\n", rc); return 1; } return NO_ERROR; }