Fix some tsan warnings

This commit is contained in:
Sebastian Messmer 2018-01-15 01:58:48 +00:00
parent fb24a249cb
commit 7287f1ca4d
5 changed files with 12 additions and 8 deletions

View File

@ -10,6 +10,7 @@
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <boost/optional.hpp> #include <boost/optional.hpp>
#include <cpp-utils/macros.h> #include <cpp-utils/macros.h>
#include <atomic>
namespace fspp { namespace fspp {
class Device; class Device;
@ -69,7 +70,7 @@ private:
Filesystem *_fs; Filesystem *_fs;
boost::filesystem::path _mountdir; boost::filesystem::path _mountdir;
std::vector<char*> _argv; std::vector<char*> _argv;
bool _running; std::atomic<bool> _running;
std::string _fstype; std::string _fstype;
boost::optional<std::string> _fsname; boost::optional<std::string> _fsname;

View File

@ -20,7 +20,7 @@ using std::future;
class ObjectWithLongDestructor { class ObjectWithLongDestructor {
public: public:
ObjectWithLongDestructor(ConditionBarrier *onDestructorStarted, bool *destructorFinished) ObjectWithLongDestructor(ConditionBarrier *onDestructorStarted, std::atomic<bool> *destructorFinished)
: _onDestructorStarted(onDestructorStarted), _destructorFinished(destructorFinished) {} : _onDestructorStarted(onDestructorStarted), _destructorFinished(destructorFinished) {}
~ObjectWithLongDestructor() { ~ObjectWithLongDestructor() {
_onDestructorStarted->release(); _onDestructorStarted->release();
@ -29,7 +29,7 @@ public:
} }
private: private:
ConditionBarrier *_onDestructorStarted; ConditionBarrier *_onDestructorStarted;
bool *_destructorFinished; std::atomic<bool> *_destructorFinished;
DISALLOW_COPY_AND_ASSIGN(ObjectWithLongDestructor); DISALLOW_COPY_AND_ASSIGN(ObjectWithLongDestructor);
}; };
@ -42,7 +42,7 @@ public:
Cache<int, unique_ptr<ObjectWithLongDestructor>, MAX_ENTRIES> cache; Cache<int, unique_ptr<ObjectWithLongDestructor>, MAX_ENTRIES> cache;
ConditionBarrier destructorStarted; ConditionBarrier destructorStarted;
bool destructorFinished; std::atomic<bool> destructorFinished;
int pushObjectWithLongDestructor() { int pushObjectWithLongDestructor() {
cache.push(2, make_unique<ObjectWithLongDestructor>(&destructorStarted, &destructorFinished)); cache.push(2, make_unique<ObjectWithLongDestructor>(&destructorStarted, &destructorFinished));

View File

@ -1,3 +1,3 @@
#include "MinimalKeyType.h" #include "MinimalKeyType.h"
int MinimalKeyType::instances = 0; std::atomic<int> MinimalKeyType::instances(0);

View File

@ -3,11 +3,12 @@
#define MESSMER_BLOCKSTORE_TEST_IMPLEMENTATIONS_CACHING_CACHE_TESTUTILS_MINIMALKEYTYPE_H_ #define MESSMER_BLOCKSTORE_TEST_IMPLEMENTATIONS_CACHING_CACHE_TESTUTILS_MINIMALKEYTYPE_H_
#include <unordered_map> #include <unordered_map>
#include <atomic>
// This is a not-default-constructible Key type // This is a not-default-constructible Key type
class MinimalKeyType { class MinimalKeyType {
public: public:
static int instances; static std::atomic<int> instances;
static MinimalKeyType create(int value) { static MinimalKeyType create(int value) {
return MinimalKeyType(value); return MinimalKeyType(value);

View File

@ -31,8 +31,10 @@ void FuseThread::start(const bf::path &mountDir, const vector<string> &fuseOptio
} }
void FuseThread::stop() { void FuseThread::stop() {
pthread_kill(_child.native_handle(), SIGINT); if (0 != pthread_kill(_child.native_handle(), SIGINT)) {
bool thread_stopped = _child.try_join_for(seconds(5)); throw std::runtime_error("Error sending stop signal");
}
bool thread_stopped = _child.try_join_for(seconds(10));
ASSERT(thread_stopped, "FuseThread could not be stopped"); ASSERT(thread_stopped, "FuseThread could not be stopped");
//Wait until it is properly shutdown (busy waiting is simple and doesn't hurt much here) //Wait until it is properly shutdown (busy waiting is simple and doesn't hurt much here)
while (_fuse->running()) {} while (_fuse->running()) {}