fix a few threading bugs in windows port

This commit is contained in:
Joel Dice 2007-10-23 16:21:28 -06:00
parent cfd4ebcb21
commit c3300948bf
3 changed files with 20 additions and 5 deletions

View File

@ -634,8 +634,6 @@ Java_java_lang_Thread_doStart(Thread* t, jobject this_)
Thread* p = t->m->processor->makeThread(t->m, *this_, t);
enter(p, Thread::ActiveState);
if (t->m->system->success(t->m->system->start(&(p->runnable)))) {
return reinterpret_cast<jlong>(p);
} else {

View File

@ -1156,6 +1156,9 @@ printTrace(Thread* t, object exception);
uint8_t&
threadInterrupted(Thread* t, object thread);
void
enterActiveState(Thread* t);
class Thread {
public:
enum State {
@ -1204,6 +1207,8 @@ class Thread {
}
virtual void run() {
enterActiveState(t);
t->m->localThread->set(t);
t->m->processor->invoke
@ -1266,6 +1271,12 @@ objectClass(Thread*, object o)
void
enter(Thread* t, Thread::State state);
inline void
enterActiveState(Thread* t)
{
enter(t, Thread::ActiveState);
}
class StateResource {
public:
StateResource(Thread* t, Thread::State state): t(t), oldState(t->state) {

View File

@ -100,6 +100,7 @@ class MySystem: public System {
virtual bool tryAcquire(System::Thread* context) {
Thread* t = static_cast<Thread*>(context);
assert(s, t);
if (owner_ == t) {
++ depth;
@ -122,6 +123,7 @@ class MySystem: public System {
virtual void acquire(System::Thread* context) {
Thread* t = static_cast<Thread*>(context);
assert(s, t);
if (owner_ != t) {
int r UNUSED = WaitForSingleObject(mutex, INFINITE);
@ -133,6 +135,7 @@ class MySystem: public System {
virtual void release(System::Thread* context) {
Thread* t = static_cast<Thread*>(context);
assert(s, t);
if (owner_ == t) {
if (-- depth == 0) {
@ -169,6 +172,7 @@ class MySystem: public System {
virtual bool wait(System::Thread* context, int64_t time) {
Thread* t = static_cast<Thread*>(context);
assert(s, t);
if (owner_ == t) {
ACQUIRE(s, t->mutex);
@ -196,7 +200,7 @@ class MySystem: public System {
assert(s, success);
int r UNUSED = WaitForSingleObject(t->event, (time ? time : INFINITE));
assert(s, r == WAIT_OBJECT_0);
assert(s, r == WAIT_OBJECT_0 or r == WAIT_TIMEOUT);
r = WaitForSingleObject(t->mutex, INFINITE);
assert(s, r == WAIT_OBJECT_0);
@ -230,12 +234,13 @@ class MySystem: public System {
t->flags |= Notified;
int r UNUSED = SetEvent(t->event);
assert(s, r == 0);
bool success UNUSED = SetEvent(t->event);
assert(s, success);
}
virtual void notify(System::Thread* context) {
Thread* t = static_cast<Thread*>(context);
assert(s, t);
if (owner_ == t) {
if (first) {
@ -254,6 +259,7 @@ class MySystem: public System {
virtual void notifyAll(System::Thread* context) {
Thread* t = static_cast<Thread*>(context);
assert(s, t);
if (owner_ == t) {
for (Thread* t = first; t; t = t->next) {