Commits

Paweł Wieczorek committed 805ec7a

* zrobiono porządek z sched_unix

  • Participants
  • Parent commits f8fd88f

Comments (0)

Files changed (3)

include/pwuthread/sched.h

 void pwuthread_sched_clocktick(void *u);
 
 void pwuthread_sched_switch(pwuthread_t t);
+int pwuthread_sched_getlock(void);
 void pwuthread_sched_lock(void);
 void pwuthread_sched_unlock(void);
 void pwuthread_sched_exit(void);
 #include <signal.h>
 #include <unistd.h>
 
-static int sched_lock = 0;
-static sigset_t sched_locksigset;
 static pwuthread_t idle_thread;
-
 static pwuthread_time_t diff_time;
 static pwuthread_time_t last_time;
 
     pwuthread_sched_yield();
 }
 
-/*
- *
- */
-void
-pwuthread_sched_yield(void)
-{
-    kill(getpid(), SIGALRM);
-    sigset_t newss;
-    sigfillset(&newss);
-    sigdelset(&newss, SIGALRM); 
-    sigsuspend(&newss);
-}
-
-/*
- *
- */
-void
-pwuthread_sched_lock(void)
-{
-    sigset_t s;
-    
-//    pwuthread_log("thread %p: LOCK", pwuthread_current);
-    assert(!sched_lock);
-    sched_lock = 1;
-    sigfillset(&s);
-    sigprocmask(SIG_SETMASK, &s, &sched_locksigset);
-}
-
-/*
- *
- */
-void
-pwuthread_sched_unlock(void)
-{
-//    pwuthread_log("thread %p: UNLOCK", pwuthread_current);
-    assert(sched_lock);
-    sched_lock = 0;
-    sigprocmask(SIG_SETMASK, &sched_locksigset, NULL);
-}
 
 void
 pwuthread_sched_wait(void)
     // sekcji krytycznej planisty. 
     // Sama się dostosowuje do realiów, zapamiętając stan w s.
     
-    int s = sched_lock;
+    int s = pwuthread_sched_getlock();
     if (!s) {
         pwuthread_sched_lock();
     }
 void
 pwuthread_sched_timedwait(int ts, int tus)
 {
-    int s = sched_lock;
+    int s = pwuthread_sched_getlock();
     if (!s) {
         pwuthread_sched_lock();
     }

support/unix_sched.c

 #include <sys/time.h>
 #include <signal.h>
 #include <errno.h>
+#include <assert.h>
 
 static void sched_clocktick(int sn, siginfo_t *si, void *u);
+static int sched_lock = 0;
+static sigset_t sched_locksigset;
+
+void
+pwuthread_sched_yield(void)
+{
+    raise(SIGALRM);
+    /*
+    sigset_t newss;
+    sigfillset(&newss);
+    sigdelset(&newss, SIGALRM); 
+    sigsuspend(&newss);
+    */
+}
+
+int
+pwuthread_sched_getlock(void)
+{
+    return sched_lock;
+}
+
+/*
+ *
+ */
+void
+pwuthread_sched_lock(void)
+{
+    sigset_t s;
+//    pwuthread_log("thread %p: LOCK", pwuthread_current);
+    assert(!sched_lock);
+    sched_lock = 1;
+    sigfillset(&s);
+    sigprocmask(SIG_SETMASK, &s, &sched_locksigset);
+}
+
+/*
+ *
+ */
+void
+pwuthread_sched_unlock(void)
+{
+//    pwuthread_log("thread %p: UNLOCK", pwuthread_current);
+    assert(sched_lock);
+    sched_lock = 0;
+    sigprocmask(SIG_SETMASK, &sched_locksigset, NULL);
+}
 
 
 int
 }
 
 
-
 void
 sched_clocktick(int sn, siginfo_t *si, void *u)
 {