diff --git a/examples/attachtest.cpp b/examples/attachtest.cpp index 018d32ef4..03ee928b4 100644 --- a/examples/attachtest.cpp +++ b/examples/attachtest.cpp @@ -16,17 +16,6 @@ int main (void) time_t start, end; double time_diff; DFHack::API DF("Memory.xml"); - //if(!DF.Attach()) - //{ - // cerr << "DF not found" << endl; - // return 1; - //} - //if(!DF.Detach()) - //{ - // cerr << "Can't detach from DF" << endl; - // return 1; - //} - try { DF.Attach(); @@ -77,11 +66,11 @@ int main (void) cout << "Testing suspend/resume" << endl; DF.Attach(); time(&start); - for (int i = 0; i < 1000000; i++) + for (int i = 0; i < 1000; i++) { DF.Suspend(); - if(i%10000 == 0) - cout << i / 10000 << "%" << endl; + if(i%10 == 0) + cout << i / 10 << "%" << endl; DF.Resume(); } time(&end); diff --git a/examples/expbench.cpp b/examples/expbench.cpp index 7f083e49b..ba2606749 100644 --- a/examples/expbench.cpp +++ b/examples/expbench.cpp @@ -29,15 +29,15 @@ int main (void) } time(&start); - for(uint32_t i = 0; i< 1000;i++) + for(uint32_t i = 0; i< 10000;i++) { if(!DF.InitMap()) break; DF.getSize(x_max,y_max,z_max); - if((i % 10) == 0) + if((i % 100) == 0) { - int percentage = i / 10; - cout << percentage << endl; + int percentage = i / 100; + cout << percentage << " %" << endl; } for(uint32_t x = 0; x< x_max;x++) { diff --git a/library/DFProcess-linux-SHM.cpp b/library/DFProcess-linux-SHM.cpp index e31ce062f..9bcda4ff2 100644 --- a/library/DFProcess-linux-SHM.cpp +++ b/library/DFProcess-linux-SHM.cpp @@ -30,6 +30,8 @@ distribution. #include "../shmserver/shms.h" #include #include +#include + using namespace DFHack; // a full memory barrier! better be safe than sorry. @@ -74,6 +76,7 @@ bool SHMProcess::Private::waitWhile (DF_PINGPONG state) { if(cnt == 10000) { + shmctl(my_shmid, IPC_STAT, &descriptor); if(descriptor.shm_nattch == 1)// DF crashed? { @@ -87,6 +90,7 @@ bool SHMProcess::Private::waitWhile (DF_PINGPONG state) cnt = 0; } } + SCHED_YIELD cnt++; } if(((shm_cmd *)my_shm)->pingpong == DFPP_SV_ERROR) @@ -254,10 +258,6 @@ SHMProcess::~SHMProcess() { delete d->my_window; } - if(d->my_shm) - { - fprintf(stderr,"detach: %d",shmdt(d->my_shm)); - } delete d; } @@ -411,6 +411,7 @@ bool SHMProcess::detach() { d->attached = false; d->suspended = false; + d->my_shm = 0; g_pProcess = 0; return true; } diff --git a/precompiled/linux/libdfconnect.so b/precompiled/linux/libdfconnect.so index 9d90a8d34..6db5d6d3b 100755 Binary files a/precompiled/linux/libdfconnect.so and b/precompiled/linux/libdfconnect.so differ diff --git a/shmserver/shms.h b/shmserver/shms.h index 6da1322cb..c23225971 100644 --- a/shmserver/shms.h +++ b/shmserver/shms.h @@ -12,7 +12,9 @@ #ifdef LINUX_BUILD // a full memory barrier! better be safe than sorry. #define full_barrier asm volatile("" ::: "memory"); __sync_synchronize(); - #define SCHED_YIELD + #define SCHED_YIELD sched_yield(); // slow but allows the SHM to work on single-core + // #define SCHED_YIELD usleep(0); // extremely slow + // #define SCHED_YIELD // works only on multi-core #else // we need windows.h for Sleep() #define _WIN32_WINNT 0x0501 // needed for INPUT struct