proxygen
folly::InitThreadFactory Class Reference

#include <InitThreadFactory.h>

Inheritance diagram for folly::InitThreadFactory:
folly::ThreadFactory

Classes

struct  ThreadInitFini
 

Public Member Functions

 InitThreadFactory (std::shared_ptr< ThreadFactory > threadFactory, Func &&threadInitializer, Func &&threadFinializer=[]{})
 
std::thread newThread (Func &&func) override
 
- Public Member Functions inherited from folly::ThreadFactory
virtual ~ThreadFactory ()=default
 

Private Attributes

std::shared_ptr< ThreadFactorythreadFactory_
 
std::shared_ptr< ThreadInitFinithreadInitFini_
 

Detailed Description

Definition at line 27 of file InitThreadFactory.h.

Constructor & Destructor Documentation

folly::InitThreadFactory::InitThreadFactory ( std::shared_ptr< ThreadFactory threadFactory,
Func &&  threadInitializer,
Func &&  threadFinializer = [] {} 
)
inlineexplicit

Definition at line 29 of file InitThreadFactory.h.

References folly::gen::move, threadFactory_, and threadInitFini_.

32  {})
33  : threadFactory_(std::move(threadFactory)),
34  threadInitFini_(std::make_shared<ThreadInitFini>(
35  std::move(threadInitializer),
36  std::move(threadFinializer))) {}
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::shared_ptr< ThreadInitFini > threadInitFini_
std::shared_ptr< ThreadFactory > threadFactory_

Member Function Documentation

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

Implements folly::ThreadFactory.

Definition at line 38 of file InitThreadFactory.h.

References folly::gen::move, SCOPE_EXIT, threadFactory_, and threadInitFini_.

Referenced by TEST().

38  {
39  return threadFactory_->newThread(
40  [func = std::move(func), threadInitFini = threadInitFini_]() mutable {
41  threadInitFini->initializer();
42  SCOPE_EXIT {
43  threadInitFini->finalizer();
44  };
45  func();
46  });
47  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
#define SCOPE_EXIT
Definition: ScopeGuard.h:274
std::shared_ptr< ThreadInitFini > threadInitFini_
std::shared_ptr< ThreadFactory > threadFactory_

Member Data Documentation

std::shared_ptr<ThreadFactory> folly::InitThreadFactory::threadFactory_
private

Definition at line 50 of file InitThreadFactory.h.

Referenced by InitThreadFactory(), and newThread().

std::shared_ptr<ThreadInitFini> folly::InitThreadFactory::threadInitFini_
private

Definition at line 58 of file InitThreadFactory.h.

Referenced by InitThreadFactory(), and newThread().


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