develop
Petr Mrázek 2010-01-11 18:57:57 +00:00
parent 7c784bce32
commit 9f1216fa2f
5 changed files with 30 additions and 9 deletions

@ -92,6 +92,7 @@ bool SHMProcess::Private::isValidSV()
bool SHMProcess::Private::waitWhile (DF_PINGPONG state)
{
uint32_t cnt = 0;
SCHED_YIELD // yield the CPU, valid only on single-core CPUs
while (((shm_cmd *)my_shm)->pingpong == state)
{
if(cnt == 10000)

@ -46,6 +46,7 @@ void SHM_Act (void)
uint32_t length;
uint32_t address;
check_again: // goto target!!!
SCHED_YIELD // yield the CPU, valid only on single-core CPUs
if(numwaits == 10000)
{
// this tests if there's a process on the other side
@ -58,6 +59,7 @@ void SHM_Act (void)
full_barrier
((shm_cmd *)shm)->pingpong = DFPP_RUNNING;
fprintf(stderr,"dfhack: Broke out of loop, other process disappeared.\n");
//MessageBox(0,"Broke out of loop, other process disappeared.","FUN", MB_OK);
}
}
switch (((shm_cmd *)shm)->pingpong)
@ -154,6 +156,7 @@ void SHM_Act (void)
case DFPP_CL_ERROR:
case DFPP_RUNNING:
fprintf(stderr, "no. of waits: %d\n", numwaits);
//MessageBox(0,"Broke out of loop properly","FUN", MB_OK);
break;
default:

@ -642,8 +642,11 @@ extern "C" void SDL_Quit(void)
static void (*_SDL_GL_SwapBuffers)(void) = 0;
extern "C" void SDL_GL_SwapBuffers(void)
{
if(!errorstate && ((shm_cmd *)shm)->pingpong != DFPP_RUNNING)
{
SHM_Act();
}
_SDL_GL_SwapBuffers();
}

@ -8,12 +8,26 @@
#define SHM_SIZE SHM_HEADER+SHM_BODY
// FIXME: add YIELD for linux, add single-core and multi-core compile targets for optimal speed
#ifdef LINUX_BUILD
// a full memory barrier! better be safe than sorry.
#define full_barrier asm volatile("" ::: "memory"); __sync_synchronize();
#define SCHED_YIELD
#else
// we need windows.h for Sleep()
#define _WIN32_WINNT 0x0501 // needed for INPUT struct
#define WINVER 0x0501 // OpenThread(), PSAPI, Toolhelp32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#define SCHED_YIELD Sleep(0);
// FIXME: detect MSVC here and use the right barrier magic
#define full_barrier
#ifdef __MINGW32__
#define full_barrier asm volatile("" ::: "memory");
#else
#include <intrin.h>
#pragma intrinsic(_ReadWriteBarrier)
#define full_barrier _ReadWriteBarrier();
#endif
#endif
@ -82,12 +96,12 @@ enum DF_ERROR
typedef struct
{
uint32_t pingpong; // = 0
volatile uint32_t pingpong; // = 0
} shm_cmd;
typedef struct
{
uint32_t pingpong;
volatile uint32_t pingpong;
uint32_t address;
uint32_t length;
} shm_read;
@ -97,25 +111,25 @@ typedef shm_read shm_bounce;
typedef struct
{
uint32_t pingpong;
volatile uint32_t pingpong;
} shm_ret_data;
typedef struct
{
uint32_t pingpong;
volatile uint32_t pingpong;
uint32_t address;
} shm_read_small;
typedef struct
{
uint32_t pingpong;
volatile uint32_t pingpong;
uint32_t address;
uint32_t value;
} shm_write_small;
typedef struct
{
uint32_t pingpong;
volatile uint32_t pingpong;
uint32_t value;
} shm_retval;