src/server/util/systhr.c

changeset 40
56cda23f48d4
parent 29
e8619defde14
child 41
bb7a1f5a8b48
equal deleted inserted replaced
39:de4bc3cd2d36 40:56cda23f48d4
39 39
40 40
41 #include "systhr.h" 41 #include "systhr.h"
42 //include "ereport.h" 42 //include "ereport.h"
43 43
44 #include "prinit.h" 44 //include "prinit.h"
45 #include "prthread.h" 45 //include "prthread.h"
46 #include "private/pprthred.h" 46 #include "private/pprthred.h"
47 47
48 #include "systems.h" 48 #include "systems.h"
49 49
50 #ifdef XP_UNIX 50 #ifdef XP_UNIX
81 81
82 SYS_THREAD systhread_current(void) { 82 SYS_THREAD systhread_current(void) {
83 return pthread_self(); 83 return pthread_self();
84 } 84 }
85 85
86 void systhread_yield(void) 86 void systhread_yield(void) {
87 {
88 sched_yield(); 87 sched_yield();
89 } 88 }
90 89
91 90
92 void systhread_timerset(int usec) 91 void systhread_timerset(int usec) {
93 {
94 92
95 } 93 }
96 94
97 SYS_THREAD systhread_attach(void) 95 SYS_THREAD systhread_attach(void) {
98 {
99 /* TODO: what to do? */ 96 /* TODO: what to do? */
100 return 0; 97 return 0;
101 } 98 }
102 99
103 void systhread_detach(SYS_THREAD thr) 100 void systhread_detach(SYS_THREAD thr) {
104 {
105 pthread_detach(thr); 101 pthread_detach(thr);
106 } 102 }
107 103
108 void systhread_terminate(SYS_THREAD thr) 104 void systhread_terminate(SYS_THREAD thr) {
109 {
110 //PR_Interrupt((PRThread *)thr); 105 //PR_Interrupt((PRThread *)thr);
111 } 106 }
112 107
113 void systhread_sleep(int msec) 108 void systhread_sleep(int msec) {
114 {
115 if(msec > 0) { 109 if(msec > 0) {
116 poll(NULL, NULL, msec); 110 poll(NULL, NULL, msec);
117 } else { 111 } else {
118 sched_yield(); 112 sched_yield();
119 } 113 }
120 } 114 }
121 115
116 NSAPI_PUBLIC int systhread_newkey() {
117 pthread_key_t key;
118 pthread_key_create(&key, NULL);
119
120 return (int)key; // TODO: don't use int
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
122 NSAPI_PUBLIC void systhread_init(char *name) 131 NSAPI_PUBLIC void systhread_init(char *name)
123 { 132 {
124 if (!PR_Initialized()) { 133 //if (!PR_Initialized()) {
125 PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 256); 134 // PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 256);
126 } 135 //}
127 // XXX: ruslan - this bug can potentially exist on all plafroms due to 136 // XXX: ruslan - this bug can potentially exist on all plafroms due to
128 // possible priority inversion on NSPR spin locks. This code will 137 // possible priority inversion on NSPR spin locks. This code will
129 // need to be remove as we get new NSPR drop 138 // need to be remove as we get new NSPR drop
130 // <WORKAROUND> 139 // <WORKAROUND>
131 /* VB: This is to fix bug# 364813 coupled with NSPR not wanting to patch 140 /* VB: This is to fix bug# 364813 coupled with NSPR not wanting to patch
137 // atomic operations on DEC, it's an assembly code which is different 146 // atomic operations on DEC, it's an assembly code which is different
138 // for every platform. NSPR_FD_CACHE_SIZE_HIGH env var will cause the 147 // for every platform. NSPR_FD_CACHE_SIZE_HIGH env var will cause the
139 // same effect as this fix. Debug version of NSPR always works as it doesn't 148 // same effect as this fix. Debug version of NSPR always works as it doesn't
140 // have FD stack. 149 // have FD stack.
141 150
142 int maxPRFdCache = 8192; 151 //int maxPRFdCache = 8192;
143 PR_SetFDCacheSize(0, maxPRFdCache); 152 //PR_SetFDCacheSize(0, maxPRFdCache);
144 // </WORKAROUND> 153 // </WORKAROUND>
145 } 154 }
146 155
147 /* 156 NSAPI_PUBLIC void systhread_dummy(void) {
148 * TODO: reimplement with pthread api
149 */
150
151 NSAPI_PUBLIC int systhread_newkey()
152 {
153 uintn newkey;
154
155 PR_NewThreadPrivateIndex(&newkey, NULL);
156 return (newkey);
157 } 157 }
158
159 NSAPI_PUBLIC void *systhread_getdata(int key)
160 {
161 return PR_GetThreadPrivate(key);
162 }
163
164 NSAPI_PUBLIC void systhread_setdata(int key, void *data)
165 {
166 PR_SetThreadPrivate(key, data);
167 }
168
169 NSAPI_PUBLIC void systhread_dummy(void)
170 {
171 }

mercurial