fix attach/detach

develop
Petr Mrázek 2010-01-01 22:19:09 +00:00
parent 037d1369cb
commit 84c68fb31c
2 changed files with 15 additions and 6 deletions

@ -393,7 +393,7 @@ bool SHMProcess::resume()
bool SHMProcess::attach() bool SHMProcess::attach()
{ {
int status; int status;
if(g_pProcess != NULL) if(g_pProcess != 0)
{ {
cerr << "there's already a different process attached" << endl; cerr << "there's already a different process attached" << endl;
return false; return false;
@ -412,6 +412,7 @@ bool SHMProcess::attach()
} }
d->attached = false; d->attached = false;
cerr << "unable to suspend" << endl; cerr << "unable to suspend" << endl;
// FIXME: detach sehment here
return false; return false;
} }
cerr << "unable to attach" << endl; cerr << "unable to attach" << endl;
@ -428,9 +429,17 @@ bool SHMProcess::detach()
{ {
resume(); resume();
} }
d->attached = false; // detach segment
d->suspended = false; if(shmdt(d->my_shm) != -1)
return true; {
d->attached = false;
d->suspended = false;
g_pProcess = 0;
return true;
}
// fail if we can't detach
perror("failed to detach shared segment");
return false;
} }

@ -68,8 +68,8 @@ int main (void)
for (int i = 0; i < 1000000; i++) for (int i = 0; i < 1000000; i++)
{ {
DF.Suspend(); DF.Suspend();
if(i%10000 == 0) if(i%10000 == 0)
cout << i / 10000 << "%" << endl; cout << i / 10000 << "%" << endl;
DF.Resume(); DF.Resume();
} }
time(&end); time(&end);