Beispiel #1
0
void *clock_alarm_thread(void *unused)
{
  int delay = 500*1000*1000; //1,5s in ns - cause overflow when actually using 1,5s
  /* time for next update */
  struct timespec ts;

  while (1) {
    sem_wait(&Clock.start_alarm);

    while (clock_get_alarm_status() == 1) {
      /* initialise time for next update */
      clock_gettime(CLOCK_MONOTONIC, &ts);

      display_alarm_text();

      /* compute time for next update */
      ts.tv_nsec += delay;
      ts.tv_sec++; // cause overflow when actually using 1,5s
      if(ts.tv_nsec >= 1000*1000*1000){
        ts.tv_nsec -= 1000*1000*1000;
        ts.tv_sec++;
      }
      /* wait until time for next update */
      clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &ts, NULL);
    }
  }
}
Beispiel #2
0
/* alarm_task: raises the alarm */
void alarm_task(void)
{
    /* local copy of Clock.alarm_enabled */
    int alarm_enabled = 1;

    while(1)
    {
        /* wait for alarm time */    
        si_sem_wait(&Clock.start_alarm);    

        /* update local copy of Clock.alarm_enabled */
        si_sem_wait(&Clock.mutex);
        alarm_enabled = Clock.alarm_enabled;
        si_sem_signal(&Clock.mutex);

        while(alarm_enabled)
        {
            /* trigger the alarm */
            display_alarm_text();

            /* wait one second */ 
            si_wait_n_ms(10000);

            /* update local copy of Clock.alarm_enabled */
            si_sem_wait(&Clock.mutex);
            alarm_enabled = Clock.alarm_enabled;
            si_sem_signal(&Clock.mutex);
        }

    }
}
Beispiel #3
0
/* alarm_task: alarm task */ 
void alarm_task(void) 
{
    /* infinite loop */ 
    while (1)
    {	
	alarm_wait();

    display_alarm_text();
	increment_alarm();
    /* wait one second */ 
	si_wait_n_ms(1000);
    }
}
Beispiel #4
0
/*alarm_task: handles the alarm*/
void *alarm_thread(void *unused)
{
    /* local copies of the current time */ 
    int hours, minutes, seconds; 
    
    while(1)
    {
        sem_wait(&Clock.start_alarm);
        display_alarm_text();
        usleep(1500000);
        pthread_mutex_lock(&Clock.mutex);
        int alarm_enabled = Clock.alarm_enabled;
        pthread_mutex_unlock(&Clock.mutex);
        if(alarm_enabled)
        {
            sem_post(&Clock.start_alarm);
        }
    }
}