mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-12-03 21:30:11 -05:00
Add debugging of mutexes (#1470)
When DEBUG defined it will used timed locks which will log when held too long along with where.
This commit is contained in:
parent
4b751c2d37
commit
92312c8507
15 changed files with 352 additions and 432 deletions
|
|
@ -19,6 +19,8 @@
|
|||
#include "fs_statvfs.hpp"
|
||||
#include "statvfs_util.hpp"
|
||||
|
||||
#include "mutex.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
|
@ -82,7 +84,7 @@ namespace fs
|
|||
rv = 0;
|
||||
now = l::get_time();
|
||||
|
||||
pthread_mutex_lock(&g_cache_lock);
|
||||
mutex_lock(&g_cache_lock);
|
||||
|
||||
e = &g_cache[path_];
|
||||
|
||||
|
|
@ -94,7 +96,7 @@ namespace fs
|
|||
|
||||
*st_ = e->st;
|
||||
|
||||
pthread_mutex_unlock(&g_cache_lock);
|
||||
mutex_unlock(&g_cache_lock);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,20 +20,23 @@
|
|||
|
||||
#include "fixed_mem_pool.hpp"
|
||||
|
||||
#include "mutex.hpp"
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
|
||||
template<size_t SIZE>
|
||||
class LockedFixedMemPool
|
||||
{
|
||||
public:
|
||||
LockedFixedMemPool()
|
||||
{
|
||||
pthread_mutex_init(&_mutex,NULL);
|
||||
mutex_init(&_mutex);
|
||||
}
|
||||
|
||||
~LockedFixedMemPool()
|
||||
{
|
||||
pthread_mutex_destroy(&_mutex);
|
||||
mutex_destroy(&_mutex);
|
||||
}
|
||||
|
||||
public:
|
||||
|
|
@ -42,9 +45,9 @@ public:
|
|||
{
|
||||
void *mem;
|
||||
|
||||
pthread_mutex_lock(&_mutex);
|
||||
mutex_lock(&_mutex);
|
||||
mem = _fmp.alloc();
|
||||
pthread_mutex_unlock(&_mutex);
|
||||
mutex_unlock(&_mutex);
|
||||
|
||||
return mem;
|
||||
}
|
||||
|
|
@ -52,9 +55,9 @@ public:
|
|||
void
|
||||
free(void *mem_)
|
||||
{
|
||||
pthread_mutex_lock(&_mutex);
|
||||
mutex_lock(&_mutex);
|
||||
_fmp.free(mem_);
|
||||
pthread_mutex_unlock(&_mutex);
|
||||
mutex_unlock(&_mutex);
|
||||
}
|
||||
|
||||
uint64_t
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
#include "policy_cache.hpp"
|
||||
|
||||
#include "mutex.hpp"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
|
@ -36,7 +38,7 @@ PolicyCache::Value::Value()
|
|||
PolicyCache::PolicyCache(void)
|
||||
: timeout(DEFAULT_TIMEOUT)
|
||||
{
|
||||
pthread_mutex_init(&_lock,NULL);
|
||||
mutex_init(&_lock);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -45,11 +47,11 @@ PolicyCache::erase(const char *fusepath_)
|
|||
if(timeout == 0)
|
||||
return;
|
||||
|
||||
pthread_mutex_lock(&_lock);
|
||||
mutex_lock(&_lock);
|
||||
|
||||
_cache.erase(fusepath_);
|
||||
|
||||
pthread_mutex_unlock(&_lock);
|
||||
mutex_unlock(&_lock);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -66,7 +68,7 @@ PolicyCache::cleanup(const int prob_)
|
|||
|
||||
now = l::get_time();
|
||||
|
||||
pthread_mutex_lock(&_lock);
|
||||
mutex_lock(&_lock);
|
||||
|
||||
i = _cache.begin();
|
||||
while(i != _cache.end())
|
||||
|
|
@ -77,17 +79,17 @@ PolicyCache::cleanup(const int prob_)
|
|||
++i;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&_lock);
|
||||
mutex_unlock(&_lock);
|
||||
}
|
||||
|
||||
void
|
||||
PolicyCache::clear(void)
|
||||
{
|
||||
pthread_mutex_lock(&_lock);
|
||||
mutex_lock(&_lock);
|
||||
|
||||
_cache.clear();
|
||||
|
||||
pthread_mutex_unlock(&_lock);
|
||||
mutex_unlock(&_lock);
|
||||
}
|
||||
|
||||
int
|
||||
|
|
@ -105,18 +107,18 @@ PolicyCache::operator()(const Policy::Search &policy_,
|
|||
|
||||
now = l::get_time();
|
||||
|
||||
pthread_mutex_lock(&_lock);
|
||||
mutex_lock(&_lock);
|
||||
v = &_cache[fusepath_];
|
||||
|
||||
if((now - v->time) >= timeout)
|
||||
{
|
||||
pthread_mutex_unlock(&_lock);
|
||||
mutex_unlock(&_lock);
|
||||
|
||||
rv = policy_(branches_,fusepath_,paths_);
|
||||
if(rv == -1)
|
||||
return -1;
|
||||
|
||||
pthread_mutex_lock(&_lock);
|
||||
mutex_lock(&_lock);
|
||||
v->time = now;
|
||||
v->paths = paths_;
|
||||
}
|
||||
|
|
@ -125,7 +127,7 @@ PolicyCache::operator()(const Policy::Search &policy_,
|
|||
paths_ = v->paths;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&_lock);
|
||||
mutex_unlock(&_lock);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue