Replaced pthread with std:: thread and mutex

This commit is contained in:
Jean-Francois Dockes
2016-07-12 18:08:21 +02:00
parent d8f215b6ed
commit c1fad4afc7
33 changed files with 367 additions and 633 deletions
+7 -7
View File
@@ -35,6 +35,7 @@
#include <cstring>
#include <map>
#include <mutex>
#include "cstr.h"
#include "mimehandler.h"
@@ -45,7 +46,6 @@
#include "rclconfig.h"
#include "md5ut.h"
#include "conftree.h"
#include "ptmutex.h"
using namespace std;
@@ -65,7 +65,7 @@ public:
private: FILE **m_fpp;
};
static PTMutexInit o_mcache_mutex;
static std::mutex o_mcache_mutex;
/**
* Handles a cache for message numbers to offset translations. Permits direct
@@ -105,7 +105,7 @@ public:
LOGDEB0("MboxCache::get_offsets: init failed\n" );
return -1;
}
PTMutexLocker locker(o_mcache_mutex);
std::unique_lock<std::mutex> locker(o_mcache_mutex);
string fn = makefilename(udi);
FILE *fp = 0;
if ((fp = fopen(fn.c_str(), "r")) == 0) {
@@ -149,7 +149,7 @@ public:
return;
if (fsize < m_minfsize)
return;
PTMutexLocker locker(o_mcache_mutex);
std::unique_lock<std::mutex> locker(o_mcache_mutex);
string fn = makefilename(udi);
FILE *fp;
if ((fp = fopen(fn.c_str(), "w")) == 0) {
@@ -179,7 +179,7 @@ public:
// Check state, possibly initialize
bool ok(RclConfig *config) {
PTMutexLocker locker(o_mcache_mutex);
std::unique_lock<std::mutex> locker(o_mcache_mutex);
if (m_minfsize == -1)
return false;
if (!m_ok) {
@@ -393,11 +393,11 @@ basic_regex<char> minifromregex;
#endif
static bool regcompiled;
static PTMutexInit o_regex_mutex;
static std::mutex o_regex_mutex;
static void compileregexes()
{
PTMutexLocker locker(o_regex_mutex);
std::unique_lock<std::mutex> locker(o_regex_mutex);
// As the initial test of regcompiled is unprotected the value may
// have changed while we were waiting for the lock. Test again now
// that we are alone.
+5 -5
View File
@@ -23,6 +23,7 @@
#include <string>
#include <vector>
#include <list>
#include <mutex>
using namespace std;
#include "cstr.h"
@@ -40,7 +41,6 @@ using namespace std;
#include "mh_symlink.h"
#include "mh_unknown.h"
#include "mh_null.h"
#include "ptmutex.h"
// Performance help: we use a pool of already known and created
// handlers. There can be several instances for a given mime type
@@ -50,14 +50,14 @@ static multimap<string, RecollFilter*> o_handlers;
static list<multimap<string, RecollFilter*>::iterator> o_hlru;
typedef list<multimap<string, RecollFilter*>::iterator>::iterator hlruit_tp;
static PTMutexInit o_handlers_mutex;
static std::mutex o_handlers_mutex;
static const unsigned int max_handlers_cache_size = 100;
/* Look for mime handler in pool */
static RecollFilter *getMimeHandlerFromCache(const string& key)
{
PTMutexLocker locker(o_handlers_mutex);
std::unique_lock<std::mutex> locker(o_handlers_mutex);
string xdigest;
MD5HexPrint(key, xdigest);
LOGDEB("getMimeHandlerFromCache: " << (xdigest) << " cache size " << (o_handlers.size()) << "\n" );
@@ -90,7 +90,7 @@ void returnMimeHandler(RecollFilter *handler)
}
handler->clear();
PTMutexLocker locker(o_handlers_mutex);
std::unique_lock<std::mutex> locker(o_handlers_mutex);
LOGDEB("returnMimeHandler: returning filter for " << (handler->get_mime_type()) << " cache size " << (o_handlers.size()) << "\n" );
@@ -124,7 +124,7 @@ void clearMimeHandlerCache()
{
LOGDEB("clearMimeHandlerCache()\n" );
multimap<string, RecollFilter *>::iterator it;
PTMutexLocker locker(o_handlers_mutex);
std::unique_lock<std::mutex> locker(o_handlers_mutex);
for (it = o_handlers.begin(); it != o_handlers.end(); it++) {
delete it->second;
}
+2 -2
View File
@@ -39,7 +39,7 @@ bool Uncomp::uncompressfile(const string& ifn,
const vector<string>& cmdv, string& tfile)
{
if (m_docache) {
PTMutexLocker lock(o_cache.m_lock);
std::unique_lock<std::mutex> lock(o_cache.m_lock);
if (!o_cache.m_srcpath.compare(ifn)) {
m_dir = o_cache.m_dir;
m_tfile = tfile = o_cache.m_tfile;
@@ -123,7 +123,7 @@ bool Uncomp::uncompressfile(const string& ifn,
Uncomp::~Uncomp()
{
if (m_docache) {
PTMutexLocker lock(o_cache.m_lock);
std::unique_lock<std::mutex> lock(o_cache.m_lock);
delete o_cache.m_dir;
o_cache.m_dir = m_dir;
o_cache.m_tfile = m_tfile;
+2 -2
View File
@@ -19,10 +19,10 @@
#include <vector>
#include <string>
#include <mutex>
#include "pathut.h"
#include "rclutil.h"
#include "ptmutex.h"
/// Uncompression script interface.
class Uncomp {
@@ -58,7 +58,7 @@ private:
{
delete m_dir;
}
PTMutexInit m_lock;
std::mutex m_lock;
TempDir *m_dir;
std::string m_tfile;
std::string m_srcpath;