forked from Wren6991/Ship-Sandbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscheduler.h
More file actions
50 lines (46 loc) · 958 Bytes
/
Copy pathscheduler.h
File metadata and controls
50 lines (46 loc) · 958 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#ifndef _SCHEDULER_H_
#define _SCHEDULER_H_
#include <queue>
#include "tinythread.h"
class scheduler
{
public:
struct task
{
virtual void process() = 0;
virtual ~task() {}
};
private:
class thread: public tthread::thread
{
scheduler *parent;
task *currentTask;
public:
int name;
thread(scheduler *_parent);
static void enter(void *_this);
};
class semaphore
{
tthread::mutex m;
tthread::condition_variable condition;
unsigned long count_;
public:
semaphore(): count_(0) {}
void signal();
void wait();
};
int nthreads;
std::vector <thread*> threadPool;
semaphore available;
semaphore completed;
std::queue<task*> tasks;
tthread::mutex critical;
public:
scheduler();
~scheduler();
void schedule(task *t);
void wait();
int getNThreads();
};
#endif // _SCHEDULER_H_