src/server/util/systhr.c

changeset 40
56cda23f48d4
parent 29
e8619defde14
child 41
bb7a1f5a8b48
--- a/src/server/util/systhr.c	Sun Dec 30 15:49:44 2012 +0100
+++ b/src/server/util/systhr.c	Mon Dec 31 00:07:52 2012 +0100
@@ -41,8 +41,8 @@
 #include "systhr.h"
 //include "ereport.h"
 
-#include "prinit.h"
-#include "prthread.h"
+//include "prinit.h"
+//include "prthread.h"
 #include "private/pprthred.h"
 
 #include "systems.h"
@@ -83,35 +83,29 @@
     return pthread_self();
 }
 
-void systhread_yield(void)
-{
+void systhread_yield(void) {
     sched_yield();
 }
 
 
-void systhread_timerset(int usec)
-{
+void systhread_timerset(int usec) {
    
 }
 
-SYS_THREAD systhread_attach(void)
-{
+SYS_THREAD systhread_attach(void) {
     /* TODO: what to do? */
     return 0;
 }
 
-void systhread_detach(SYS_THREAD thr)
-{
+void systhread_detach(SYS_THREAD thr) {
     pthread_detach(thr);
 }
 
-void systhread_terminate(SYS_THREAD thr)
-{
+void systhread_terminate(SYS_THREAD thr) {
     //PR_Interrupt((PRThread *)thr);
 }
 
-void systhread_sleep(int msec)
-{
+void systhread_sleep(int msec) {
     if(msec > 0) {
         poll(NULL, NULL, msec);
     } else {
@@ -119,11 +113,26 @@
     }
 }
 
+NSAPI_PUBLIC int systhread_newkey() {
+    pthread_key_t key;
+    pthread_key_create(&key, NULL);
+    
+    return (int)key; // TODO: don't use int
+}
+
+NSAPI_PUBLIC void* systhread_getdata(int key) {
+    return pthread_getspecific((pthread_key_t)key);
+}
+
+NSAPI_PUBLIC void systhread_setdata(int key, void *data) {
+    pthread_setspecific((pthread_key_t)key, data);
+}
+
 NSAPI_PUBLIC void systhread_init(char *name)
 {
-    if (!PR_Initialized()) {
-        PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 256);
-    }
+    //if (!PR_Initialized()) {
+    //    PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 256);
+    //}
     // XXX: ruslan - this bug can potentially exist on all plafroms due to
     //	possible priority inversion on NSPR spin locks. This code will
     //	need to be remove as we get new NSPR drop
@@ -139,33 +148,10 @@
     //	same effect as this fix. Debug version of NSPR always works as it doesn't
     //  have FD stack.
 
-    int maxPRFdCache = 8192;
-    PR_SetFDCacheSize(0, maxPRFdCache);
+    //int maxPRFdCache = 8192;
+    //PR_SetFDCacheSize(0, maxPRFdCache);
     // </WORKAROUND>
 }
 
-/*
- *  TODO: reimplement with pthread api
- */
-
-NSAPI_PUBLIC int systhread_newkey()
-{
-    uintn newkey;
-
-    PR_NewThreadPrivateIndex(&newkey, NULL);
-    return (newkey);
+NSAPI_PUBLIC void systhread_dummy(void) {
 }
-
-NSAPI_PUBLIC void *systhread_getdata(int key)
-{
-    return PR_GetThreadPrivate(key);
-}
-
-NSAPI_PUBLIC void systhread_setdata(int key, void *data)
-{
-    PR_SetThreadPrivate(key, data);
-}
-
-NSAPI_PUBLIC void systhread_dummy(void)
-{
-}

mercurial