[M3commit] CVS Update: cm3
Jay Krell
jkrell at elego.de
Tue Sep 29 12:04:28 CEST 2009
CVSROOT: /usr/cvs
Changes by: jkrell at birch. 09/09/29 12:04:28
Modified files:
cm3/m3-libs/m3core/src/thread/WIN32/: ThreadWin32.m3
Log message:
make it look a little more like ThreadPThread.m3 with
respect to
no need to lock setting of thread.result or reading thread.closure
remove assertion that thread.closure is non-NIL (maybe Win32 was better here?)
assert that allThreads # me; that is, the initial thread never gets here
redefine thread id from an always incrementing number to instead
match the Win32 thread id
Index: ThreadWin32.m3
===================================================================
RCS file: /usr/cvs/cm3/m3-libs/m3core/src/thread/WIN32/ThreadWin32.m3,v
retrieving revision 1.60
diff -u -w -r1.60 ThreadWin32.m3
--- ThreadWin32.m3 29 Sep 2009 09:54:06 -0000 1.60
+++ ThreadWin32.m3 29 Sep 2009 10:02:29 -0000
@@ -17,15 +17,14 @@
FROM WinBase IMPORT WaitForSingleObject, INFINITE, ReleaseSemaphore,
GetCurrentProcess, DuplicateHandle, GetCurrentThread, CreateSemaphore,
CloseHandle, CreateThread, ResumeThread, Sleep, SuspendThread,
- GetThreadContext, VirtualQuery, GetLastError, CREATE_SUSPENDED;
+ GetThreadContext, VirtualQuery, GetLastError, CREATE_SUSPENDED,
+ GetCurrentThreadId;
(*----------------------------------------- Exceptions, types and globals ---*)
VAR
default_stack: DWORD := 8192;
- nextId: Id := 1;
-
threadMu: Mutex;
(* Global lock for internal fields of Thread.T *)
@@ -499,31 +498,21 @@
END ThreadBase;
PROCEDURE RunThread (me: Activation) =
- VAR self: T; cl: Closure; res: REFANY;
+ VAR self: T;
BEGIN
EnterCriticalSection_slotMu();
self := slots [me.slot];
LeaveCriticalSection_slotMu();
- LockMutex(threadMu);
- cl := self.closure;
- self.id := nextId; INC (nextId);
- UnlockMutex(threadMu);
-
- IF (cl = NIL) THEN
- Die (ThisLine(), "NIL closure passed to Thread.Fork!");
- END;
-
(* Run the user-level code. *)
IF perfOn THEN PerfRunning(self.id) END;
- res := cl.apply();
+ self.result := self.closure.apply();
+ IF perfOn THEN PerfChanged(self.id, State.dying) END;
LockMutex(threadMu);
(* mark "self" done and clean it up a bit *)
- self.result := res;
self.completed := TRUE;
Broadcast(self.cond); (* let everybody know that "self" is done *)
- IF perfOn THEN PerfChanged(self.id, State.dying) END;
UnlockMutex(threadMu);
IF perfOn THEN PerfDeleted(self.id) END;
@@ -539,7 +528,7 @@
(* remove ourself from the list of active threads *)
EnterCriticalSection_activeMu();
- IF allThreads = me THEN allThreads := me.next; END;
+ <*ASSERT allThreads # me*>
me.next.prev := me.prev;
me.prev.next := me.next;
me.next := NIL;
@@ -571,6 +560,7 @@
act := t.act;
act.handle := CreateThread(NIL, stack_size, ThreadBase,
act, CREATE_SUSPENDED, ADR(id));
+ t.id := id;
EnterCriticalSection_activeMu();
act.next := allThreads;
act.prev := allThreads.prev;
@@ -932,7 +922,7 @@
BEGIN
threadMu := NEW(Mutex);
self := CreateT(me);
- self.id := nextId; INC (nextId);
+ self.id := GetCurrentThreadId();
mutex := NEW(MUTEX);
condition := NEW(Condition);
More information about the M3commit
mailing list