Converted comms system entirely to being bitflag-based instead of integer state based
This commit is contained in:
parent
6e316663fc
commit
974380ab30
10 changed files with 28 additions and 24 deletions
|
@ -16,7 +16,9 @@ namespace Comms{
|
|||
}
|
||||
|
||||
Comms::~Comms(){
|
||||
if (index != INVALID_RECORD_INDEX){setStatus(COMM_STATUS_DISCONNECT);}
|
||||
if (index != INVALID_RECORD_INDEX){
|
||||
setStatus(COMM_STATUS_DISCONNECT | getStatus());
|
||||
}
|
||||
if (master){
|
||||
if (dataPage.mapped){
|
||||
finishAll();
|
||||
|
@ -69,13 +71,13 @@ namespace Comms{
|
|||
do{
|
||||
keepGoing = false;
|
||||
for (size_t i = 0; i < recordCount(); i++){
|
||||
if (getStatus(i) == COMM_STATUS_INVALID || getStatus(i) == COMM_STATUS_DISCONNECT){continue;}
|
||||
if (getStatus(i) == COMM_STATUS_INVALID || (getStatus(i) & COMM_STATUS_DISCONNECT)){continue;}
|
||||
uint64_t cPid = getPid(i);
|
||||
if (cPid > 1){
|
||||
Util::Procs::Stop(cPid); // soft kill
|
||||
keepGoing = true;
|
||||
}
|
||||
setStatus(COMM_STATUS_REQDISCONNECT, i);
|
||||
setStatus(COMM_STATUS_REQDISCONNECT | getStatus(i), i);
|
||||
}
|
||||
if (keepGoing){Util::sleep(250);}
|
||||
}while (keepGoing && ++c < 8);
|
||||
|
@ -83,7 +85,7 @@ namespace Comms{
|
|||
|
||||
Comms::operator bool() const{
|
||||
if (master){return dataPage;}
|
||||
return dataPage && (getStatus() != COMM_STATUS_INVALID) && (getStatus() != COMM_STATUS_DISCONNECT);
|
||||
return dataPage && (getStatus() != COMM_STATUS_INVALID) && !(getStatus() & COMM_STATUS_DISCONNECT);
|
||||
}
|
||||
|
||||
void Comms::setMaster(bool _master){
|
||||
|
@ -142,7 +144,9 @@ namespace Comms{
|
|||
Statistics::Statistics() : Comms(){sem.open(SEM_STATISTICS, O_CREAT | O_RDWR, ACCESSPERMS, 1);}
|
||||
|
||||
void Statistics::unload(){
|
||||
if (index != INVALID_RECORD_INDEX){setStatus(COMM_STATUS_DISCONNECT);}
|
||||
if (index != INVALID_RECORD_INDEX){
|
||||
setStatus(COMM_STATUS_DISCONNECT | getStatus());
|
||||
}
|
||||
index = INVALID_RECORD_INDEX;
|
||||
}
|
||||
|
||||
|
|
12
lib/comms.h
12
lib/comms.h
|
@ -3,12 +3,12 @@
|
|||
#include "shared_memory.h"
|
||||
#include "util.h"
|
||||
|
||||
#define COMM_STATUS_DONOTTRACK 0x40
|
||||
#define COMM_STATUS_SOURCE 0x80
|
||||
#define COMM_STATUS_REQDISCONNECT 0xFD
|
||||
#define COMM_STATUS_DISCONNECT 0xFE
|
||||
#define COMM_STATUS_INVALID 0x0
|
||||
#define COMM_STATUS_DONOTTRACK 0x40
|
||||
#define COMM_STATUS_DISCONNECT 0x20
|
||||
#define COMM_STATUS_REQDISCONNECT 0x10
|
||||
#define COMM_STATUS_ACTIVE 0x1
|
||||
#define COMM_STATUS_INVALID 0x0
|
||||
|
||||
|
||||
#define COMM_LOOP(comm, onActive, onDisconnect) \
|
||||
|
@ -16,10 +16,10 @@
|
|||
for (size_t id = 0; id < comm.recordCount(); id++){\
|
||||
if (comm.getStatus(id) == COMM_STATUS_INVALID){continue;}\
|
||||
if (!Util::Procs::isRunning(comm.getPid(id))){\
|
||||
comm.setStatus(COMM_STATUS_DISCONNECT, id);\
|
||||
comm.setStatus(COMM_STATUS_DISCONNECT | comm.getStatus(id), id);\
|
||||
}\
|
||||
onActive;\
|
||||
if (comm.getStatus(id) == COMM_STATUS_DISCONNECT){\
|
||||
if (comm.getStatus(id) & COMM_STATUS_DISCONNECT){\
|
||||
onDisconnect;\
|
||||
comm.setStatus(COMM_STATUS_INVALID, id);\
|
||||
}\
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue