1
0
forked from 0ad/0ad

unbreak lockfree test, add sanity checks and timer init

lockfree: avoid potential race condition and add bounds check
whrt: sanity check
test_lockfree: fix by adding call to init/shutdown lockfree
timer: add proper init/shutdown
GameSetup: call lockfree and timer init/shutdown

This was SVN commit r5096.
This commit is contained in:
janwas 2007-05-26 17:56:38 +00:00
parent 349d9b9afe
commit 4582c8f276
6 changed files with 57 additions and 4 deletions

View File

@ -245,7 +245,7 @@ static void smr_release_unreferenced_nodes(TLS* tls)
return;
// required for head/tail below; guaranteed by callers.
debug_assert(tls->num_retired_nodes != 0);
debug_assert(0 < tls->num_retired_nodes && tls->num_retired_nodes <= MAX_RETIRED);
//
// build array of all active (non-NULL) hazard pointers (more efficient
@ -313,8 +313,9 @@ static void smr_retire_node(Node* node)
// if this triggers, tls_alloc called from lfl_init failed due to
// lack of memory and the caller didn't check its return value.
debug_assert(tls->num_retired_nodes < MAX_RETIRED);
tls->retired_nodes[tls->num_retired_nodes++] = node;
if(tls->num_retired_nodes >= MAX_RETIRED)
if(tls->num_retired_nodes >= MAX_RETIRED/2)
smr_release_unreferenced_nodes(tls);
}

View File

@ -119,6 +119,7 @@ static TickSource* CreateNextBestTickSource()
{
TickSource* tickSource = CreateTickSource(id);
debug_printf("HRT/ create id=%d name=%s freq=%f\n", id, tickSource->Name(), tickSource->NominalFrequency());
debug_assert(tickSources[id] == 0);
tickSources[id] = tickSource;
return tickSource;
}

View File

@ -9,10 +9,19 @@
class TestLockfreeBasic : public CxxTest::TestSuite
{
public:
void setUp()
{
lockfree_Init();
}
void tearDown()
{
lockfree_Shutdown();
}
void test_basic_single_threaded()
{
void* user_data;
const uint ENTRIES = 50;
// should be more than max # retired nodes to test release..() code
uintptr_t key = 0x1000;
@ -59,6 +68,16 @@ public:
// known to fail on P4 due to mem reordering and lack of membars.
class TestMultithread : public CxxTest::TestSuite
{
void setUp()
{
lockfree_Init();
}
void tearDown()
{
lockfree_Shutdown();
}
// poor man's synchronization "barrier"
bool is_complete;
intptr_t num_active_threads;

View File

@ -18,6 +18,7 @@
#include "lib/posix/posix_time.h"
#include "adts.h"
#include "module_init.h"
#include "lib/sysdep/cpu.h"
#if OS_WIN
#include "lib/sysdep/win/whrt/whrt.h"
@ -38,7 +39,7 @@ static struct timespec start;
static struct timeval start;
#endif
void timer_Init()
static void LatchStartTime()
{
#if HAVE_CLOCK_GETTIME
(void)clock_gettime(CLOCK_REALTIME, &start);
@ -337,3 +338,24 @@ TimerRdtsc::unit TimerRdtsc::get_timestamp() const
}
#endif
//-----------------------------------------------------------------------------
static ModuleInitState initState;
void timer_Init()
{
if(!ModuleShouldInitialize(&initState))
return;
LatchStartTime();
}
void timer_Shutdown()
{
if(!ModuleShouldShutdown(&initState))
return;
// nothing to do
}

View File

@ -17,6 +17,9 @@
#include "debug.h" // debug_printf
extern void timer_Init();
extern void timer_Shutdown();
// high resolution (> 1 us) timestamp [s], starting at or near 0 s.
extern double get_time(void);

View File

@ -4,6 +4,7 @@
#include "lib/ogl.h"
#include "lib/timer.h"
#include "lib/input.h"
#include "lib/lockfree.h"
#include "lib/app_hooks.h"
#include "lib/sysdep/cpu.h"
#include "lib/sysdep/gfx.h"
@ -869,6 +870,9 @@ void Shutdown(uint flags)
SAFE_DELETE(g_Logger);
delete &g_Profiler;
delete &g_ProfileViewer;
timer_Shutdown();
lockfree_Shutdown();
TIMER_END("shutdown misc");
}
@ -883,6 +887,9 @@ void Init(const CmdLineArgs& args, uint flags)
// add all debug_printf "tags" that we are interested in:
debug_filter_add("TIMER");
lockfree_Init();
timer_Init();
// Query CPU capabilities, possibly set some CPU-dependent flags
cpu_Init();