On (22 Aug 97) Darin Mcbride wrote to Thomas Maeder...
[ ... ]
DM> I'd post it, but the hand-coded queue uses OS/2 mutex's. Mind you, if
DM> I posted the entire class hiearchy, anyone who wanted to convert the
DM> one mutex class to Win32 could, and the rest of the class would work
DM> just fine. :-) A semaphore, in this class hiearchy, needs to:
DM> Create (publically, based on a semaphore name - not used by my
DM> queues)
DM> Create (privately, without a semaphore name)
DM> Claim (optionally with a timeout to wait for the semaphore to
DM> become available)
DM> Release
DM> Close
DM> Tell if the current thread has it claimed (note that the same
DM> object can be used by multiple threads in the same process)
DM> Tell if the semaphore name (in the public create) is valid
DM> If this is possible in Win32, I can post what I have for OS/2... :-)
As you doubtless expect, Win32's mutexes are similar enough to OS/2's
that all this should be pretty trivial to port. In fact, I did
something like this a long time ago, with both OS/2 and Win32 variants:
// event.h
//
#ifdef _OS2_
#define INCL_DOSSEMAPHORES
#include
#define OS2(x) (x)
#else
#define OS2(x)
#include
typedef HANDLE HEV;
#endif
class Event {
HEV *events; // Probably not really needed for OS/2, as SemRecords
// is pretty much the same thing...
unsigned how_many;
OS2(HMUX hMux;)
OS2(SEMRECORD *SemRecords;)
public:
Event(unsigned number);
void post(unsigned number);
void WaitAll(void);
~Event();
};
// event.cpp
//
#include "event.h"
#ifdef _OS2_
#define OS2(x) x
HEV CreateAnEvent(unsigned i) {
HEV hEv = NULLHANDLE;
char SemName[32];
(SemRecords + i)->hsemCur = NULL;
(SemRecords + i)->ulUser = i;
sprintf(SemName, "\\SEM32\\MT%d", i);
DosCreateEventSem(SemName, &hEv, 0L, FALSE);
(SemRecords + i)->hsemCur = (void *)hEv;
return hEv;
}
void Event::WaitAll() {
//Wait for the muxwait sem to post on all
unsigned long ulUser;
DosWaitMuxWaitSem(hMux, SEM_INDEFINITE_WAIT, &ulUser);
DosCloseMuxWaitSem(hMux);
}
void Event::post(unsigned number) {
HEV hEv = NULLHANDLE;
char SemName[32];
sprintf(SemName, "\\SEM32\\MT%d", number);
DosOpenEventSem(SemName, &hEv);
DosPostEventSem(hEv);
DosCloseEventSem(hEv);
}
#else
#define OS2(x)
HEV CreateAnEvent(unsigned i) {
return CreateEvent(NULL, FALSE, FALSE, NULL);
}
void Event::WaitAll() {
WaitForMultipleObjects(how_many, events, TRUE, INFINITE);
}
void Event::post(unsigned number ) {
SetEvent(events[number]);
}
#endif
Event::Event(unsigned number) {
how_many = number ;
events = new HEV[number];
OS2(SemRecords = new SEMRECORD[NumThreads];)
for ( unsigned i=0; i * Origin: Point Pointedly Pointless (1:128/166.5)
|