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); 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)))) { if (t->m->system->success(t->m->system->start(&(p->runnable)))) {
return reinterpret_cast<jlong>(p); return reinterpret_cast<jlong>(p);
} else { } else {

View File

@ -1156,6 +1156,9 @@ printTrace(Thread* t, object exception);
uint8_t& uint8_t&
threadInterrupted(Thread* t, object thread); threadInterrupted(Thread* t, object thread);
void
enterActiveState(Thread* t);
class Thread { class Thread {
public: public:
enum State { enum State {
@ -1204,6 +1207,8 @@ class Thread {
} }
virtual void run() { virtual void run() {
enterActiveState(t);
t->m->localThread->set(t); t->m->localThread->set(t);
t->m->processor->invoke t->m->processor->invoke
@ -1266,6 +1271,12 @@ objectClass(Thread*, object o)
void void
enter(Thread* t, Thread::State state); enter(Thread* t, Thread::State state);
inline void
enterActiveState(Thread* t)
{
enter(t, Thread::ActiveState);
}
class StateResource { class StateResource {
public: public:
StateResource(Thread* t, Thread::State state): t(t), oldState(t->state) { 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) { virtual bool tryAcquire(System::Thread* context) {
Thread* t = static_cast<Thread*>(context); Thread* t = static_cast<Thread*>(context);
assert(s, t);
if (owner_ == t) { if (owner_ == t) {
++ depth; ++ depth;
@ -122,6 +123,7 @@ class MySystem: public System {
virtual void acquire(System::Thread* context) { virtual void acquire(System::Thread* context) {
Thread* t = static_cast<Thread*>(context); Thread* t = static_cast<Thread*>(context);
assert(s, t);
if (owner_ != t) { if (owner_ != t) {
int r UNUSED = WaitForSingleObject(mutex, INFINITE); int r UNUSED = WaitForSingleObject(mutex, INFINITE);
@ -133,6 +135,7 @@ class MySystem: public System {
virtual void release(System::Thread* context) { virtual void release(System::Thread* context) {
Thread* t = static_cast<Thread*>(context); Thread* t = static_cast<Thread*>(context);
assert(s, t);
if (owner_ == t) { if (owner_ == t) {
if (-- depth == 0) { if (-- depth == 0) {
@ -169,6 +172,7 @@ class MySystem: public System {
virtual bool wait(System::Thread* context, int64_t time) { virtual bool wait(System::Thread* context, int64_t time) {
Thread* t = static_cast<Thread*>(context); Thread* t = static_cast<Thread*>(context);
assert(s, t);
if (owner_ == t) { if (owner_ == t) {
ACQUIRE(s, t->mutex); ACQUIRE(s, t->mutex);
@ -196,7 +200,7 @@ class MySystem: public System {
assert(s, success); assert(s, success);
int r UNUSED = WaitForSingleObject(t->event, (time ? time : INFINITE)); 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); r = WaitForSingleObject(t->mutex, INFINITE);
assert(s, r == WAIT_OBJECT_0); assert(s, r == WAIT_OBJECT_0);
@ -230,12 +234,13 @@ class MySystem: public System {
t->flags |= Notified; t->flags |= Notified;
int r UNUSED = SetEvent(t->event); bool success UNUSED = SetEvent(t->event);
assert(s, r == 0); assert(s, success);
} }
virtual void notify(System::Thread* context) { virtual void notify(System::Thread* context) {
Thread* t = static_cast<Thread*>(context); Thread* t = static_cast<Thread*>(context);
assert(s, t);
if (owner_ == t) { if (owner_ == t) {
if (first) { if (first) {
@ -254,6 +259,7 @@ class MySystem: public System {
virtual void notifyAll(System::Thread* context) { virtual void notifyAll(System::Thread* context) {
Thread* t = static_cast<Thread*>(context); Thread* t = static_cast<Thread*>(context);
assert(s, t);
if (owner_ == t) { if (owner_ == t) {
for (Thread* t = first; t; t = t->next) { for (Thread* t = first; t; t = t->next) {