[M3commit] CVS Update: cm3

Jay K jay.krell at cornell.edu
Thu Dec 10 18:21:10 CET 2009


I think the problem might just be not understanding the Modula-3 object/linkage model.

I thought if just change ThreadWin32.m3, I didn't have to recompile/link anything besides m3core.dll.

That seems to be wrong though.

It seems maybe the sizes of types not exposed in .i3 files are exposed to the object code of clients.

?

I'll try again.

 

 -Jay




From: jay.krell at cornell.edu
To: hosking at cs.purdue.edu
Date: Thu, 10 Dec 2009 16:53:57 +0000
CC: m3commit at elegosoft.com
Subject: Re: [M3commit] CVS Update: cm3



Maybe some of them need not be?
I have a simple implementation but it fails.




? 
Attached. Tried to put this in for Thread.Mutex, not the static locks. It is based on the Java code.

NewLockE, LockE, UnlockE.
 
typedef struct _LockE_t { /* E = exclusive */
    long count;
    int owner;
    HANDLE event;
} LockE_t;
 
void __cdecl ThreadWin32__DeleteLockE(LockE_t* lock)
/* E = exclusive */
{
    if (lock)
    {
        HANDLE event = lock->event;
        assert(lock->owner == 0);
        assert(lock->count == -1);
        if (event)
            CloseHandle(event);
        HeapFree(GetProcessHeap(), 0, lock);
    }
}
 
LockE_t* __cdecl ThreadWin32__NewLockE(void)
/* E = exclusive */
{
    HANDLE event;
    LockE_t* lock = (LockE_t*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*lock));
    if (!lock)
        goto Error;
    lock->owner = 0;
    lock->count = -1;
    if (!(lock->event = CreateEventA(0, 0, 0, 0)))
        goto Error;
    return lock;
Error:
    ThreadWin32__DeleteLockE(lock);
    return NULL;
}
 
void __cdecl ThreadWin32__LockE(LockE_t* lock)
/* E = exclusive */
{
    if (InterlockedIncrement(&lock->count) != 0)
        WaitForSingleObject(lock->event, INFINITE);
    assert(lock->owner == 0);
    lock->owner = GetCurrentThreadId();
}
 
void __cdecl ThreadWin32__UnlockE(LockE_t* lock)
/* E = exclusive */
{
    assert(lock->owner == GetCurrentThreadId());
    lock->owner = 0;
    if (InterlockedDecrement(&lock->count) >= 0)
        SetEvent(lock->event);
}

 
 - Jay

 


From: hosking at cs.purdue.edu
Date: Thu, 10 Dec 2009 11:16:08 -0500
To: jkrell at elego.de
CC: m3commit at elegosoft.com
Subject: Re: [M3commit] CVS Update: cm3

Umm.  Modula-3 locks are *not* recursive...







Antony Hosking | Associate Professor | Computer Science | Purdue University
305 N. University Street | West Lafayette | IN 47907 | USA
Office    +1 765 494 6001  +1 765 494 6001    +1 765 494 6001  +1 765 494 6001      +1 765 494 6001  +1 765 494 6001    +1 765 494 6001  +1 765 494 6001   | Mobile    +1 765 427 5484  +1 765 427 5484    +1 765 427 5484  +1 765 427 5484      +1 765 427 5484  +1 765 427 5484    +1 765 427 5484  +1 765 427 5484  



On 10 Dec 2009, at 16:08, Jay Krell wrote:

CVSROOT: /usr/cvs
Changes by: jkrell at birch. 09/12/10 16:08:58

Modified files:
cm3/m3-libs/m3core/src/thread/WIN32/: ThreadWin32.i3 
                                     ThreadWin32.m3 
                                     ThreadWin32C.c 

Log message:
rename Lock => LockRE for recursive/exclusive
so that we might introduce LockE for exclusive


 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3commit/attachments/20091210/4e754a8d/attachment-0002.html>


More information about the M3commit mailing list