Paweł Wieczorek avatar Paweł Wieczorek committed 27ec6e9

* naprawiono przelaczanie watkow

Comments (0)

Files changed (4)

include/pwuthread/private.h

     int flags;
 };
 
+enum PWUTHREAD_FLAGS {
+    PWUTHREAD_RUN       = 0x001,
+    PWUTHREAD_JOIN      = 0x002,
+    PWUTHREAD_SLEEP     = 0x004,
+    PWUTHREAD_IO        = 0x008
+};
+
 void pwuthread_log(const char *fmt, ...);
 void pwuthread_perror(const char *fmt, ...);
 int pwuthread_init(void);
 #define PWUTHREAD_MALLOC(type) (type*)malloc(sizeof(type))
 #define PWUTHREAD_ICALL(c) ( (err = c) ) 
 
+#define PWUTHREAD_ISSET(x,b) ((x) & (b))
+#define PWUTHREAD_SET(x,b) (x) |= (b)
+#define PWUTHREAD_UNSET(x,b) (x) &= ~(b)
+
+#define PWUTHREAD_ISRUN(t) PWUTHREAD_ISSET(t->flags, PWUTHREAD_RUN)
+
 #endif
     if (old == t) return;
     if (!t->flags) return;
     pwuthread_current = t;
-    pwuthread_log("switch %p -> %p", old, t);
     old->saved_error = errno;
-    if (pwuthread_ctx_switch(t->context, old->context)) {
-        pwuthread_log("return %p <- ?%p", old, t); 
+    if (pwuthread_ctx_switch(old->context, t->context)) {
         errno = old->saved_error;
         pwuthread_current = old;
     }
 }
+
         thr, thr->main, thr->main_arg, thr->context, thr->stack_addr,
         thr->stack_len);
     *t = thr;
+    thr->flags = 1;
     return 0;
 }
 

support/unix_ctx_setjmp.c

+#define POSIX_C_SOURCE 200212L
+#define XOPEN_SOURCE 600
+
 #include "pwuthread/private.h"
 #include <setjmp.h>
 #include <signal.h>
     sigdelset(&shortjump_waitmask, SIGBUS);
     sigdelset(&shortjump_waitmask, SIGILL);
     sigdelset(&shortjump_waitmask, SIGFPE);
+    sigdelset(&shortjump_waitmask, SIGALRM);
     pwuthread_current->context = PWUTHREAD_MALLOC(struct pwuthread_ctx);
     return 0;
 }
     struct sigaction oldsa;
     sigset_t oldmask;
 
-    pwuthread_log("new ctx");
+    pwuthread_log("setjmp-ctx create %p entry=%p sa=%p+%x",
+        t, func, sa, sl);
     curstack.ss_sp = sa;
     curstack.ss_size = sl;
     curstack.ss_flags = 0;
         pwuthread_perror("setting new sigmask");
         return errno;
     }
-
     if (sigaltstack(&curstack, &oldstack) == -1) {
         pwuthread_perror("setting new sigaltstack");
         return errno;
     }
 
+    shortjump_sa.sa_mask = oldmask;
     if (sigaction(SIGUSR2, &shortjump_sa, &oldsa) == -1) {
         pwuthread_perror("setting new signal handler");
         return errno;
     t->next = pwuthread_current->next;
     pwuthread_current->next = t;
     t->next->prev = t;
-    pwuthread_log("NEW %p -> %p", pwuthread_current, pwuthread_current->next);
-    pwuthread_log("NEW %p", &t);
     shortjump_raised = 0;
     shortjump_thread = t;
     kill(getpid(), SIGUSR2);
             return errno;
         } 
     }
-
     if (sigaction(SIGUSR2, &oldsa, NULL) == -1) {
         pwuthread_perror("setting old signal handler");
         return errno;
     }
-
     if (sigaltstack(&oldstack, &curstack) == -1) {
         pwuthread_perror("setting old sigaltstack");
         return errno;
     }
-
     if (sigprocmask(SIG_SETMASK, &oldmask, NULL) == -1) {
         pwuthread_perror("setting old sigmask");
         return errno;
     }
-    pwuthread_log("uthread %p can work", t);
-    t->flags = 0;
-    longjmp(t->context->jb, 1);
     return 0;
 }
 
 shortjump_handler(int s)
 {
     pwuthread_t thread = shortjump_thread;
-    pwuthread_log("trampoline called %p %p", thread, &thread);
+    pwuthread_log("shortjump done for %p", thread);
     if (setjmp(thread->context->jb)) {
-        pwuthread_log("continuation called");
         thread->main_ret = thread->main(thread->main_arg);
         while(1);
     }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.