blob: 149396a3bff4685260f394be9e4865a8e9f99cdb (
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
53
54
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
#include "threadpool.h"
namespace vespamalloc {
#ifdef __PIC__
#define TLS_LINKAGE __attribute__((visibility("hidden"), tls_model("initial-exec")))
#else
#define TLS_LINKAGE __attribute__((visibility("hidden"), tls_model("local-exec")))
#endif
template <typename MemBlockPtrT, typename ThreadStatT>
class ThreadListT
{
public:
typedef ThreadPoolT<MemBlockPtrT, ThreadStatT > ThreadPool;
typedef AllocPoolT<MemBlockPtrT> AllocPool;
ThreadListT(AllocPool & pool);
~ThreadListT();
void setParams(size_t alwayReuseLimit, size_t threadCacheLimit) {
ThreadPool::setParams(alwayReuseLimit, threadCacheLimit);
}
bool quitThisThread();
bool initThisThread();
ThreadPool & getCurrent() { return *_myPool; }
size_t getThreadId() const { return (_myPool - _threadVector); }
void enableThreadSupport() {
if ( ! _isThreaded ) {
_isThreaded = true;
}
}
void info(FILE * os, size_t level=0);
size_t getMaxNumThreads() const { return NELEMS(_threadVector); }
private:
size_t getThreadCount() const { return _threadCount; }
size_t getThreadCountAccum() const { return _threadCountAccum; }
ThreadListT(const ThreadListT & tl);
ThreadListT & operator = (const ThreadListT & tl);
enum {ThreadStackSize=2048*1024};
volatile bool _isThreaded;
std::atomic<size_t> _threadCount;
std::atomic<size_t> _threadCountAccum;
ThreadPool _threadVector[NUM_THREADS];
AllocPoolT<MemBlockPtrT> & _allocPool;
static thread_local ThreadPool * _myPool TLS_LINKAGE;
};
template <typename MemBlockPtrT, typename ThreadStatT>
thread_local ThreadPoolT<MemBlockPtrT, ThreadStatT> * ThreadListT<MemBlockPtrT, ThreadStatT>::_myPool TLS_LINKAGE = nullptr;
}
|