Skip to content

Commit

Permalink
Merge branch 'fix-ctsaving-stream-data-race' into 'master'
Browse files Browse the repository at this point in the history
Fix ctsaving stream data race

See merge request limagroup/lima!186
  • Loading branch information
claustre committed Jan 14, 2021
2 parents 939726d + 32ee8b7 commit 7ae24c5
Show file tree
Hide file tree
Showing 15 changed files with 106 additions and 54 deletions.
12 changes: 8 additions & 4 deletions common/include/lima/MemUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ void LIMACORE_API ClearBuffer(void *ptr, int nb_concat_frames, const FrameDim& f

struct LIMACORE_API Allocator
{
DEB_STRUCT_NAMESPC(DebModCommon, "MemUtils", "Allocator");

struct Data {
virtual ~Data() = default;
};
Expand All @@ -54,9 +56,10 @@ struct LIMACORE_API Allocator

Allocator(Allocator&& o) : m_ref_count(0)
{
DEB_MEMBER_FUNCT();

if (o.m_ref_count != 0)
throw LIMA_COM_EXC(InvalidValue,
"Moved-from Allocator is not empty");
DEB_ERROR() << "Moved-from Allocator is not empty";
}

// Allocate a buffer of a given size and eventually return
Expand Down Expand Up @@ -102,9 +105,10 @@ struct LIMACORE_API Allocator

virtual ~Allocator()
{
DEB_MEMBER_FUNCT();

if (m_ref_count != 0)
std::cerr << "Error: destroying non-empty Allocator"
<< std::endl;
DEB_ERROR() << "Error: destroying non-empty Allocator";
}

// The real resource management counter, triggered by Ref
Expand Down
10 changes: 9 additions & 1 deletion common/include/lima/VideoUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <iostream>

#include "lima/Constants.h"
#include "lima/Exceptions.h"

#include "processlib/Data.h"

Expand Down Expand Up @@ -35,7 +36,14 @@ namespace lima
inline void alloc(int size)
{
if(!buffer || double(size) > this->size())
buffer = (char*)realloc(buffer,size);
{
char* tmp = (char*)realloc(buffer,size);
if (tmp == NULL)
throw LIMA_COM_EXC(Error, "Error in realloc: ")
<< "NULL pointer returned";
else
buffer = tmp;
}
}
inline void setParams(int fNumber,int w,int h,VideoMode m)
{
Expand Down
4 changes: 3 additions & 1 deletion common/src/Exceptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ Exception::Exception(Layer layer, ErrorType err_type, const string& err_desc,
if (deb_proxy)
*deb_proxy << "Exception(" << getErrType() << "): "
<< getErrDesc();
else
std::cerr << "********* Exception(" << getErrType() << "): "
<< getErrDesc();
}

Layer Exception::getLayer() const
Expand Down Expand Up @@ -146,4 +149,3 @@ ostream& lima::operator <<(ostream& os, const Exception& e)
{
return os << e.getErrMsg();
}

2 changes: 1 addition & 1 deletion common/src/MemUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ int lima::GetDefMaxNbBuffers(const FrameDim& frame_dim)
void lima::ClearBuffer(void *ptr, int nb_concat_frames,
const FrameDim& frame_dim)
{
memset(ptr, 0, nb_concat_frames * frame_dim.getMemSize());
memset(ptr, 0, nb_concat_frames * size_t(frame_dim.getMemSize()));
}

Allocator *Allocator::defaultAllocator()
Expand Down
6 changes: 2 additions & 4 deletions common/src/ThreadUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ bool Cond::wait(double timeout)
struct timeval now;
struct timespec waitTimeout;
gettimeofday(&now,NULL);
waitTimeout.tv_sec = now.tv_sec + long(timeout);
waitTimeout.tv_sec = now.tv_sec + time_t(timeout);
waitTimeout.tv_nsec = (now.tv_usec * 1000) +
long((timeout - long(timeout)) * 1e9);
if(waitTimeout.tv_nsec >= 1000000000L) // Carry
Expand Down Expand Up @@ -241,10 +241,8 @@ Thread::ExceptionCleanUp::~ExceptionCleanUp()
m_thread.m_exception_handled = true;
}

Thread::Thread()
Thread::Thread() : m_thread(NULL), m_started(false), m_finished(false), m_exception_handled(false), m_tid(0)
{
m_started = m_finished = m_exception_handled = false;
m_tid = 0;
pthread_attr_init(&m_thread_attr);
}

Expand Down
2 changes: 1 addition & 1 deletion control/include/lima/CtAccumulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ namespace lima
"Control");
friend class CtAccumulation;
public:
ThresholdCallback() {};
ThresholdCallback() : m_max(0) {};
virtual ~ThresholdCallback() {};

int m_max;
Expand Down
2 changes: 1 addition & 1 deletion control/include/lima/CtConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ namespace lima

private:
typedef std::map<std::string,ModuleTypeCallback*> ModuleMap;
CtConfig(const CtConfig &other): m_ctrl(other.m_ctrl) {}
CtConfig(const CtConfig &other): m_ctrl(other.m_ctrl), m_config(NULL) {}

CtControl& m_ctrl;
libconfig::Config* m_config;
Expand Down
9 changes: 6 additions & 3 deletions control/include/lima/CtSaving.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,10 @@ class LIMACORE_API CtSaving
typedef std::map<long, FrameParameters> Frame2Params;
struct Handler
{
Handler() : m_handler(NULL) {}
Handler() : m_handler(NULL), m_nb_frames(0) {}

void* m_handler;
int m_nb_frames;
int m_nb_frames;
};
struct cmpParameters
{
Expand Down Expand Up @@ -518,12 +518,14 @@ class LIMACORE_API CtSaving
void _prepare();

enum ContainerStatus {
Init, Prepare, Open,
Init, Preparing, Prepared, Open,
};

CtSaving& m_saving;
int m_idx;

// protect m_cnt_status, ensure atomic Preparing
Cond m_cond;
ContainerStatus m_cnt_status;
SaveContainer* m_save_cnt;
_SaveCBK* m_saving_cbk;
Expand All @@ -533,6 +535,7 @@ class LIMACORE_API CtSaving
bool m_pars_dirty_flag;
bool m_active;
_CompressionCBK* m_compression_cbk;

};
friend class Stream;

Expand Down
2 changes: 1 addition & 1 deletion control/include/lima/CtSaving_Compression.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ static const LZ4F_preferences_t lz4_preferences = {
int framesPerFile,const CtSaving::HeaderMap &header);
~FileLz4Compression();
virtual void process(Data &aData);
void _compression(const char *src,int size,ZBufferList& return_buffers);
void _compression(const char *src,size_t size,ZBufferList& return_buffers);
};
#endif // WITH_LZ4_COMPRESSION

Expand Down
2 changes: 1 addition & 1 deletion control/software_operation/src/SoftOpId.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ void SoftOpPeakFinder::setComputingMode(ComputingMode aComputingMode)

void SoftOpPeakFinder::getComputingMode(ComputingMode &aComputingMode) const
{
Tasks::PeakFinderTask::ComputingMode aMode;
Tasks::PeakFinderTask::ComputingMode aMode = Tasks::PeakFinderTask::MAXIMUM;
for(NameMapConstIterator i = m_task_manager.begin(); i != m_task_manager.end();++i) {
i->second.second->getComputingMode(aMode);
}
Expand Down
10 changes: 10 additions & 0 deletions control/src/CtControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ class CtControl::ImageStatusThread : public Thread

private:
struct ChangeEvent {

ChangeEvent() : force(false), finished(NULL) {}
ImageStatus status;
bool force;
bool *finished;
Expand Down Expand Up @@ -388,6 +390,14 @@ CtControl::CtControl(HwInterface *hw) :
CtControl::~CtControl()
{
DEB_DESTRUCTOR();

Status aStatus;
getStatus(aStatus);
if(aStatus.AcquisitionStatus == AcqRunning)
{
DEB_WARNING() << "Acquisition is still running, stopping acquisition";
stopAcq();
}

DEB_TRACE() << "Waiting for all threads to finish their tasks";
PoolThreadMgr& pool_thread_mgr = PoolThreadMgr::get();
Expand Down
Loading

0 comments on commit 7ae24c5

Please sign in to comment.