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 #include "systhr.h"
42
43
44
45
46
47
48 #include "systems.h"
49
50 #ifdef XP_UNIX
51 #include <poll.h>
52 #endif
53
54 #define DEFAULT_STACKSIZE (
64*
1024)
55
56 static unsigned long _systhr_stacksize =
DEFAULT_STACKSIZE;
57
58 NSAPI_PUBLIC
59 void systhread_set_default_stacksize(
unsigned long size)
60 {
61 _systhr_stacksize = size;
62 }
63
64
65
66 SYS_THREAD systhread_start(
int prio,
int stksz, thrstartfunc fn,
void *arg) {
67 pthread_t thr =
0;
68 pthread_attr_t attr;
69
70 pthread_attr_init(&attr);
71 if(stksz) {
72 pthread_attr_setstacksize(&attr, stksz);
73 }
74
75 if(pthread_create(&thr, &attr, (posix_thrstartfunc)fn, arg) !=
0) {
76
77 }
78
79 return thr;
80 }
81
82 SYS_THREAD systhread_current(
void) {
83 return pthread_self();
84 }
85
86 void systhread_yield(
void) {
87 sched_yield();
88 }
89
90
91 void systhread_timerset(
int usec) {
92
93 }
94
95 SYS_THREAD systhread_attach(
void) {
96
97 return 0;
98 }
99
100 void systhread_detach(
SYS_THREAD thr) {
101 pthread_detach(thr);
102 }
103
104 void systhread_terminate(
SYS_THREAD thr) {
105
106 }
107
108 void systhread_sleep(
int msec) {
109 if(msec >
0) {
110 poll(
NULL,
0, msec);
111 }
else {
112 sched_yield();
113 }
114 }
115
116 NSAPI_PUBLIC int systhread_newkey() {
117 pthread_key_t key;
118 pthread_key_create(&key,
NULL);
119
120 return (
int)key;
121 }
122
123 NSAPI_PUBLIC void* systhread_getdata(
int key) {
124 return pthread_getspecific((
pthread_key_t)key);
125 }
126
127 NSAPI_PUBLIC void systhread_setdata(
int key,
void *data) {
128 pthread_setspecific((
pthread_key_t)key, data);
129 }
130
131 NSAPI_PUBLIC void systhread_init(
char *name)
132 {
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154 }
155
156 NSAPI_PUBLIC void systhread_dummy(
void) {
157 }
158