diff options
Diffstat (limited to 'uisimulator')
-rw-r--r-- | uisimulator/x11/thread.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/uisimulator/x11/thread.c b/uisimulator/x11/thread.c index ddaae313ae..437080acc9 100644 --- a/uisimulator/x11/thread.c +++ b/uisimulator/x11/thread.c | |||
@@ -23,6 +23,7 @@ | |||
23 | #include "kernel.h" | 23 | #include "kernel.h" |
24 | #include <poll.h> | 24 | #include <poll.h> |
25 | 25 | ||
26 | long current_tick = 0; | ||
26 | 27 | ||
27 | /* | 28 | /* |
28 | * We emulate the target threads by using pthreads. We have a mutex that only | 29 | * We emulate the target threads by using pthreads. We have a mutex that only |
@@ -38,6 +39,7 @@ void init_threads(void) | |||
38 | /* get mutex to only allow one thread running at a time */ | 39 | /* get mutex to only allow one thread running at a time */ |
39 | pthread_mutex_lock(&mp); | 40 | pthread_mutex_lock(&mp); |
40 | 41 | ||
42 | current_tick = time(NULL); /* give it a boost from start! */ | ||
41 | } | 43 | } |
42 | /* | 44 | /* |
43 | int pthread_create(pthread_t *new_thread_ID, | 45 | int pthread_create(pthread_t *new_thread_ID, |
@@ -45,16 +47,17 @@ void init_threads(void) | |||
45 | void * (*start_func)(void *), void *arg); | 47 | void * (*start_func)(void *), void *arg); |
46 | */ | 48 | */ |
47 | 49 | ||
48 | void (yield)(void) | 50 | void yield(void) |
49 | { | 51 | { |
52 | current_tick+=3; | ||
50 | pthread_mutex_unlock(&mp); /* return */ | 53 | pthread_mutex_unlock(&mp); /* return */ |
51 | pthread_mutex_lock(&mp); /* get it again */ | 54 | pthread_mutex_lock(&mp); /* get it again */ |
52 | } | 55 | } |
53 | 56 | ||
54 | void newfunc(void (*func)(void)) | 57 | void newfunc(void (*func)(void)) |
55 | { | 58 | { |
56 | yield(); | 59 | yield(); |
57 | func(); | 60 | func(); |
58 | } | 61 | } |
59 | 62 | ||
60 | 63 | ||
@@ -72,9 +75,9 @@ int create_thread(void* fp, void* sp, int stk_size) | |||
72 | (void *(*)(void *)) newfunc, /* function to start */ | 75 | (void *(*)(void *)) newfunc, /* function to start */ |
73 | fp /* start argument */); | 76 | fp /* start argument */); |
74 | if(0 != error) | 77 | if(0 != error) |
75 | fprintf(stderr, "Couldn't run thread number %d, errno %d\n", i, error); | 78 | fprintf(stderr, "Couldn't run thread number %d, errno %d\n", i, error); |
76 | else | 79 | else |
77 | fprintf(stderr, "Thread %ld is running\n", (long)tid); | 80 | fprintf(stderr, "Thread %ld is running\n", (long)tid); |
78 | 81 | ||
79 | yield(); | 82 | yield(); |
80 | 83 | ||
@@ -84,6 +87,7 @@ int create_thread(void* fp, void* sp, int stk_size) | |||
84 | /* ticks is HZ per second */ | 87 | /* ticks is HZ per second */ |
85 | void x11_sleep(int ticks) | 88 | void x11_sleep(int ticks) |
86 | { | 89 | { |
90 | current_tick+=5; | ||
87 | pthread_mutex_unlock(&mp); /* return */ | 91 | pthread_mutex_unlock(&mp); /* return */ |
88 | /* portable subsecond "sleep" */ | 92 | /* portable subsecond "sleep" */ |
89 | poll((void *)0, 0, ticks * 1000/HZ); | 93 | poll((void *)0, 0, ticks * 1000/HZ); |