semmutex-r0drv-linux.c revision 30c84c361575629a712f338b514d9db7a8c681f4
/* $Id$ */
/** @file
* IPRT - Mutex Semaphores, Ring-0 Driver, Linux.
*/
/*
* Copyright (C) 2006-2007 Sun Microsystems, Inc.
*
* 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.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include "the-linux-kernel.h"
#include <iprt/semaphore.h>
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
/**
* Linux mutex semaphore.
*/
typedef struct RTSEMMUTEXINTERNAL
{
/** Magic value (RTSEMMUTEX_MAGIC). */
/** Number of recursive locks - 0 if not owned by anyone, > 0 if owned. */
uint32_t volatile cRecursion;
/** The wait queue. */
/** The current owner. */
void * volatile pOwner;
{
if (pMutexInt)
{
AssertReleaseMsgFailed(("This mutex implementation is buggy, fix it!\n"));
return VINF_SUCCESS;
}
return VERR_NO_MEMORY;
}
{
/*
* Validate input.
*/
if (!pMutexInt)
return VERR_INVALID_PARAMETER;
{
return VERR_INVALID_PARAMETER;
}
/*
* Invalidate it and signal the object just in case.
*/
return VINF_SUCCESS;
}
{
/*
* Validate input.
*/
if (!pMutexInt)
return VERR_INVALID_PARAMETER;
if ( !pMutexInt
{
AssertMsgFailed(("pMutexInt->u32Magic=%RX32 pMutexInt=%p\n", pMutexInt ? pMutexInt->u32Magic : 0, pMutexInt));
return VERR_INVALID_PARAMETER;
}
/*
* Check for recursive request.
*/
{
return VINF_SUCCESS;
}
/*
* Try aquire it.
*/
{
return VINF_SUCCESS;
}
else
{
/*
* Ok wait for it.
*/
int rc = VINF_SUCCESS;
for (;;)
{
/* make everything thru schedule() atomic scheduling wise. */
/* check the condition. */
{
break;
}
/* check for pending signals. */
if (signal_pending(current))
{
rc = VERR_INTERRUPTED; /** @todo VERR_INTERRUPTED isn't correct anylonger. please fix r0drv stuff! */
break;
}
/* wait */
after_wait(&Wait);
/* Check if someone destroyed the semaphore while we was waiting. */
{
break;
}
/* check for timeout. */
if (!lTimeout)
{
rc = VERR_TIMEOUT;
break;
}
}
return rc;
}
return VINF_SUCCESS;
}
{
/*
* Validate input.
*/
if (!pMutexInt)
return VERR_INVALID_PARAMETER;
if ( !pMutexInt
{
AssertMsgFailed(("pMutexInt->u32Magic=%RX32 pMutexInt=%p\n", pMutexInt ? pMutexInt->u32Magic : 0, pMutexInt));
return VERR_INVALID_PARAMETER;
}
{
return VERR_NOT_OWNER;
}
/*
* Release the mutex.
*/
{
}
else
return VINF_SUCCESS;
}