Commit 4fee8034 authored by Jeroen Vreeken's avatar Jeroen Vreeken
Browse files

Changes needed for FreeBSD clock usage in sample

parent 8450f2f0
...@@ -136,6 +136,12 @@ static void *sample_thread(void *arg) ...@@ -136,6 +136,12 @@ static void *sample_thread(void *arg)
struct timespec t_io; struct timespec t_io;
struct timespec t_end; struct timespec t_end;
param.sched_priority = 99; param.sched_priority = 99;
clockid_t clock;
#ifdef __FreeBSD__
pthread_condattr_t attr;
pthread_mutex_t lock;
pthread_cond_t cv;
#endif
log_send(LOG_T_DEBUG, "Starting sample thread"); log_send(LOG_T_DEBUG, "Starting sample thread");
controller_sample_thread_running = true; controller_sample_thread_running = true;
...@@ -150,7 +156,21 @@ static void *sample_thread(void *arg) ...@@ -150,7 +156,21 @@ static void *sample_thread(void *arg)
strerror(errno)); strerror(errno));
} }
clock_gettime(0, &t); #ifndef __FreeBSD__
clock = 0;
#else
clock = CLOCK_MONOTONIC_PRECISE;
pthread_condattr_init(&attr);
pthread_condattr_setclock(&attr, clock);
pthread_cond_init(&cv, &attr);
pthread_condattr_destroy(&attr);
pthread_mutex_init(&lock, NULL);
pthread_mutex_lock(&lock);
#endif
clock_gettime(clock, &t);
t.tv_nsec = 0; t.tv_nsec = 0;
t.tv_sec++; t.tv_sec++;
...@@ -168,19 +188,23 @@ static void *sample_thread(void *arg) ...@@ -168,19 +188,23 @@ static void *sample_thread(void *arg)
/* Wait for the right moment... /* Wait for the right moment...
(Internal timer or external interrupt) */ (Internal timer or external interrupt) */
#ifndef __FreeBSD__
clock_nanosleep(0, TIMER_ABSTIME, &t, NULL); clock_nanosleep(0, TIMER_ABSTIME, &t, NULL);
#else
pthread_cond_timedwait(&cv, &lock, &t);
#endif
clock_gettime(0, &t_start); clock_gettime(clock, &t_start);
/* Do sample stuff */ /* Do sample stuff */
controller_block_calculate(); controller_block_calculate();
clock_gettime(0, &t_io); clock_gettime(clock, &t_io);
controller_block_trace(); controller_block_trace();
controller_block_param_handle(); controller_block_param_handle();
clock_gettime(0, &t_end); clock_gettime(clock, &t_end);
sample_timing_add(&st_start, &t, &t_start); sample_timing_add(&st_start, &t, &t_start);
sample_timing_add(&st_io, &t_start, &t_io); sample_timing_add(&st_io, &t_start, &t_io);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment