Commit 698b3c07 authored by aorlati's avatar aorlati Committed by Giuseppe Carboni
Browse files

fix issue #255: found a flow in memory managment in the timer callback...

fix issue #255: found a flow in memory managment in the timer callback function. Issue fixed, but it should be confirmed that was also the cause of the problme described in this issue. Got rid of some compilation warnings (#260)
parent 3a9384ae
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ CScheduleTimer::~CScheduleTimer()
		delete m_timerQueue;
	}
	for(i=m_events.begin();i<m_events.end();i++) {
		if ((*i)->cleanupFunction) (*i)->cleanupFunction((*i)->parameter);
		delete (*i)->handler;
		delete (*i);
	}
@@ -71,6 +72,7 @@ bool CScheduleTimer::cancel(const ACS::Time& time)
	for(i=m_events.begin();i<m_events.end();i++) {
		if ((*i)->time==time) { 
			if (m_timerQueue->cancel((*i)->id)!=0) { //remove the event from the queue
				if ((*i)->cleanupFunction) (*i)->cleanupFunction((*i)->parameter);
				delete (*i)->handler;
				delete (*i);
				m_events.erase(i);
@@ -92,6 +94,8 @@ bool CScheduleTimer::cancel(const unsigned& pos)
	}
	id=m_events[pos]->id;
	if (m_timerQueue->cancel(id)!=0) { //remove the event from the queue
		if ((m_events[pos])->cleanupFunction) (m_events[pos])->cleanupFunction(
		  (m_events[pos])->parameter);
		delete m_events[pos]->handler;
		delete m_events[pos];
		m_events.erase(m_events.begin()+pos);
@@ -112,8 +116,10 @@ bool CScheduleTimer::cancelAll()
		else {
			ok=false;
		}
		if ((*i)->cleanupFunction) (*i)->cleanupFunction((*i)->parameter); 
		delete (*i)->handler;
		delete (*i);
		
	}
	m_events.clear();
	return ok;	
@@ -131,7 +137,8 @@ bool CScheduleTimer::getNextEvent(unsigned &index,ACS::Time& time,ACS::TimeInter
	return true;
}

bool CScheduleTimer::schedule(TCallBack callBack,const ACS::Time& timeMark,const ACS::TimeInterval& interval,const void* param,TCleanupFunction cleanup)
bool CScheduleTimer::schedule(TCallBack callBack,const ACS::Time& timeMark,const ACS::TimeInterval& interval,
  const void* param,TCleanupFunction cleanup)
{
	long id;
	ACS::Time time=timeMark;
+17 −11
Original line number Diff line number Diff line
@@ -27,10 +27,16 @@ void oneShotCallBack(const ACS::Time& time,const void *par)
	Runit=false;
}

void contCleanUp(const void * par)
{
	long *val=(long *)(par);
	printf("continuous event clean-up called, got %ld\n",*val);
}


void cleanUp(const void * par)
{
	printf("event cleanup called\n");
	printf("one shot event clean-up called\n");
}

int main(int argc, char *argv[]) 
@@ -48,20 +54,20 @@ int main(int argc, char *argv[])
		printf("Error initializing the timer\n");
		return -1;
	}
	// setup a continuos event...every 2.5 seconds
	// setup a continuous event...every 2.5 seconds
	par1=1;
	period.second(2);
	period.microSecond(500000);
	if (!timer.schedule(&contCallBack,now.value().value,period.value().value,&par1)) {
		printf("Error scheduling the continuos event\n");
	if (!timer.schedule(&contCallBack,now.value().value,period.value().value,&par1,contCleanUp)) {
		printf("Error scheduling the continuous event\n");
		return -1;
	}
	// setup a continuos event...every 0.7 seconds
	// setup a continuous event...every 0.5 seconds
	par2=2;
	period.reset();
	period.microSecond(700000);
	if (!timer.schedule(&contCallBack,now.value().value,period.value().value,&par2)) {
		printf("Error scheduling the continuos event\n");
	period.microSecond(500000);
	if (!timer.schedule(&contCallBack,now.value().value,period.value().value,&par2,contCleanUp)) {
		printf("Error scheduling the continuous event\n");
		return -1;
	}
	// saves the current time
@@ -77,12 +83,12 @@ int main(int argc, char *argv[])
	while (Runit) {
		CIRATools::Wait(500000);
	}
	printf("removing the first continuos event\n");
	printf("removing the first continuous event\n");
	if (!timer.cancel(copy.value().value)) {
		printf("Error canceling an event\n");
		printf("Error cancelling an event\n");
		return -1;		
	}
	CIRATools::Wait(5,0);
	printf("closing up\n");
	printf("closing up everything\n");
}
+3 −3
Original line number Diff line number Diff line
@@ -10,7 +10,7 @@
	} \
	else { \
		FIELD=tmpw; \
		ACS_DEBUG_PARAM("CConfiguration::Init()",DESCR" %lu",tmpw); \
		ACS_DEBUG_PARAM("CConfiguration::Init()",DESCR" %u",tmpw); \
	} \
}

@@ -214,7 +214,7 @@ void CConfiguration::init(maci::ContainerServices *Services) throw (ComponentErr
		counter++;
		if (m_minorServoMappings>=MAX_AXIS_NUMBER) break;
	}
	ACS_DEBUG_PARAM("CConfiguration::Init()","Total minor servo axis: %d",m_minorServoMappings);
	ACS_DEBUG_PARAM("CConfiguration::Init()","Total minor servo axis: %ld",m_minorServoMappings);
	componentName="DataBlock/Equipment/AvailableBackend";
	counter--;
	for(;;) {
@@ -245,7 +245,7 @@ void CConfiguration::init(maci::ContainerServices *Services) throw (ComponentErr
		if (m_availableBackends>=MAX_BCK_NUMBER) break;
		counter++;
	}
	ACS_DEBUG_PARAM("CConfiguration::Init()","Total available backends: %d",m_availableBackends);
	ACS_DEBUG_PARAM("CConfiguration::Init()","Total available backends: %ld",m_availableBackends);
	if (!CIRATools::getDBValue(Services,"FTrackPrecisionDigits",m_fTrackDigits,"alma/","DataBlock/Equipment")) {
		_EXCPT(ComponentErrors::CDBAccessExImpl,dummy,"CConfiguration::Init()");
		dummy.setFieldName("FTrackPrecisionDigits");
+7 −7
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ bool CCore::checkScan(ACS::Time& ut,const Antenna::TTrackingParameters *const pr
	try {
		//antennaUT will stores the estimated start time from the antenna for all kind of subscans
		antennaAnswer=m_antennaBoss->checkScan(ut,*prim,*sec,minEl,maxEl,m_antennaRTime.out());
		ACS_LOG(LM_FULL_INFO,"CCore::checkScan()",(LM_DEBUG,"SLEWING_TIME %lld :",m_antennaRTime->slewingTime));
		ACS_LOG(LM_FULL_INFO,"CCore::checkScan()",(LM_DEBUG,"SLEWING_TIME %llu :",(unsigned long long)m_antennaRTime->slewingTime));
	}
	catch (ComponentErrors::ComponentErrorsEx& ex) {
		_ADD_BACKTRACE(ComponentErrors::OperationErrorExImpl,impl,ex,"CCore::checkScan()");
@@ -177,7 +177,7 @@ void CCore::doScan(ACS::Time& ut,const Antenna::TTrackingParameters * const prim
	try {
		antennaUT=ut;
		m_antennaBoss->startScan(antennaUT,*prim,*sec); // the ut could be modified by the call
		ACS_LOG(LM_FULL_INFO,"CCore::doScan()",(LM_DEBUG,"ANTENNA_SCAN_EPOCH %lld",antennaUT));
		ACS_LOG(LM_FULL_INFO,"CCore::doScan()",(LM_DEBUG,"ANTENNA_SCAN_EPOCH %llu",(unsigned long long)antennaUT));
	}
	catch (ComponentErrors::ComponentErrorsEx& ex) {
		_ADD_BACKTRACE(ComponentErrors::OperationErrorExImpl,impl,ex,"CCore::doScan()");
@@ -210,7 +210,7 @@ void CCore::doScan(ACS::Time& ut,const Antenna::TTrackingParameters * const prim
		try {
			servoUT=ut;
			m_minorServoBoss->startScan(servoUT,*servoPar,m_antennaRTime.in());
			ACS_LOG(LM_FULL_INFO,"CCore::doScan()",(LM_DEBUG,"MINOR_SERVO_SCAN_EPOCH %lld",servoUT));
			ACS_LOG(LM_FULL_INFO,"CCore::doScan()",(LM_DEBUG,"MINOR_SERVO_SCAN_EPOCH %llu",(unsigned long long)servoUT));
		}
		catch (MinorServoErrors::MinorServoErrorsEx& ex) {
			_ADD_BACKTRACE(ComponentErrors::OperationErrorExImpl,impl,ex,"CCore::doScan()");
@@ -241,7 +241,7 @@ void CCore::doScan(ACS::Time& ut,const Antenna::TTrackingParameters * const prim
	try {
		receiversUT=ut;
		m_receiversBoss->startScan(receiversUT,*recvPa,m_antennaRTime.in());
		ACS_LOG(LM_FULL_INFO,"CCore::doScan()",(LM_DEBUG,"RECEIEVERS_SCAN_EPOCH %lld",receiversUT));
		ACS_LOG(LM_FULL_INFO,"CCore::doScan()",(LM_DEBUG,"RECEIEVERS_SCAN_EPOCH %llu",(unsigned long long)receiversUT));
	}
	catch (ComponentErrors::ComponentErrorsEx& ex) {
		_ADD_BACKTRACE(ComponentErrors::OperationErrorExImpl,impl,ex,"CCore::doScan()");
@@ -395,7 +395,7 @@ ACS::Time CCore::closeScan(bool wait) throw (ComponentErrors::ComponentNotActive
	try {
		if (!CORBA::is_nil(m_antennaBoss)) {
			m_antennaBoss->closeScan(antennaUT); // the ut could be modified by the call
			ACS_LOG(LM_FULL_INFO,"CCore::closeScan()",(LM_DEBUG,"ANTENNA_CLOSE_SCAN_EPOCH %lld",antennaUT));
			ACS_LOG(LM_FULL_INFO,"CCore::closeScan()",(LM_DEBUG,"ANTENNA_CLOSE_SCAN_EPOCH %llu",(unsigned long long)antennaUT));
			IRA::CString outstr;
			IRA::CIRATools::timeToStr(antennaUT,outstr);
			//printf("tempo di chiusura (Antenna): %s\n",(const char*)outstr);
@@ -432,7 +432,7 @@ ACS::Time CCore::closeScan(bool wait) throw (ComponentErrors::ComponentNotActive
		try {
			if (!CORBA::is_nil(m_minorServoBoss)) {
				m_minorServoBoss->closeScan(servoUT);
				ACS_LOG(LM_FULL_INFO,"CCore::closeScan()",(LM_DEBUG,"MINOR_SERVO_CLOSE_SCAN_EPOCH %lld",servoUT));
				ACS_LOG(LM_FULL_INFO,"CCore::closeScan()",(LM_DEBUG,"MINOR_SERVO_CLOSE_SCAN_EPOCH %llu",(unsigned long long)servoUT));
				IRA::CString outstr;
				IRA::CIRATools::timeToStr(servoUT,outstr);
				//printf("tempo di chiusura (Servo): %s\n",(const char*)outstr);
@@ -467,7 +467,7 @@ ACS::Time CCore::closeScan(bool wait) throw (ComponentErrors::ComponentNotActive
	try {
		if (!CORBA::is_nil(m_receiversBoss)) {
			m_receiversBoss->closeScan(receiversUT);
			ACS_LOG(LM_FULL_INFO,"CCore::closeScan()",(LM_DEBUG,"RECEIEVERS_STOP_SCAN_EPOCH %lld",receiversUT));
			ACS_LOG(LM_FULL_INFO,"CCore::closeScan()",(LM_DEBUG,"RECEIEVERS_STOP_SCAN_EPOCH %llu",(unsigned long long)receiversUT));
			IRA::CString outstr;
			IRA::CIRATools::timeToStr(receiversUT,outstr);
			//printf("tempo di chiusura (receievers): %s\n",(const char*)outstr);
+24 −17
Original line number Diff line number Diff line
void CCore::_wait(const double& seconds) throw (ComponentErrors::TimerErrorExImpl,ManagementErrors::AbortedByUserExImpl)
{
	long *done;
	done=new long;
	*done=0;
	TIMEVALUE now;
	long done=0;
	TIMEVALUE now,check;
	IRA::CIRATools::getTime(now);
	ACS::Time time;
	time=now.value().value+(ACS::Time)(seconds*10000000);
	m_abortCurrentOperation=false;
	if (!addTimerEvent(time,waitUntilHandler,static_cast<void *>(done),waitUntilHandlerCleanup)) {
	long *pdone=&done;
	if (!addTimerEvent(time,waitUntilHandler,static_cast<void *>(pdone))) {
		//errore
		_EXCPT(ComponentErrors::TimerErrorExImpl,dummy,"CCore::wait()");
		_EXCPT(ComponentErrors::TimerErrorExImpl,dummy,"CCore::_wait()");
		dummy.setReason("timer event could not be scheduled");
		delete done;
		throw dummy;
	}
	while ((*done)==0) {
	while (done==0) {
		if (m_abortCurrentOperation) {
			m_abortCurrentOperation=false;
			_EXCPT(ManagementErrors::AbortedByUserExImpl,dummy,"CCore::wait()");
			_EXCPT(ManagementErrors::AbortedByUserExImpl,dummy,"CCore::_wait()");
			dummy.setOperation("wait for an amount of time");
			throw dummy;
		}
		IRA::CIRATools::getTime(check);
		if (check.value().value>time) {
			done=1;
			ACS_LOG(LM_FULL_INFO,"CCore::_wait()",(LM_WARNING,"Timer precision outside threshold"));
		}
		IRA::CIRATools::Wait(25000); // 25 milliseconds
	}
}

void CCore::_waitUntil(const ACS::Time& time) throw (ComponentErrors::TimerErrorExImpl,ManagementErrors::AbortedByUserExImpl)
{
	long *done;
	done=new long;
	*done=0;
	long done=0;
	long *pdone=&done;
	TIMEVALUE check;
	m_abortCurrentOperation=false;
	if (!addTimerEvent(time,waitUntilHandler,static_cast<void *>(done),waitUntilHandlerCleanup)) {
	if (!addTimerEvent(time,waitUntilHandler,static_cast<void *>(pdone))) {
		//errore
		_EXCPT(ComponentErrors::TimerErrorExImpl,dummy,"CCore::waitUntil()");
		_EXCPT(ComponentErrors::TimerErrorExImpl,dummy,"CCore::_waitUntil()");
		dummy.setReason("timer event could not be scheduled");
		delete done;
		throw dummy;
	}
	while ((*done)==0) {
	while (done==0) {
		if (m_abortCurrentOperation) {
			m_abortCurrentOperation=false;
			_EXCPT(ManagementErrors::AbortedByUserExImpl,dummy,"CCore::waitUntil()");
			_EXCPT(ManagementErrors::AbortedByUserExImpl,dummy,"CCore::_waitUntil()");
			dummy.setOperation("wait until an epoch");
			throw dummy;
		}
		IRA::CIRATools::getTime(check);
		if (check.value().value>time) {
			done=1;
			ACS_LOG(LM_FULL_INFO,"CCore::_waitUntil()",(LM_WARNING,"Timer precision outside threshold"));
		}
		IRA::CIRATools::Wait(25000); // 25 milliseconds
	}
}
Loading