Skip to content

Commit

Permalink
fix to destructor and slowcontrol mutexs
Browse files Browse the repository at this point in the history
  • Loading branch information
brichards64 committed Jul 3, 2024
1 parent 9400ac8 commit 87fcc02
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 28 deletions.
28 changes: 18 additions & 10 deletions src/DAQDataModelBase/SlowControlCollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,43 +44,49 @@ SlowControlCollection::~SlowControlCollection(){
}

void SlowControlCollection::Stop(){

if(m_thread) m_util->KillThread(args);
//printf("p0\n");
std::cout<<args<<std::endl;
//printf("p1 %p \n",args);
if(m_thread && args) m_util->KillThread(args);
m_thread=false;

//printf("p2\n");
delete args;
args=0;

//printf("p3\n");
delete m_pub;
m_pub=0;

//printf("p4\n");
if(m_new_service) m_util->RemoveService("SlowControlReceiver");

m_new_service=false;
//printf("p5\n");
delete m_util;
m_util=0;

//printf("p6\n");
Clear();

//printf("p7\n");
}

bool SlowControlCollection::Init(zmq::context_t* context, int port, bool new_service){

if(args) return false;

//printf("Init\n");
m_context=context;

m_util=new DAQUtilities(m_context);
m_new_service=new_service;

m_pub= new zmq::socket_t(*(m_context), ZMQ_PUB);
m_pub->setsockopt(ZMQ_LINGER, 0);
m_pub->bind("tcp://*:78787");

args=new SlowControlCollectionThread_args();
//printf("init p=%p\n", args);

args->alert_functions=&m_alert_functions;
args->alert_functions_mutex=&m_alert_functions_mutex;

args->sock = new zmq::socket_t(*(m_context), ZMQ_ROUTER);
args->sock->setsockopt(ZMQ_LINGER, 0);

std::stringstream tmp;
tmp<<"tcp://*:"<<port;
Expand All @@ -89,6 +95,7 @@ bool SlowControlCollection::Init(zmq::context_t* context, int port, bool new_ser

args->sub = new zmq::socket_t(*(m_context), ZMQ_SUB);
args->sub->setsockopt(ZMQ_SUBSCRIBE, "", 0);
args->sub->setsockopt(ZMQ_LINGER, 0);
args->sub->bind("tcp://*:78788");


Expand Down Expand Up @@ -135,6 +142,7 @@ bool SlowControlCollection::ListenForData(int poll_length){
bool SlowControlCollection::InitThreadedReceiver(zmq::context_t* context, int port, int poll_length, bool new_service){

if(args) return false;
//printf("InitThreadedReceiver\n");
m_thread=true;

//std::cout<<"new_service="<<new_service<<std::endl;
Expand Down Expand Up @@ -176,7 +184,7 @@ void SlowControlCollection::Thread(Thread_args* arg){
// std::stringstream tmpstream(str);
// tmpstream>>str;

tmp.Print();
//tmp.Print();
//printf("key=%s\n",key.c_str());

std::string reply="error: " + key;
Expand Down
5 changes: 0 additions & 5 deletions src/DAQDataModelBase/SlowControlElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ std::string SlowControlElement::Print(){

bool SlowControlElement::JsonParser(std::string json){

mtx.lock();
Store tmp;
tmp.JsonParser(json);
//m_name=tmp.Get<std::string>("name");
Expand Down Expand Up @@ -148,11 +147,9 @@ bool SlowControlElement::JsonParser(std::string json){
SetValue(tmp.Get<std::string>("value"));
}
else{
mtx.unlock();
return false;
}

mtx.unlock();
return true;
}

Expand Down Expand Up @@ -207,9 +204,7 @@ bool SlowControlElement::SetDefault(std::string value){
bool SlowControlElement::SetValue(const char value[]){
bool ret=false;
std::string tmp_value=value;
mtx.lock();
ret=SetValue(tmp_value);
mtx.unlock();
return ret;
}

Expand Down
38 changes: 25 additions & 13 deletions src/ToolDAQChain/ToolDAQChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,38 +312,50 @@ ToolDAQChain::~ToolDAQChain(){
m_tools.clear();
printf("yakka3\n");
*/

m_DAQdata->SC_vars.Stop();

delete m_log;
m_log=0;

// printf("%s \n","tdebug 3");

delete SD;
//printf("%s \n","tdebug 4");
SD=0;
//printf("%s \n","tdebug 5");

//printf("%s \n","tdebug 6");
delete context;
//printf("%s \n","tdebug 7");
context=0;

//printf("%s \n","tdebug 8");

/*
if(m_data!=0 && m_data->Log==m_log){
m_data->Log=0;
delete m_data;
m_data=0;
}

*/
delete m_DAQdata;
m_DAQdata=0;

/*
delete m_log;
m_log=0;
*/

// printf("%s \n","tdebug 1");
// delete m_data->Log; // change this to m_log
//printf("%s \n","tdebug 2");
//m_data->Log=0;
//printf("%s \n","tdebug 3");

delete SD;
//printf("%s \n","tdebug 4");
SD=0;
//printf("%s \n","tdebug 5");
//sleep(30);
//printf("%s \n","tdebug 6");
// context->close();
//printf("%s \n","tdebug 6.5");

delete context;
// printf("%s \n","tdebug 7");
context=0;

//printf("%s \n","tdebug 8");

// if(m_log_mode!="Off"){
//std::cout.rdbuf(bcout);
//printf("%s \n","tdebug 9");
Expand Down

0 comments on commit 87fcc02

Please sign in to comment.