semevent-posix.cpp revision 0fcf82b2591711fa8980e8f5d9cad1b8f222d6d7
897afdda769ec9fd3dbe35b57a3a041cfde0d6a7vboxsync * IPRT - Event Semaphore, POSIX.
897afdda769ec9fd3dbe35b57a3a041cfde0d6a7vboxsync * Copyright (C) 2006-2010 Sun Microsystems, Inc.
897afdda769ec9fd3dbe35b57a3a041cfde0d6a7vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
897afdda769ec9fd3dbe35b57a3a041cfde0d6a7vboxsync * available from http://www.virtualbox.org. This file is free software;
897afdda769ec9fd3dbe35b57a3a041cfde0d6a7vboxsync * you can redistribute it and/or modify it under the terms of the GNU
897afdda769ec9fd3dbe35b57a3a041cfde0d6a7vboxsync * General Public License (GPL) as published by the Free Software
897afdda769ec9fd3dbe35b57a3a041cfde0d6a7vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
897afdda769ec9fd3dbe35b57a3a041cfde0d6a7vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
897afdda769ec9fd3dbe35b57a3a041cfde0d6a7vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
897afdda769ec9fd3dbe35b57a3a041cfde0d6a7vboxsync * The contents of this file may alternatively be used under the terms
897afdda769ec9fd3dbe35b57a3a041cfde0d6a7vboxsync * of the Common Development and Distribution License Version 1.0
897afdda769ec9fd3dbe35b57a3a041cfde0d6a7vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
897afdda769ec9fd3dbe35b57a3a041cfde0d6a7vboxsync * VirtualBox OSE distribution, in which case the provisions of the
897afdda769ec9fd3dbe35b57a3a041cfde0d6a7vboxsync * CDDL are applicable instead of those of the GPL.
897afdda769ec9fd3dbe35b57a3a041cfde0d6a7vboxsync * You may elect to license modified versions of this file under the
897afdda769ec9fd3dbe35b57a3a041cfde0d6a7vboxsync * terms and conditions of either the GPL or the CDDL or both.
897afdda769ec9fd3dbe35b57a3a041cfde0d6a7vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
897afdda769ec9fd3dbe35b57a3a041cfde0d6a7vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
897afdda769ec9fd3dbe35b57a3a041cfde0d6a7vboxsync * additional information or have any questions.
897afdda769ec9fd3dbe35b57a3a041cfde0d6a7vboxsync/*******************************************************************************
897afdda769ec9fd3dbe35b57a3a041cfde0d6a7vboxsync* Header Files *
897afdda769ec9fd3dbe35b57a3a041cfde0d6a7vboxsync*******************************************************************************/
897afdda769ec9fd3dbe35b57a3a041cfde0d6a7vboxsync/*******************************************************************************
897afdda769ec9fd3dbe35b57a3a041cfde0d6a7vboxsync* Structures and Typedefs *
897afdda769ec9fd3dbe35b57a3a041cfde0d6a7vboxsync*******************************************************************************/
897afdda769ec9fd3dbe35b57a3a041cfde0d6a7vboxsync/** Internal representation of the POSIX implementation of an Event semaphore.
897afdda769ec9fd3dbe35b57a3a041cfde0d6a7vboxsync * The POSIX implementation uses a mutex and a condition variable to implement
897afdda769ec9fd3dbe35b57a3a041cfde0d6a7vboxsync * the automatic reset event semaphore semantics.
897afdda769ec9fd3dbe35b57a3a041cfde0d6a7vboxsync /** pthread condition. */
897afdda769ec9fd3dbe35b57a3a041cfde0d6a7vboxsync /** pthread mutex which protects the condition and the event state. */
897afdda769ec9fd3dbe35b57a3a041cfde0d6a7vboxsync /** The state of the semaphore.
897afdda769ec9fd3dbe35b57a3a041cfde0d6a7vboxsync * This is operated while owning mutex and using atomic updating. */
897afdda769ec9fd3dbe35b57a3a041cfde0d6a7vboxsync /** Number of waiters. */
897afdda769ec9fd3dbe35b57a3a041cfde0d6a7vboxsync /** Signallers. */
897afdda769ec9fd3dbe35b57a3a041cfde0d6a7vboxsync /** Indicates that lock validation should be performed. */
897afdda769ec9fd3dbe35b57a3a041cfde0d6a7vboxsync/** The valus of the u32State variable in a RTSEMEVENTINTERNAL.
897afdda769ec9fd3dbe35b57a3a041cfde0d6a7vboxsync/** The object isn't initialized. */
897afdda769ec9fd3dbe35b57a3a041cfde0d6a7vboxsync/** The semaphore is signaled. */
897afdda769ec9fd3dbe35b57a3a041cfde0d6a7vboxsync/** The semaphore is not signaled. */
897afdda769ec9fd3dbe35b57a3a041cfde0d6a7vboxsync * Allocate semaphore handle.
897afdda769ec9fd3dbe35b57a3a041cfde0d6a7vboxsync struct RTSEMEVENTINTERNAL *pThis = (struct RTSEMEVENTINTERNAL *)RTMemAlloc(sizeof(struct RTSEMEVENTINTERNAL));
897afdda769ec9fd3dbe35b57a3a041cfde0d6a7vboxsync * Create the condition variable.
897afdda769ec9fd3dbe35b57a3a041cfde0d6a7vboxsync * Create the semaphore.
if (!rc)
if (!rc)
#ifdef RTSEMEVENT_STRICT
return VINF_SUCCESS;
return rc;
return VERR_INVALID_HANDLE;
int rc;
if (rc)
if (rc)
#ifdef RTSEMEVENT_STRICT
return VINF_SUCCESS;
#ifdef RTSEMEVENT_STRICT
return rc9;
if (rc)
if (rc)
if (rc2)
return VINF_SUCCESS;
if (rc)
return VINF_SUCCESS;
return VERR_SEM_DESTROYED;
#ifdef RTSEMEVENT_STRICT
RTTHREADSTATE_EVENT, true);
return rc;
if (rc)
#ifdef RT_OS_DARWIN
if (cMillies != 0)
if (rc)
return VINF_SUCCESS;
return VERR_SEM_DESTROYED;
if (!cMillies)
return VERR_SEM_BUSY;
#ifdef RTSEMEVENT_STRICT
RTTHREADSTATE_EVENT, true);
return rc;
if (rc && (rc != EINTR || !fAutoResume)) /* according to SuS this function shall not return EINTR, but linux man page says differently. */
return rc;
#ifdef RTSEMEVENT_STRICT
#ifdef RTSEMEVENT_STRICT
#ifdef RTSEMEVENT_STRICT