[M3commit] CVS Update: cm3

Jay K jay.krell at cornell.edu
Thu Dec 10 17:53:57 CET 2009


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  | Mobile   +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/abe94eca/attachment-0002.html>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: ThreadWin32C.c
URL: <http://m3lists.elegosoft.com/pipermail/m3commit/attachments/20091210/abe94eca/attachment-0002.c>


More information about the M3commit mailing list