69 void systhread_set_default_stacksize(unsigned long size) |
59 void systhread_set_default_stacksize(unsigned long size) |
70 { |
60 { |
71 _systhr_stacksize = size; |
61 _systhr_stacksize = size; |
72 } |
62 } |
73 |
63 |
74 NSAPI_PUBLIC |
64 |
75 SYS_THREAD systhread_start(int prio, int stksz, thrstartfunc fn, void *arg) |
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 /* error */ |
|
77 } |
|
78 |
|
79 return thr; |
|
80 } |
|
81 |
|
82 SYS_THREAD systhread_current(void) { |
|
83 return pthread_self(); |
|
84 } |
|
85 |
|
86 void systhread_yield(void) |
76 { |
87 { |
77 PRThread *ret = PR_CreateThread(PR_USER_THREAD, (void (*)(void *))fn, |
88 sched_yield(); |
78 (void *)arg, (PRThreadPriority)prio, |
|
79 PR_GLOBAL_THREAD, PR_UNJOINABLE_THREAD, |
|
80 stksz ? stksz : _systhr_stacksize); |
|
81 return (void *) ret; |
|
82 } |
89 } |
83 |
90 |
84 |
91 |
85 NSAPI_PUBLIC SYS_THREAD systhread_current(void) |
92 void systhread_timerset(int usec) |
86 { |
93 { |
87 return PR_GetCurrentThread(); |
94 |
88 } |
95 } |
89 |
96 |
90 NSAPI_PUBLIC void systhread_yield(void) |
97 SYS_THREAD systhread_attach(void) |
91 { |
98 { |
92 PR_Sleep(PR_INTERVAL_NO_WAIT); |
99 /* TODO: what to do? */ |
|
100 return 0; |
93 } |
101 } |
94 |
102 |
95 |
103 void systhread_detach(SYS_THREAD thr) |
96 NSAPI_PUBLIC void systhread_timerset(int usec) |
|
97 { |
104 { |
98 /* This is an interesting problem. If you ever do turn on interrupts |
105 pthread_detach(thr); |
99 * on the server, you're in for lots of fun with NSPR Threads |
|
100 PR_StartEvents(usec); */ |
|
101 } |
106 } |
102 |
107 |
103 |
108 void systhread_terminate(SYS_THREAD thr) |
104 NSAPI_PUBLIC |
|
105 SYS_THREAD systhread_attach(void) |
|
106 { |
109 { |
107 PRThread *ret; |
110 //PR_Interrupt((PRThread *)thr); |
108 ret = PR_AttachThread(PR_USER_THREAD, PR_PRIORITY_NORMAL, NULL); |
|
109 |
|
110 return (void *) ret; |
|
111 } |
111 } |
112 |
112 |
113 NSAPI_PUBLIC |
113 void systhread_sleep(int msec) |
114 void systhread_detach(SYS_THREAD thr) |
|
115 { |
114 { |
116 /* XXXMB - this is not correct! */ |
115 if(msec > 0) { |
117 PR_DetachThread(); |
116 poll(NULL, NULL, msec); |
118 } |
117 } else { |
119 |
118 sched_yield(); |
120 NSAPI_PUBLIC void systhread_terminate(SYS_THREAD thr) |
119 } |
121 { |
|
122 PR_Interrupt((PRThread *)thr); |
|
123 } |
|
124 |
|
125 NSAPI_PUBLIC void systhread_sleep(int milliseconds) |
|
126 { |
|
127 #ifdef XP_WIN32 |
|
128 PR_Sleep(PR_MillisecondsToInterval(milliseconds)); |
|
129 #else |
|
130 /* poll() is more efficient than PR_Sleep() */ |
|
131 if (milliseconds > 0) |
|
132 poll(NULL, NULL, milliseconds); |
|
133 #endif |
|
134 } |
120 } |
135 |
121 |
136 NSAPI_PUBLIC void systhread_init(char *name) |
122 NSAPI_PUBLIC void systhread_init(char *name) |
137 { |
123 { |
138 if (!PR_Initialized()) { |
124 if (!PR_Initialized()) { |