5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync/* $Id$ */
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync/** @file
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync * IPRT - RTSemMutexRequestDebug, generic RTSemMutexRequestNoResumeDebug wrapper.
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync */
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync/*
c58f1213e628a545081c70e26c6b67a841cff880vboxsync * Copyright (C) 2006-2010 Oracle Corporation
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync *
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync * available from http://www.virtualbox.org. This file is free software;
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync * you can redistribute it and/or modify it under the terms of the GNU
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync * General Public License (GPL) as published by the Free Software
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync *
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync * The contents of this file may alternatively be used under the terms
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync * of the Common Development and Distribution License Version 1.0
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync * VirtualBox OSE distribution, in which case the provisions of the
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync * CDDL are applicable instead of those of the GPL.
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync *
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync * You may elect to license modified versions of this file under the
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync * terms and conditions of either the GPL or the CDDL or both.
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync */
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync/*******************************************************************************
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync* Header Files *
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync*******************************************************************************/
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync#define LOG_GROUP RTLOGGROUP_SEM
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync#include <iprt/semaphore.h>
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync#include "internal/iprt.h"
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync#include <iprt/time.h>
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync#include <iprt/err.h>
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync#include <iprt/assert.h>
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync
b79e4344bf4eb8033fd06d560cd864192728bd0bvboxsyncRTDECL(int) RTSemMutexRequestDebug(RTSEMMUTEX Mutex, RTMSINTERVAL cMillies, RTHCUINTPTR uId, RT_SRC_POS_DECL)
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync{
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync int rc;
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync if (cMillies == RT_INDEFINITE_WAIT)
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync {
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync do rc = RTSemMutexRequestNoResumeDebug(Mutex, cMillies, uId, RT_SRC_POS_ARGS);
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync while (rc == VERR_INTERRUPTED);
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync }
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync else
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync {
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync const uint64_t u64Start = RTTimeMilliTS();
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync rc = RTSemMutexRequestNoResumeDebug(Mutex, cMillies, uId, RT_SRC_POS_ARGS);
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync if (rc == VERR_INTERRUPTED)
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync {
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync do
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync {
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync uint64_t u64Elapsed = RTTimeMilliTS() - u64Start;
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync if (u64Elapsed >= cMillies)
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync return VERR_TIMEOUT;
b79e4344bf4eb8033fd06d560cd864192728bd0bvboxsync rc = RTSemMutexRequestNoResumeDebug(Mutex, cMillies - (RTMSINTERVAL)u64Elapsed, uId, RT_SRC_POS_ARGS);
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync } while (rc == VERR_INTERRUPTED);
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync }
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync }
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync return rc;
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync}
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsyncRT_EXPORT_SYMBOL(RTSemMutexRequestDebug);
5964f60ed7fb52a3c4becbe83c9429f9b2f119c2vboxsync