tstRTSemXRoads.cpp revision c7814cf6e1240a519cbec0441e033d0e2470ed00
/* $Id$ */
/** @file
* IPRT Testcase - RTSemXRoads.
*/
/*
* Copyright (C) 2009-2012 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>
#include <iprt/initterm.h>
/*******************************************************************************
* Global Variables *
*******************************************************************************/
static uint32_t volatile g_cNSCrossings;
static uint32_t volatile g_cEWCrossings;
static uint64_t g_u64StartMilliTS;
static RTSEMXROADS g_hXRoads;
{
{
/* fudge */
RTThreadSleep(1);
if (fNS)
{
}
else
{
}
}
return VINF_SUCCESS;
}
{
return tstTrafficThreadCommon(iThread, true);
}
{
return tstTrafficThreadCommon(iThread, false);
}
{
/*
* in a loop for 15 seconds with slight delays between some of the runs and
* then check the numbers.
*/
/* init */
for (unsigned i = 0; i < RT_ELEMENTS(ahThreadsX); i++)
ahThreadsX[i] = NIL_RTTHREAD;
for (unsigned i = 0; i < RT_ELEMENTS(ahThreadsY); i++)
ahThreadsY[i] = NIL_RTTHREAD;
g_cNSCrossings = 0;
g_cEWCrossings = 0;
/* create */
int rc = VINF_SUCCESS;
{
rc = RTThreadCreateF(&ahThreadsX[i], tstTrafficNSThread, (void *)(uintptr_t)i, 0, RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "NS-%u", i);
}
{
rc = RTThreadCreateF(&ahThreadsX[i], tstTrafficEWThread, (void *)(uintptr_t)i, 0, RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "NS-%u", i);
}
/* wait */
for (unsigned i = 0; i < RT_ELEMENTS(ahThreadsX); i++)
if (ahThreadsX[i] != NIL_RTTHREAD)
{
}
for (unsigned i = 0; i < RT_ELEMENTS(ahThreadsY); i++)
if (ahThreadsY[i] != NIL_RTTHREAD)
{
}
}
static bool tstBasics(void)
{
return true;
}
int main()
{
if (rc)
return rc;
if (tstBasics())
{
}
return RTTestSummaryAndDestroy(g_hTest);
}