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

View File

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

View File

@ -1,3 +1,3 @@
#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_
#include <unordered_map>
#include <atomic>
// This is a not-default-constructible Key type
class MinimalKeyType {
public:
static int instances;
static std::atomic<int> instances;
static MinimalKeyType create(int value) {
return MinimalKeyType(value);

View File

@ -31,8 +31,10 @@ void FuseThread::start(const bf::path &mountDir, const vector<string> &fuseOptio
}
void FuseThread::stop() {
pthread_kill(_child.native_handle(), SIGINT);
bool thread_stopped = _child.try_join_for(seconds(5));
if (0 != pthread_kill(_child.native_handle(), SIGINT)) {
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");
//Wait until it is properly shutdown (busy waiting is simple and doesn't hurt much here)
while (_fuse->running()) {}