-
Notifications
You must be signed in to change notification settings - Fork 0
/
job_api.h
71 lines (56 loc) · 1.02 KB
/
job_api.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
#ifndef _JOB_API_H_
#define _JOB_API_H_
#ifdef SESC
#include "sescapi.h"
#else
#include <pthread.h>
#endif
struct work_struct {
int id;
/*
* add here whatever fields you need. See job_api_example.[ch]
* for an example.
*/
#ifndef SESC
pthread_t pthread;
#endif /* !SESC */
};
#ifdef SESC
static inline void job_create(void (*func), void *arg, long flags)
{
sesc_spawn(func, arg, flags);
}
static inline int job_join(struct work_struct *work)
{
sesc_wait();
return 0;
}
static inline void job_init(void)
{
sesc_init();
}
static inline void job_exit(void)
{
sesc_exit(0);
}
#else
static inline void job_create(void (*func), void *arg, long flags)
{
struct work_struct *work = arg;
if(pthread_create(&work->pthread, NULL, func, arg)!=0){
perror("can't create thread!");
}
}
static inline int job_join(struct work_struct *work)
{
return pthread_join(work->pthread, NULL);
}
static inline void job_init(void)
{
}
static inline void job_exit(void)
{
pthread_exit(NULL);
}
#endif /* SESC */
#endif /* _JOB_API_H_ */