proxygen
folly::PriorityThreadFactory Class Reference

#include <PriorityThreadFactory.h>

Inheritance diagram for folly::PriorityThreadFactory:
folly::ThreadFactory

Public Member Functions

 PriorityThreadFactory (std::shared_ptr< ThreadFactory > factory, int priority)
 
std::thread newThread (Func &&func) override
 
- Public Member Functions inherited from folly::ThreadFactory
virtual ~ThreadFactory ()=default
 

Private Attributes

std::shared_ptr< ThreadFactoryfactory_
 
int priority_
 

Detailed Description

A ThreadFactory that sets nice values for each thread. The main use case for this class is if there are multiple CPUThreadPoolExecutors in a single process, or between multiple processes, where some should have a higher priority than the others.

Note that per-thread nice values are not POSIX standard, but both pthreads and linux support per-thread nice. The default linux scheduler uses these values to do smart thread prioritization. sched_priority function calls only affect real-time schedulers.

Definition at line 38 of file PriorityThreadFactory.h.

Constructor & Destructor Documentation

folly::PriorityThreadFactory::PriorityThreadFactory ( std::shared_ptr< ThreadFactory factory,
int  priority 
)
inlineexplicit

Definition at line 40 of file PriorityThreadFactory.h.

43  : factory_(std::move(factory)), priority_(priority) {}
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::shared_ptr< ThreadFactory > factory_

Member Function Documentation

std::thread folly::PriorityThreadFactory::newThread ( Func &&  func)
inlineoverridevirtual

Implements folly::ThreadFactory.

Definition at line 45 of file PriorityThreadFactory.h.

References folly::errnoStr(), factory_, folly::gen::move, and priority_.

Referenced by TEST().

45  {
46  int priority = priority_;
47  return factory_->newThread([priority, func = std::move(func)]() mutable {
48  if (setpriority(PRIO_PROCESS, 0, priority) != 0) {
49  LOG(ERROR) << "setpriority failed (are you root?) with error " << errno,
50  errnoStr(errno);
51  }
52  func();
53  });
54  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
fbstring errnoStr(int err)
Definition: String.cpp:463
std::shared_ptr< ThreadFactory > factory_

Member Data Documentation

std::shared_ptr<ThreadFactory> folly::PriorityThreadFactory::factory_
private

Definition at line 57 of file PriorityThreadFactory.h.

Referenced by newThread().

int folly::PriorityThreadFactory::priority_
private

Definition at line 58 of file PriorityThreadFactory.h.

Referenced by newThread().


The documentation for this class was generated from the following file: