semspingpong.cpp revision e64031e20c39650a7bc902a3e1aba613b9415dee
/* $Id$ */
/** @file
* IPRT - Thread Ping-Pong Construct.
*/
/*
* 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 *
*******************************************************************************/
#include <iprt/semaphore.h>
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
/**
* Validation macro returns if invalid parameter.
*
* Expects a enmSpeaker variable to be handy and will set it to the current
* enmSpeaker value.
*/
#define RTSEMPP_VALIDATE_RETURN(pPP) \
do { \
|| enmSpeaker == RTPINGPONGSPEAKER_PONG \
("enmSpeaker=%d\n", enmSpeaker), \
} while (0)
/**
* Init a Ping-Pong construct.
*
* @returns iprt status code.
* @param pPP Pointer to the ping-pong structure which needs initialization.
*/
{
/*
* Init the structure.
*/
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
return VINF_SUCCESS;
}
return rc;
}
/**
* Destroys a Ping-Pong construct.
*
* @returns iprt status code.
* @param pPP Pointer to the ping-pong structure which is to be destroyed.
* (I.e. put into uninitialized state.)
*/
{
/*
* Validate input
*/
if (!pPP)
return VINF_SUCCESS;
/*
* Invalidate the ping pong handle and destroy the event semaphores.
*/
return VINF_SUCCESS;
}
/**
* Signals the pong thread in a ping-pong construct. (I.e. sends ping.)
* This is called by the ping thread.
*
* @returns iprt status code.
* @param pPP Pointer to the ping-pong structure to ping.
*/
{
/*
* Validate input
*/
AssertMsgReturn(enmSpeaker == RTPINGPONGSPEAKER_PING,("Speaking out of turn! enmSpeaker=%d\n", enmSpeaker),
/*
* Signal the other thread.
*/
if (RT_SUCCESS(rc))
return rc;
/* restore the state. */
return rc;
}
/**
* Signals the ping thread in a ping-pong construct. (I.e. sends pong.)
* This is called by the pong thread.
*
* @returns iprt status code.
* @param pPP Pointer to the ping-pong structure to pong.
*/
{
/*
* Validate input
*/
AssertMsgReturn(enmSpeaker == RTPINGPONGSPEAKER_PONG,("Speaking out of turn! enmSpeaker=%d\n", enmSpeaker),
/*
* Signal the other thread.
*/
if (RT_SUCCESS(rc))
return rc;
/* restore the state. */
return rc;
}
/**
* Wait function for the ping thread.
*
* @returns iprt status code.
* Will not return VERR_INTERRUPTED.
* @param pPP Pointer to the ping-pong structure to wait on.
* @param cMillies Number of milliseconds to wait.
*/
{
/*
* Validate input
*/
("Speaking out of turn! enmSpeaker=%d\n", enmSpeaker),
/*
* Wait.
*/
if (RT_SUCCESS(rc))
return rc;
}
/**
* Wait function for the pong thread.
*
* @returns iprt status code.
* Will not return VERR_INTERRUPTED.
* @param pPP Pointer to the ping-pong structure to wait on.
* @param cMillies Number of milliseconds to wait.
*/
{
/*
* Validate input
*/
("Speaking out of turn! enmSpeaker=%d\n", enmSpeaker),
/*
* Wait.
*/
if (RT_SUCCESS(rc))
return rc;
}