Skip to content
Snippets Groups Projects
Commit 7817885d authored by Moe Jette's avatar Moe Jette
Browse files

replace gang scheduling polling logic with pthread_cond_timedwait()

parent b8199f90
No related branches found
No related tags found
No related merge requests found
...@@ -55,6 +55,8 @@ ...@@ -55,6 +55,8 @@
/* global timeslicer thread variables */ /* global timeslicer thread variables */
static bool thread_running = false; static bool thread_running = false;
static bool thread_shutdown = false; static bool thread_shutdown = false;
static pthread_mutex_t term_lock = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t term_cond = PTHREAD_COND_INITIALIZER;
static pthread_mutex_t thread_flag_mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t thread_flag_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_t timeslicer_thread_id = (pthread_t) 0; static pthread_t timeslicer_thread_id = (pthread_t) 0;
static List preempt_job_list = (List) NULL; static List preempt_job_list = (List) NULL;
...@@ -1193,7 +1195,10 @@ extern int gs_fini(void) ...@@ -1193,7 +1195,10 @@ extern int gs_fini(void)
debug3("gang: entering gs_fini"); debug3("gang: entering gs_fini");
pthread_mutex_lock(&thread_flag_mutex); pthread_mutex_lock(&thread_flag_mutex);
if (thread_running) { if (thread_running) {
pthread_mutex_lock(&term_lock);
thread_shutdown = true; thread_shutdown = true;
pthread_cond_signal(&term_cond);
pthread_mutex_unlock(&term_lock);
usleep(120000); usleep(120000);
if (timeslicer_thread_id) if (timeslicer_thread_id)
error("gang: timeslicer pthread still running"); error("gang: timeslicer pthread still running");
...@@ -1535,10 +1540,13 @@ static void _cycle_job_list(struct gs_part *p_ptr) ...@@ -1535,10 +1540,13 @@ static void _cycle_job_list(struct gs_part *p_ptr)
static void _slice_sleep(void) static void _slice_sleep(void)
{ {
int i, cycles = timeslicer_seconds * 10; struct timespec ts = {0, 0};
for (i=0; ((i<cycles) && !thread_shutdown); i++) ts.tv_sec = time(NULL) + timeslicer_seconds;
usleep(100000); pthread_mutex_lock(&term_lock);
if (!thread_shutdown)
pthread_cond_timedwait(&term_cond, &term_lock, &ts);
pthread_mutex_unlock(&term_lock);
} }
/* The timeslicer thread */ /* The timeslicer thread */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment