aboutsummaryrefslogtreecommitdiff
path: root/src/thread-pool.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/thread-pool.c')
-rw-r--r--src/thread-pool.c143
1 files changed, 0 insertions, 143 deletions
diff --git a/src/thread-pool.c b/src/thread-pool.c
index c91c7002..133cbfcf 100644
--- a/src/thread-pool.c
+++ b/src/thread-pool.c
@@ -114,149 +114,6 @@ signed int get_status_label()
}
-/* ---------------------------------- Range --------------------------------- */
-
-enum {
- TASK_READY,
- TASK_RUNNING,
- TASK_FINISHED,
-};
-
-
-struct task_queue_range
-{
- pthread_mutex_t lock;
-
- int n_tasks;
- int *status;
- int n_done;
-
- void (*work)(int, void *);
- void *work_args;
-
- const char *text;
-};
-
-
-static void *range_worker(void *pargsv)
-{
- struct worker_args *w = pargsv;
- struct task_queue_range *q = w->tqr;
- int *cookie;
-
- set_affinity(w->id, w->cpu_num, w->cpu_groupsize, w->cpu_offset);
-
- cookie = malloc(sizeof(int));
- *cookie = w->id;
- pthread_setspecific(status_label_key, cookie);
-
- free(w);
-
- do {
-
- int i;
- int found = 0;
- int mytask = -1;
-
- /* Get a task */
- pthread_mutex_lock(&q->lock);
- for ( i=0; i<q->n_tasks; i++ ) {
- if ( q->status[i] == TASK_READY ) {
- mytask = i;
- found = 1;
- q->status[i] = TASK_RUNNING;
- break;
- }
- }
- pthread_mutex_unlock(&q->lock);
-
- /* No more tasks? */
- if ( !found ) break;
-
- q->work(mytask, q->work_args);
-
- /* Mark this task as done, update totals etc */
- pthread_mutex_lock(&q->lock);
- q->status[mytask] = TASK_FINISHED;
- q->n_done++;
- if ( q->text != NULL ) {
- progress_bar(q->n_done, q->n_tasks, q->text);
- }
- pthread_mutex_unlock(&q->lock);
-
- } while ( 1 );
-
- free(cookie);
-
- return NULL;
-}
-
-
-void run_thread_range(int n_tasks, int n_threads, const char *text,
- void (*work)(int, void *), void *work_args,
- int cpu_num, int cpu_groupsize, int cpu_offset)
-{
- pthread_t *workers;
- int i;
- struct task_queue_range q;
-
- /* The nation of CrystFEL prides itself on having 0% unemployment. */
- if ( n_threads > n_tasks ) n_threads = n_tasks;
-
- pthread_key_create(&status_label_key, NULL);
-
- workers = malloc(n_threads * sizeof(pthread_t));
-
- q.status = malloc(n_tasks * sizeof(int));
- pthread_mutex_init(&q.lock, NULL);
- q.n_tasks = n_tasks;
- q.work = work;
- q.work_args = work_args;
- q.n_done = 0;
- q.text = text;
-
- for ( i=0; i<n_tasks; i++ ) {
- q.status[i] = TASK_READY;
- }
-
- /* Now it's safe to start using the status labels */
- if ( n_threads > 1 ) use_status_labels = 1;
-
- /* Start threads */
- for ( i=0; i<n_threads; i++ ) {
-
- struct worker_args *w;
-
- w = malloc(sizeof(struct worker_args));
-
- w->tqr = &q;
- w->tq = NULL;
- w->id = i;
- w->cpu_num = cpu_num;
- w->cpu_groupsize = cpu_groupsize;
- w->cpu_offset = cpu_offset;
-
- if ( pthread_create(&workers[i], NULL, range_worker, w) ) {
- /* Not ERROR() here */
- fprintf(stderr, "Couldn't start thread %i\n", i);
- n_threads = i;
- break;
- }
-
- }
-
- /* Join threads */
- for ( i=0; i<n_threads; i++ ) {
- pthread_join(workers[i], NULL);
- }
-
- use_status_labels = 0;
-
- free(q.status);
- free(workers);
-}
-
-
/* ---------------------------- Custom get_task() --------------------------- */
struct task_queue