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()
{
int status;
if(g_pProcess != NULL)
if(g_pProcess != 0)
{
cerr << "there's already a different process attached" << endl;
return false;
@ -412,6 +412,7 @@ bool SHMProcess::attach()
}
d->attached = false;
cerr << "unable to suspend" << endl;
// FIXME: detach sehment here
return false;
}
cerr << "unable to attach" << endl;
@ -428,9 +429,17 @@ bool SHMProcess::detach()
{
resume();
}
d->attached = false;
d->suspended = false;
return true;
// detach segment
if(shmdt(d->my_shm) != -1)
{
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++)
{
DF.Suspend();
if(i%10000 == 0)
cout << i / 10000 << "%" << endl;
if(i%10000 == 0)
cout << i / 10000 << "%" << endl;
DF.Resume();
}
time(&end);