Index: trunk/src/wsock32/makefile
===================================================================
--- trunk/src/wsock32/makefile	(revision 8902)
+++ trunk/src/wsock32/makefile	(revision 8903)
@@ -1,3 +1,3 @@
-# $Id: makefile,v 1.33 2001-09-30 09:12:17 bird Exp $
+# $Id: makefile,v 1.34 2002-07-22 09:53:47 sandervl Exp $
 
 #
@@ -34,4 +34,5 @@
 $(OBJDIR)\asyncapi.obj \
 $(OBJDIR)\asyncthread.obj \
+$(OBJDIR)\vsemaphore.obj \
 $(OBJDIR)\dbglocal.obj \
 $(OBJDIR)\wsock2.obj
Index: trunk/src/wsock32/vsemaphore.cpp
===================================================================
--- trunk/src/wsock32/vsemaphore.cpp	(revision 8903)
+++ trunk/src/wsock32/vsemaphore.cpp	(revision 8903)
@@ -0,0 +1,123 @@
+/* $Id: vsemaphore.cpp,v 1.1 2002-07-22 09:53:47 sandervl Exp $ */
+
+/*
+ * Semaphore class
+ *
+ * Copyright 2000 Sander van Leeuwen (sandervl@xs4all.nl)
+ *
+ *
+ * NOTE: When creating a shared semaphore object, you must call the ctor, wait &
+ *       post with a 2nd parameter (HMTX *). This semaphore handle must be located
+ *       in the local data segment of the dll.
+ *       This enables other processes than the one that created the semaphore object
+ *       to access it 
+ *
+ * Project Odin Software License can be found in LICENSE.TXT
+ *
+ */
+#define INCL_DOSSEMAPHORES
+#define INCL_DOSERRORS
+#include <os2wrap.h>	//Odin32 OS/2 api wrappers
+#include <VSemaphore.h>
+#include <win32type.h>
+#include <misc.h>
+
+/******************************************************************************/
+/******************************************************************************/
+VSemaphore::VSemaphore(int fShared, HEV *phSem)
+{
+ APIRET rc;
+
+  this->fShared = fShared;
+  rc = DosCreateEventSem(NULL, &sem_handle, (fShared == VSEMAPHORE_SHARED) ? DC_SEM_SHARED : 0, FALSE);
+  if(rc != 0) {
+    dprintf(("Error creating mutex %X\n", rc));
+    sem_handle = 0;
+  }
+  if(fShared) {
+	*phSem = sem_handle;
+  }
+}
+/******************************************************************************/
+/******************************************************************************/
+VSemaphore::~VSemaphore()
+{
+  if(sem_handle) {
+    	DosCloseEventSem(sem_handle);
+  }
+}
+/******************************************************************************/
+/******************************************************************************/
+void VSemaphore::wait(ULONG timeout, HEV *phSem)
+{
+ APIRET rc;
+
+  if(fShared == VSEMAPHORE_SHARED && phSem == NULL) {
+	DebugInt3();
+	return;
+  }
+  if(sem_handle) {
+	if(fShared == VSEMAPHORE_SHARED && *phSem == 0) {
+		//must open the shared semaphore first (other process created it)
+		*phSem = sem_handle;
+		rc = DosOpenEventSem(NULL, phSem);
+		if(rc) {
+			DebugInt3();
+		}
+	}
+    	rc = DosWaitEventSem((fShared == VSEMAPHORE_SHARED) ? *phSem : sem_handle, timeout);
+  	if(rc) {
+		DebugInt3();
+  	}
+  }
+}
+/******************************************************************************/
+/******************************************************************************/
+void VSemaphore::reset(HMTX *phSem)
+{
+ APIRET rc;
+ ULONG  count;
+
+  if(fShared == VSEMAPHORE_SHARED && phSem == NULL) {
+	DebugInt3();
+	return;
+  }
+  if(fShared == VSEMAPHORE_SHARED && *phSem == 0) {
+	//must open the shared semaphore first (other process created it)
+	*phSem = sem_handle;
+	rc = DosOpenEventSem(NULL, phSem);
+	if(rc) {
+		DebugInt3();
+	}
+  }
+  rc = DosResetEventSem((fShared == VSEMAPHORE_SHARED) ? *phSem : sem_handle, &count);
+  if(rc != NO_ERROR && rc != ERROR_ALREADY_RESET) {
+	DebugInt3();
+  }
+}
+/******************************************************************************/
+/******************************************************************************/
+void VSemaphore::post(HMTX *phSem)
+{
+ APIRET rc;
+
+  if(fShared == VSEMAPHORE_SHARED && phSem == NULL) {
+	DebugInt3();
+	return;
+  }
+  if(fShared == VSEMAPHORE_SHARED && *phSem == 0) {
+	//must open the shared semaphore first (other process created it)
+	*phSem = sem_handle;
+	rc = DosOpenEventSem(NULL, phSem);
+	if(rc) {
+		DebugInt3();
+	}
+  }
+  rc = DosPostEventSem((fShared == VSEMAPHORE_SHARED) ? *phSem : sem_handle);
+  if(rc != NO_ERROR && rc != ERROR_ALREADY_POSTED) {
+	DebugInt3();
+  }
+}
+/******************************************************************************/
+/******************************************************************************/
+
Index: trunk/src/wsock32/vsemaphore.h
===================================================================
--- trunk/src/wsock32/vsemaphore.h	(revision 8903)
+++ trunk/src/wsock32/vsemaphore.h	(revision 8903)
@@ -0,0 +1,37 @@
+/* $Id: vsemaphore.h,v 1.1 2002-07-22 09:53:48 sandervl Exp $ */
+
+/*
+ *
+ * Project Odin Software License can be found in LICENSE.TXT
+ *
+ */
+#ifndef __VSEMAPHORE_H__
+#define __VSEMAPHORE_H__
+
+#define VSEMAPHORE_RETURN_IMM	 	0
+#define VSEMAPHORE_WAIT_FOREVER		-1
+
+#define VSEMAPHORE_NONSHARED         	0
+#define VSEMAPHORE_SHARED		1
+
+#ifdef _OS2WIN_H
+#define HEV DWORD
+#endif
+
+class VSemaphore
+{
+public:
+	VSemaphore (int fShared = VSEMAPHORE_NONSHARED, HEV *phSem = NULL);
+       ~VSemaphore();
+
+public:
+	VOID wait(ULONG timeout = VSEMAPHORE_WAIT_FOREVER, HEV *phSem = NULL);
+	VOID post(HEV *phSem = NULL);
+	VOID reset(HEV *phSem = NULL);
+
+protected:
+	HEV  sem_handle;
+	BOOL fShared;
+};
+
+#endif //__VSEMAPHORE_H__
