19 #include <boost/algorithm/string.hpp>
20 #include <boost/thread/locks.hpp>
21 #include <gflags/gflags.h>
28 using namespace impala;
33 DEFINE_int32(num_threads_per_core, 3,
"Number of threads per core.");
36 DCHECK_GE(threads_quota, 0);
37 if (threads_quota == 0) {
51 num_reserved_optional_threads_ = 0;
52 thread_available_fn_ = NULL;
58 num_reserved_optional_threads_ = num;
62 unique_lock<mutex> l(
lock_);
83 unique_lock<mutex> l(
lock_);
91 unique_lock<mutex> l(
lock_);
92 DCHECK(thread_available_fn_ == NULL || fn == NULL);
93 thread_available_fn_ = fn;
97 if (
pools_.empty())
return;
100 for (Pools::iterator it =
pools_.begin(); it !=
pools_.end(); ++it) {
102 if (pool == new_pool)
continue;
103 unique_lock<mutex> l(pool->
lock_);
int system_threads_quota_
'Optimal' number of threads for the entire process.
boost::mutex lock_
Lock for the entire object. Protects all fields below.
void SetThreadAvailableCb(ThreadAvailableCb fn)
boost::function< void(ResourcePool *)> ThreadAvailableCb
void UpdatePoolQuotas(ResourcePool *new_pool=NULL)
ResourcePool * RegisterPool()
void ReserveOptionalTokens(int num)
int num_available_threads() const
Returns the number of optional threads that can still be used.
void UnregisterPool(ResourcePool *pool)
ThreadResourceMgr(int threads_quota=0)
void Reset()
Resets internal state.
static int num_cores()
Returns the number of cores (including hyper-threaded) on this machine.
DEFINE_int32(periodic_counter_update_period_ms, 500,"Period to update rate counters and"" sampling counters in ms")
ThreadAvailableCb thread_available_fn_
std::list< ResourcePool * > free_pool_objs_
Recycled list of pool objects.
ResourcePool(ThreadResourceMgr *parent)