mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-01-10 07:49:54 +00:00
REORG: clock: move the clock_id initialization to clock.c
This was previously open-coded in run_thread_poll_loop(). Now that we have clock.c dedicated to such stuff, let's move the code there so that we don't need to keep such ifdefs nor to depend on the clock_id.
This commit is contained in:
parent
2c6a998727
commit
44c58da52f
@ -35,6 +35,7 @@ extern THREAD_LOCAL struct timeval date; /* the real current date (wall
|
||||
uint64_t now_cpu_time_thread(const struct thread_info *thr);
|
||||
uint64_t now_mono_time(void);
|
||||
uint64_t now_cpu_time(void);
|
||||
void clock_set_local_source(void);
|
||||
void clock_update_date(int max_wait, int interrupted);
|
||||
void clock_init_process_date(void);
|
||||
void clock_init_thread_date(void);
|
||||
|
16
src/clock.c
16
src/clock.c
@ -13,6 +13,10 @@
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
|
||||
#ifdef USE_THREAD
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
|
||||
#include <haproxy/api.h>
|
||||
#include <haproxy/activity.h>
|
||||
#include <haproxy/clock.h>
|
||||
@ -73,6 +77,18 @@ uint64_t now_cpu_time_thread(const struct thread_info *thr)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* set the clock source for the local thread */
|
||||
void clock_set_local_source(void)
|
||||
{
|
||||
#if defined(_POSIX_TIMERS) && (_POSIX_TIMERS > 0) && defined(_POSIX_THREAD_CPUTIME)
|
||||
#ifdef USE_THREAD
|
||||
pthread_getcpuclockid(pthread_self(), &ti->clock_id);
|
||||
#else
|
||||
ti->clock_id = CLOCK_THREAD_CPUTIME_ID;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
/* clock_update_date: sets <date> to system time, and sets <now> to something as
|
||||
* close as possible to real time, following a monotonic function. The main
|
||||
* principle consists in detecting backwards and forwards time jumps and adjust
|
||||
|
@ -2700,14 +2700,8 @@ static void *run_thread_poll_loop(void *data)
|
||||
ha_set_tid((unsigned long)data);
|
||||
set_thread_cpu_affinity();
|
||||
sched = &task_per_thread[tid];
|
||||
clock_set_local_source();
|
||||
|
||||
#if (_POSIX_TIMERS > 0) && defined(_POSIX_THREAD_CPUTIME)
|
||||
#ifdef USE_THREAD
|
||||
pthread_getcpuclockid(pthread_self(), &ti->clock_id);
|
||||
#else
|
||||
ti->clock_id = CLOCK_THREAD_CPUTIME_ID;
|
||||
#endif
|
||||
#endif
|
||||
/* Now, initialize one thread init at a time. This is better since
|
||||
* some init code is a bit tricky and may release global resources
|
||||
* after reallocating them locally. This will also ensure there is
|
||||
|
Loading…
Reference in New Issue
Block a user