File: threadpool.h

package info (click to toggle)
gr-framework 0.73.14%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 11,600 kB
  • sloc: ansic: 87,413; cpp: 45,348; objc: 3,057; javascript: 2,647; makefile: 1,129; python: 1,000; sh: 991; yacc: 855; pascal: 554; fortran: 228
file content (36 lines) | stat: -rw-r--r-- 835 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#ifndef THREADPOOL_H_INCLUDED
#define THREADPOOL_H_INCLUDED

#ifdef _MSC_VER
#define NO_THREADS 1
#endif
#ifndef NO_THREADS

#include <stdbool.h>
#include <stddef.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

typedef void (*worker_func_t)(void *arg);
typedef struct threadpool
{
  worker_func_t worker_func;
  pthread_mutex_t work_mutex;
  pthread_cond_t wait_for_work_cond;
  pthread_cond_t work_fetched;
  pthread_cond_t all_work_done_cond;
  size_t working_cnt;
  size_t thread_cnt;
  pthread_t *threads;
  int stop;
} threadpool_t;

void threadpool_create(threadpool_t *tp, size_t num, worker_func_t func);
void threadpool_destroy(threadpool_t *tp);
void threadpool_add_work(threadpool_t *tp, void *arg);
void threadpool_wait(threadpool_t *tp);

#endif
#endif /* ifndef THREADPOOL_H_INCLUDED */