forked from andreyciupitu/thread-scheduler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathso_scheduler.h
99 lines (80 loc) · 1.7 KB
/
so_scheduler.h
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
* Threads scheduler header
*
* 2017, Operating Systems
*/
#ifndef SO_SCHEDULER_H_
#define SO_SCHEDULER_H_
/* OS dependent stuff */
#ifdef __linux__
#include <pthread.h>
#define DECL_PREFIX
typedef pthread_t tid_t;
#elif defined(_WIN32)
#include <windows.h>
#ifdef DLL_IMPORTS
#define DECL_PREFIX __declspec(dllimport)
#else
#define DECL_PREFIX __declspec(dllexport)
#endif
typedef DWORD tid_t;
#else
#error "Unknown platform"
#endif
/*
* the maximum priority that can be assigned to a thread
*/
#define SO_MAX_PRIO 5
/*
* the maximum number of events
*/
#define SO_MAX_NUM_EVENTS 256
/*
* return value of failed tasks
*/
#define INVALID_TID ((tid_t)0)
#ifdef __cplusplus
extern "C" {
#endif
/*
* handler prototype
*/
typedef void (so_handler)(unsigned int);
/*
* creates and initializes scheduler
* + time quantum for each thread
* + number of IO devices supported
* returns: 0 on success or negative on error
*/
DECL_PREFIX int so_init(unsigned int time_quantum, unsigned int io);
/*
* creates a new so_task_t and runs it according to the scheduler
* + handler function
* + priority
* returns: tid of the new task if successful or INVALID_TID
*/
DECL_PREFIX tid_t so_fork(so_handler *func, unsigned int priority);
/*
* waits for an IO device
* + device index
* returns: -1 if the device does not exist or 0 on success
*/
DECL_PREFIX int so_wait(unsigned int io);
/*
* signals an IO device
* + device index
* return the number of tasks woke or -1 on error
*/
DECL_PREFIX int so_signal(unsigned int io);
/*
* does whatever operation
*/
DECL_PREFIX void so_exec(void);
/*
* destroys a scheduler
*/
DECL_PREFIX void so_end(void);
#ifdef __cplusplus
}
#endif
#endif /* SO_SCHEDULER_H_ */