Cosmetic changes, really

develop
Petr Mrázek 2010-03-12 12:14:20 +01:00
parent 9d503515dd
commit 0dd14bb9c8
3 changed files with 21 additions and 19 deletions

@ -215,6 +215,7 @@ void SHMProcess::Private::FreeLocks()
{ {
close(suspend_lock); close(suspend_lock);
locked = false; locked = false;
suspended = false;
suspend_lock = -1; suspend_lock = -1;
} }
} }
@ -327,8 +328,9 @@ SHMProcess::SHMProcess(uint32_t PID, vector< memory_info* >& known_versions)
} }
if(!bridgeOK) if(!bridgeOK)
{ {
detach();
throw Error::SHMVersionMismatch(); throw Error::SHMVersionMismatch();
detach();
return; return;
} }
@ -473,11 +475,13 @@ bool SHMProcess::suspend()
if(D_SHMCMD == CORE_RUN) if(D_SHMCMD == CORE_RUN)
{ {
//fprintf(stderr,"%d invokes step\n",d->attachmentIdx); //fprintf(stderr,"%d invokes step\n",d->attachmentIdx);
// wait for the next window
D_SHMCMD = CORE_STEP; D_SHMCMD = CORE_STEP;
} }
else else
{ {
//fprintf(stderr,"%d invokes suspend\n",d->attachmentIdx); //fprintf(stderr,"%d invokes suspend\n",d->attachmentIdx);
// lock now
D_SHMCMD = CORE_SUSPEND; D_SHMCMD = CORE_SUSPEND;
} }
//fprintf(stderr,"waiting for lock\n"); //fprintf(stderr,"waiting for lock\n");
@ -579,24 +583,22 @@ bool SHMProcess::attach()
/* /*
* Attach the segment * Attach the segment
*/ */
if ((d->shm_addr = (char *) shmat(d->shm_ID, NULL, 0)) != (char *) -1) if ((d->shm_addr = (char *) shmat(d->shm_ID, NULL, 0)) == (char *) -1)
{
d->FreeLocks();
cerr << "can't attach segment" << endl;
return false;
}
d->attached = true;
if(!suspend())
{ {
d->attached = true;
if(suspend())
{
d->suspended = true;
g_pProcess = this;
return true;
}
d->attached = false;
cerr << "unable to suspend" << endl;
shmdt(d->shm_addr); shmdt(d->shm_addr);
d->FreeLocks(); d->FreeLocks();
cerr << "unable to suspend" << endl;
return false; return false;
} }
cerr << "unable to attach" << endl; g_pProcess = this;
d->FreeLocks(); return true;
return false;
} }
bool SHMProcess::detach() bool SHMProcess::detach()

@ -51,7 +51,7 @@ bool useYield = 0;
int currentClient = -1; int currentClient = -1;
#define SHMHDR ((shm_core_hdr *)shm) #define SHMHDR ((shm_core_hdr *)shm)
#define SHMCMDPP ((shm_core_hdr *) shm)->cmd[currentClient].pingpong #define SHMCMD ((uint32_t *)shm )[currentClient]
#define SHMDATA(type) ((type *)(shm + SHM_HEADER)) #define SHMDATA(type) ((type *)(shm + SHM_HEADER))
void ReadRaw (void * data) void ReadRaw (void * data)
@ -264,7 +264,7 @@ void SHM_Act (void)
else else
{ {
full_barrier full_barrier
SHMCMDPP = CORE_RUNNING; SHMCMD = CORE_RUNNING;
fprintf(stderr,"dfhack: Broke out of loop, other process disappeared.\n"); fprintf(stderr,"dfhack: Broke out of loop, other process disappeared.\n");
} }
} }
@ -276,7 +276,7 @@ void SHM_Act (void)
// this is very important! copying two words separately from the command variable leads to inconsistency. // this is very important! copying two words separately from the command variable leads to inconsistency.
// Always copy the thing in one go. // Always copy the thing in one go.
// Also, this whole SHM thing probably only works on intel processors // Also, this whole SHM thing probably only works on intel processors
atomic = *(uint32_t *) (shm + 4*currentClient); //SHMHDR->cmd[currentClient]; atomic = SHMCMD;
full_barrier full_barrier
DFPP_module & mod = module_registry[ ((shm_cmd)atomic).parts.module ]; DFPP_module & mod = module_registry[ ((shm_cmd)atomic).parts.module ];
@ -303,7 +303,7 @@ void SHM_Act (void)
currentClient,((shm_cmd)atomic).parts.module,((shm_cmd)atomic).parts.command, cmd._function); currentClient,((shm_cmd)atomic).parts.module,((shm_cmd)atomic).parts.command, cmd._function);
fprintf(stderr, "%s\n",cmd.name.c_str()); fprintf(stderr, "%s\n",cmd.name.c_str());
// FIXME: WHAT HAPPENS WHEN A 'NEXTSTATE' IS FROM A DIFFERENT MODULE THAN 'CORE'? Yeah. It doesn't work. // FIXME: WHAT HAPPENS WHEN A 'NEXTSTATE' IS FROM A DIFFERENT MODULE THAN 'CORE'? Yeah. It doesn't work.
SHMCMDPP = cmd.nextState; SHMCMD = cmd.nextState;
fprintf(stderr, "Server set %d\n",cmd.nextState); fprintf(stderr, "Server set %d\n",cmd.nextState);
} }
full_barrier full_barrier

@ -196,7 +196,7 @@ void SHM_Init ( void )
// make sure we don't stall or do crazy stuff // make sure we don't stall or do crazy stuff
for(int i = 0; i < SHM_MAX_CLIENTS;i++) for(int i = 0; i < SHM_MAX_CLIENTS;i++)
{ {
((shm_cmd *)shm)[i].pingpong = CORE_RUNNING; ((uint32_t *)shm)[i] = CORE_RUNNING;
} }
InitModules(); InitModules();
} }