sems-os2.cpp revision e64031e20c39650a7bc902a3e1aba613b9415dee
/* $Id$ */
/** @file
* IPRT - Semaphores, OS/2.
*/
/*
* Copyright (C) 2006-2007 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define INCL_DOSSEMAPHORES
#define INCL_ERRORS
#include <os2.h>
#include <iprt/semaphore.h>
/** Converts semaphore to OS/2 handle. */
{
}
RTDECL(int) RTSemEventCreateEx(PRTSEMEVENT phEventSem, uint32_t fFlags, RTLOCKVALCLASS hClass, const char *pszNameFmt, ...)
{
/*
* Create the semaphore.
* (Auto reset, not signaled, private event object.)
*/
if (!rc)
{
return VINF_SUCCESS;
}
return RTErrConvertFromOS2(rc);
}
{
if (hEventSem == NIL_RTSEMEVENT)
return VINF_SUCCESS;
/*
* Close semaphore handle.
*/
if (!rc)
return VINF_SUCCESS;
return RTErrConvertFromOS2(rc);
}
{
/*
* Wait for condition.
*/
int rc = DosWaitEventSem(SEM2HND(hEventSem), cMillies == RT_INDEFINITE_WAIT ? SEM_INDEFINITE_WAIT : cMillies);
switch (rc)
{
case NO_ERROR: return VINF_SUCCESS;
case ERROR_SEM_TIMEOUT:
case ERROR_TIMEOUT: return VERR_TIMEOUT;
case ERROR_INTERRUPT: return VERR_INTERRUPTED;
default:
{
return RTErrConvertFromOS2(rc);
}
}
}
{
/*
* Signal the object.
*/
switch (rc)
{
case NO_ERROR:
case ERROR_ALREADY_POSTED:
case ERROR_TOO_MANY_POSTS:
return VINF_SUCCESS;
default:
return RTErrConvertFromOS2(rc);
}
}
{
/** @todo implement RTSemEventSetSignaller and friends for OS/2 */
}
{
}
{
}
{
}
RTDECL(int) RTSemEventMultiCreateEx(PRTSEMEVENTMULTI phEventMultiSem, uint32_t fFlags, RTLOCKVALCLASS hClass,
const char *pszNameFmt, ...)
{
/*
* Create the semaphore.
* (Manual reset, not signaled, private event object.)
*/
if (!rc)
{
return VINF_SUCCESS;
}
return RTErrConvertFromOS2(rc);
}
{
if (hEventMultiSem == NIL_RTSEMEVENTMULTI)
return VINF_SUCCESS;
/*
* Close semaphore handle.
*/
if (!rc)
return VINF_SUCCESS;
return RTErrConvertFromOS2(rc);
}
{
/*
* Signal the object.
*/
switch (rc)
{
case NO_ERROR:
case ERROR_ALREADY_POSTED:
case ERROR_TOO_MANY_POSTS:
return VINF_SUCCESS;
default:
return RTErrConvertFromOS2(rc);
}
}
{
/*
* Reset the object.
*/
switch (rc)
{
case NO_ERROR:
case ERROR_ALREADY_RESET:
return VINF_SUCCESS;
default:
return RTErrConvertFromOS2(rc);
}
}
{
/*
* Wait for condition.
*/
int rc = DosWaitEventSem(SEM2HND(hEventMultiSem), cMillies == RT_INDEFINITE_WAIT ? SEM_INDEFINITE_WAIT : cMillies);
switch (rc)
{
case NO_ERROR: return VINF_SUCCESS;
case ERROR_SEM_TIMEOUT:
case ERROR_TIMEOUT: return VERR_TIMEOUT;
case ERROR_INTERRUPT: return VERR_INTERRUPTED;
default:
{
return RTErrConvertFromOS2(rc);
}
}
}
{
/** @todo implement RTSemEventMultiSetSignaller on OS/2 */
}
{
}
{
}
{
return RTSemMutexCreateEx(phMutexSem, 0 /*fFlags*/, NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_NONE, NULL);
}
{
/*
* Create the semaphore.
*/
if (!rc)
{
/** @todo implement lock validation of OS/2 mutex semaphores. */
return VINF_SUCCESS;
}
return RTErrConvertFromOS2(rc);
}
{
if (hMutexSem == NIL_RTSEMMUTEX)
return VINF_SUCCESS;
/*
* Close semaphore handle.
*/
if (!rc)
return VINF_SUCCESS;
return RTErrConvertFromOS2(rc);
}
{
#if 0 /** @todo def RTSEMMUTEX_STRICT */
/*
* Validate.
*/
#else
return RTLOCKVAL_SUB_CLASS_INVALID;
#endif
}
{
/*
* Lock mutex semaphore.
*/
int rc = DosRequestMutexSem(SEM2HND(hMutexSem), cMillies == RT_INDEFINITE_WAIT ? SEM_INDEFINITE_WAIT : cMillies);
switch (rc)
{
case NO_ERROR: return VINF_SUCCESS;
case ERROR_SEM_TIMEOUT:
case ERROR_TIMEOUT: return VERR_TIMEOUT;
case ERROR_INTERRUPT: return VERR_INTERRUPTED;
case ERROR_SEM_OWNER_DIED: return VERR_SEM_OWNER_DIED;
default:
{
return RTErrConvertFromOS2(rc);
}
}
}
{
/*
* Unlock mutex semaphore.
*/
if (!rc)
return VINF_SUCCESS;
return RTErrConvertFromOS2(rc);
}
{
/*
* Unlock mutex semaphore.
*/
if (!rc)
return cRecursions != 0;
return rc == ERROR_SEM_OWNER_DIED;
}