use own reentrant mutex implementation
This commit is contained in:
@@ -24,9 +24,9 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <mutex>
|
|
||||||
#include "lib/ebus/symbol.h"
|
#include "lib/ebus/symbol.h"
|
||||||
#include "lib/ebus/result.h"
|
#include "lib/ebus/result.h"
|
||||||
|
#include "lib/utils/thread.h"
|
||||||
|
|
||||||
namespace ebusd {
|
namespace ebusd {
|
||||||
|
|
||||||
@@ -44,7 +44,6 @@ using std::string;
|
|||||||
using std::map;
|
using std::map;
|
||||||
using std::ostream;
|
using std::ostream;
|
||||||
using std::istream;
|
using std::istream;
|
||||||
using std::mutex;
|
|
||||||
|
|
||||||
/** the separator character used between fields. */
|
/** the separator character used between fields. */
|
||||||
#define FIELD_SEPARATOR ','
|
#define FIELD_SEPARATOR ','
|
||||||
@@ -275,6 +274,10 @@ class MappedFileReader : public FileReader {
|
|||||||
*/
|
*/
|
||||||
static const string combineRow(const map<string, string>& row);
|
static const string combineRow(const map<string, string>& row);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
/** a @a Mutex for access to defaults. */
|
||||||
|
Mutex m_mutex;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/** whether this instance supports rows with defaults (starting with a star). */
|
/** whether this instance supports rows with defaults (starting with a star). */
|
||||||
const bool m_supportsDefaults;
|
const bool m_supportsDefaults;
|
||||||
@@ -282,9 +285,6 @@ class MappedFileReader : public FileReader {
|
|||||||
/** the preferred language code (up to 2 characters), or empty. */
|
/** the preferred language code (up to 2 characters), or empty. */
|
||||||
const string m_preferLanguage;
|
const string m_preferLanguage;
|
||||||
|
|
||||||
/** a @a mutex for access to defaults. */
|
|
||||||
mutex m_mutex;
|
|
||||||
|
|
||||||
/** the name of each column. */
|
/** the name of each column. */
|
||||||
vector<string> m_columnNames;
|
vector<string> m_columnNames;
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,6 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <mutex>
|
|
||||||
#include "lib/ebus/data.h"
|
#include "lib/ebus/data.h"
|
||||||
#include "lib/ebus/result.h"
|
#include "lib/ebus/result.h"
|
||||||
#include "lib/ebus/symbol.h"
|
#include "lib/ebus/symbol.h"
|
||||||
@@ -1556,9 +1555,6 @@ class MessageMap : public MappedFileReader {
|
|||||||
|
|
||||||
/** additional attributes by circuit name. */
|
/** additional attributes by circuit name. */
|
||||||
map<string, AttributedItem*> m_circuitData;
|
map<string, AttributedItem*> m_circuitData;
|
||||||
|
|
||||||
/** a @a mutex for locking out changes. */
|
|
||||||
mutex m_mutex;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ebusd
|
} // namespace ebusd
|
||||||
|
|||||||
@@ -105,4 +105,25 @@ bool WaitThread::Wait(int seconds) {
|
|||||||
return isRunning();
|
return isRunning();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Mutex::Mutex() {
|
||||||
|
pthread_mutexattr_t attr;
|
||||||
|
pthread_mutexattr_init(&attr);
|
||||||
|
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
|
||||||
|
pthread_mutex_init(&m_mutex, &attr);
|
||||||
|
pthread_mutexattr_destroy(&attr);
|
||||||
|
}
|
||||||
|
|
||||||
|
Mutex::~Mutex() {
|
||||||
|
pthread_mutex_destroy(&m_mutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Mutex::lock() {
|
||||||
|
pthread_mutex_lock(&m_mutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Mutex::unlock() {
|
||||||
|
pthread_mutex_unlock(&m_mutex);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace ebusd
|
} // namespace ebusd
|
||||||
|
|||||||
@@ -142,6 +142,37 @@ class WaitThread : public Thread {
|
|||||||
pthread_cond_t m_cond;
|
pthread_cond_t m_cond;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A simple mutex.
|
||||||
|
*/
|
||||||
|
class Mutex {
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*/
|
||||||
|
Mutex();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destructor.
|
||||||
|
*/
|
||||||
|
virtual ~Mutex();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lock this mutex.
|
||||||
|
*/
|
||||||
|
void lock();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unlock this mutex.
|
||||||
|
*/
|
||||||
|
void unlock();
|
||||||
|
|
||||||
|
private:
|
||||||
|
/** the mutex for waiting. */
|
||||||
|
pthread_mutex_t m_mutex;
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace ebusd
|
} // namespace ebusd
|
||||||
|
|
||||||
#endif // LIB_UTILS_THREAD_H_
|
#endif // LIB_UTILS_THREAD_H_
|
||||||
|
|||||||
Reference in New Issue
Block a user