semevent-r0drv-os2.cpp revision 64eea8161bef2aa3c6516481383c830bca27abfe
/* $Id$ */
/** @file
* IPRT - Single Release Event Semaphores, Ring-0 Driver, OS/2.
*/
/*
* Copyright (c) 2007 knut st. osmundsen <bird-src-spam@anduin.net>
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include "the-os2-kernel.h"
#include <iprt/semaphore.h>
#include <iprt/lockvalidator.h>
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
/**
* OS/2 event semaphore.
*/
typedef struct RTSEMEVENTINTERNAL
{
/** Magic value (RTSEMEVENT_MAGIC). */
/** The number of waiting threads. */
/** Set if the event object is signaled. */
/** The number of threads in the process of waking up. */
/** The OS/2 spinlock protecting this structure. */
{
}
RTDECL(int) RTSemEventCreateEx(PRTSEMEVENT phEventSem, uint32_t fFlags, RTLOCKVALCLASS hClass, const char *pszNameFmt, ...)
{
AssertReturn(!(fFlags & ~(RTSEMEVENT_FLAGS_NO_LOCK_VAL | RTSEMEVENT_FLAGS_BOOTSTRAP_HACK)), VERR_INVALID_PARAMETER);
AssertCompile(sizeof(RTSEMEVENTINTERNAL) > sizeof(void *));
if (!pThis)
return VERR_NO_MEMORY;
*phEventSem = pThis;
return VINF_SUCCESS;
}
{
if (pThis == NIL_RTSEMEVENT)
return VINF_SUCCESS;
AssertMsgReturn(pThis->u32Magic == RTSEMEVENT_MAGIC, ("u32Magic=%RX32 pThis=%p\n", pThis->u32Magic, pThis), VERR_INVALID_HANDLE);
{
/* abort waiting thread, last man cleans up. */
}
/* the last waking thread is gonna do the cleanup */
else
{
}
return VINF_SUCCESS;
}
{
AssertMsgReturn(pThis->u32Magic == RTSEMEVENT_MAGIC, ("u32Magic=%RX32 pThis=%p\n", pThis->u32Magic, pThis), VERR_INVALID_HANDLE);
{
if (RT_UNLIKELY(!cThreads))
{
/* shouldn't ever happen on OS/2 */
}
}
else
return VINF_SUCCESS;
}
/**
* Worker for RTSemEventWaitEx and RTSemEventWaitExDebug.
*
* @returns VBox status code.
* @param pThis The event semaphore.
* @param fFlags See RTSemEventWaitEx.
* @param uTimeout See RTSemEventWaitEx.
* @param pSrcPos The source code position of the wait.
*/
{
/*
* Validate and convert input.
*/
if (!pThis)
return VERR_INVALID_HANDLE;
AssertMsgReturn(pThis->u32Magic == RTSEMEVENT_MAGIC, ("u32Magic=%RX32 pThis=%p\n", pThis->u32Magic, pThis), VERR_INVALID_HANDLE);
if (!(fFlags & RTSEMWAIT_FLAGS_INTERRUPTIBLE))
/*
* Do the job.
*/
int rc;
{
rc = VINF_SUCCESS;
}
else
{
&ulData);
switch (rc)
{
case NO_ERROR:
{
/* The event was destroyed (ulData == VINF_SUCCESS if it was after we awoke), as
the last thread do the cleanup. */
return rc;
}
break;
case ERROR_TIMEOUT:
rc = VERR_TIMEOUT;
break;
case ERROR_INTERRUPT:
break;
default:
break;
}
}
return rc;
}
{
#ifndef RTSEMEVENT_STRICT
#else
#endif
}
{
}
{
return 32000000; /* 32ms */
}