projects
/
model-checker.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
cbbc5fc
)
libthreads: add THREAD_* states
author
Brian Norris
<banorris@uci.edu>
Tue, 13 Mar 2012 03:38:18 +0000
(20:38 -0700)
committer
Brian Norris
<banorris@uci.edu>
Tue, 13 Mar 2012 03:38:18 +0000
(20:38 -0700)
libthreads.c
patch
|
blob
|
history
libthreads.h
patch
|
blob
|
history
diff --git
a/libthreads.c
b/libthreads.c
index 8d76bf12dbf7459cd83d97c18948fa08a39725fd..892d784587b7c00fa22083bde526567729326170 100644
(file)
--- a/
libthreads.c
+++ b/
libthreads.c
@@
-70,7
+70,7
@@
int thread_yield(void)
static void thread_dispose(struct thread *t)
{
DEBUG("completed thread %d\n", thread_current()->index);
static void thread_dispose(struct thread *t)
{
DEBUG("completed thread %d\n", thread_current()->index);
- t->
completed = 1
;
+ t->
state = THREAD_COMPLETED
;
stack_free(t->stack);
}
stack_free(t->stack);
}
@@
-106,13
+106,15
@@
int thread_create(struct thread *t, void (*start_routine), void *arg)
if (ret)
return ret;
if (ret)
return ret;
+ t->state = THREAD_CREATED;
+
model->scheduler->add_thread(t);
return 0;
}
void thread_join(struct thread *t)
{
model->scheduler->add_thread(t);
return 0;
}
void thread_join(struct thread *t)
{
- while (
!t->completed
)
+ while (
t->state != THREAD_COMPLETED
)
thread_yield();
}
thread_yield();
}
diff --git
a/libthreads.h
b/libthreads.h
index c0eb7d75c658e2e5d3de1842cefa75b67ec0b383..bf7acae804bc58a99d85cf883f9cf3d14e8b1bac 100644
(file)
--- a/
libthreads.h
+++ b/
libthreads.h
@@
-3,13
+3,20
@@
#include <ucontext.h>
#include <ucontext.h>
+typedef enum thread_state {
+ THREAD_CREATED,
+ THREAD_RUNNING,
+ THREAD_READY,
+ THREAD_COMPLETED
+} thread_state;
+
struct thread {
void (*start_routine);
void *arg;
ucontext_t context;
void *stack;
int index;
struct thread {
void (*start_routine);
void *arg;
ucontext_t context;
void *stack;
int index;
-
int completed
;
+
thread_state state
;
};
int thread_create(struct thread *t, void (*start_routine), void *arg);
};
int thread_create(struct thread *t, void (*start_routine), void *arg);