Commit a271a778 authored by dino's avatar dino
Browse files

Add possibility to use boost/thread/mutex in MultiHist for older than c++11 compilers

git-svn-id: svn://gal-serv.lnl.infn.it/agata/trunk/narval_emulator@1287 170316e4-aea8-4b27-aad4-0380ec0519c9
parent 33554dd8
......@@ -12,12 +12,19 @@
#include <vector>
#include <cstdio>
#if THR_TYPE == THR_BOOST || THR_TYPE == THR_STD
#define MHIST_LMBUFF_ENABLE // comment to disable feature
#endif
#ifdef MHIST_LMBUFF_ENABLE
const int MHIST_LMBUFF_MAXNUM = 256; // because of incr(..., unsigned char thr)
const int MHIST_LMBUFF_MINLEN = 1024 * 64; // default (and minimum) LM buffer size
#include <mutex>
#if THR_TYPE == THR_BOOST
#include <boost/thread/mutex.hpp>
#elif THR_TYPE == THR_STD
#include <mutex>
#endif
#endif
class MultiHist_t
......@@ -232,7 +239,7 @@ class MultiHist : public MultiHist_t
int *bstored;
int buffsize;
int nswapped;
std::mutex theMutex;
thrLib::mutex theMutex;
#endif
// should only be called by the constructors
......@@ -303,7 +310,8 @@ class MultiHist : public MultiHist_t
histFlush(thr); // only one source, no need to lock
}
else {
std::lock_guard<std::mutex> lck{ theMutex };
thrLock lck(theMutex);
// std::lock_guard<thrLib::mutex> lck{ theMutex };
histFlush(thr);
}
}
......@@ -395,6 +403,8 @@ public:
buffsize = 0;
nswapped = 0;
}
#else
bool setupSwapper(int num = 1, int len = 1) { return true; }
#endif
void erase() {
......@@ -825,6 +835,8 @@ public:
}
return (count == hgroup.size());
}
#else
bool setupSwapper(int num = 1, int len = 1) { return true; }
#endif
};
......
......@@ -105,7 +105,8 @@
#define thrLib std
#define thrYield() ( thrLib::this_thread::yield() )
#define thrSleep(msecs) ( thrLib::this_thread::sleep_for(thrLib::chrono::milliseconds(msecs)) )
#define thrLock thrLib::unique_lock<std::mutex>
//#define thrLock thrLib::unique_lock<thrLib::mutex>
#define thrLock thrLib::lock_guard<thrLib::mutex>
#elif THR_TYPE == THR_NONE
#define thrLib
#define thrYield()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment