-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththreadPool.h
More file actions
35 lines (27 loc) · 858 Bytes
/
threadPool.h
File metadata and controls
35 lines (27 loc) · 858 Bytes
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
#ifndef __THREAD_POOL__
#define __THREAD_POOL__
#include <unistd.h>
#include "stdlib.h"
#include "osqueue.h"
#include "pthread.h"
#define ERROR "Error in system call\n"
/**
* info about a task(function pointer and arguments)
*/
typedef struct task{
void (*function_pointer)(void *);
void *param;
} task;
typedef struct thread_pool {
OSQueue* task_queue; // saves tasks
pthread_t ** threads; // saves threads
pthread_mutex_t mutex;
pthread_cond_t cond;
int run_permission; // can threads run tasks?(0/1)
int add_permission; // can we add tasks to the queue?(0/1)
int threads_count; // number of threads
} ThreadPool;
ThreadPool *tpCreate(int numOfThreads);
void tpDestroy(ThreadPool *threadPool, int shouldWaitForTasks);
int tpInsertTask(ThreadPool *threadPool, void (*computeFunc)(void *), void *param);
#endif