semmutex-r0drv-linux.c revision a8e0cb7ddfd05bcabf5e18959cf09e723f254663
/* $Id$ */
/** @file
* innotek Portable Runtime - Mutex Semaphores, Ring-0 Driver, Linux.
*/
/*
* Copyright (C) 2006-2007 innotek GmbH
*
* 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 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.
*/
/*******************************************************************************
* 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 */
/* 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;
}