blob: eab023d12faea05a8c99253196e125bf54a914e6 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "common.h"
#include <pthread.h>
namespace vespamalloc {
std::atomic<uint32_t> Mutex::_threadCount(0);
bool Mutex::_stopRecursion = true;
void Mutex::lock()
{
if (_use) {
pthread_mutex_lock(&_mutex);
}
}
void Mutex::unlock()
{
if (_use) {
pthread_mutex_unlock(&_mutex);
}
}
void Mutex::quit()
{
if (_use) {
_use = false;
pthread_mutex_destroy(&_mutex);
}
}
void Mutex::init() {
if (!_use && ! _stopRecursion) {
pthread_mutex_init(&_mutex, NULL);
_use = true;
}
}
Guard::Guard(Mutex & m) :
_mutex(&m)
{
MallocRecurseOnSuspend(false);
_mutex->lock();
MallocRecurseOnSuspend(true);
}
}
extern "C" void MallocRecurseOnSuspend(bool recurse)
{
(void) recurse;
}
|