proxygen
folly::NamedThreadFactory Class Reference

#include <NamedThreadFactory.h>

Inheritance diagram for folly::NamedThreadFactory:
folly::ThreadFactory

Public Member Functions

 NamedThreadFactory (folly::StringPiece prefix)
 
std::thread newThread (Func &&func) override
 
void setNamePrefix (folly::StringPiece prefix)
 
std::string getNamePrefix ()
 
- Public Member Functions inherited from folly::ThreadFactory
virtual ~ThreadFactory ()=default
 

Private Attributes

std::string prefix_
 
std::atomic< uint64_tsuffix_
 

Detailed Description

Definition at line 30 of file NamedThreadFactory.h.

Constructor & Destructor Documentation

folly::NamedThreadFactory::NamedThreadFactory ( folly::StringPiece  prefix)
inlineexplicit

Definition at line 32 of file NamedThreadFactory.h.

33  : prefix_(prefix.str()), suffix_(0) {}
std::string str() const
Definition: Range.h:591
std::atomic< uint64_t > suffix_

Member Function Documentation

std::string folly::NamedThreadFactory::getNamePrefix ( )
inline

Definition at line 48 of file NamedThreadFactory.h.

References prefix_.

48  {
49  return prefix_;
50  }
std::thread folly::NamedThreadFactory::newThread ( Func &&  func)
inlineoverridevirtual

Implements folly::ThreadFactory.

Definition at line 35 of file NamedThreadFactory.h.

References folly::gen::move, name, prefix_, folly::setThreadName(), and suffix_.

35  {
36  auto name = folly::to<std::string>(prefix_, suffix_++);
37  return std::thread(
38  [func = std::move(func), name = std::move(name)]() mutable {
40  func();
41  });
42  }
std::atomic< uint64_t > suffix_
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
const char * name
Definition: http_parser.c:437
bool setThreadName(std::thread::id tid, StringPiece name)
Definition: ThreadName.cpp:109
void folly::NamedThreadFactory::setNamePrefix ( folly::StringPiece  prefix)
inline

Definition at line 44 of file NamedThreadFactory.h.

References prefix_, and folly::Range< Iter >::str().

44  {
45  prefix_ = prefix.str();
46  }
std::string str() const
Definition: Range.h:591

Member Data Documentation

std::string folly::NamedThreadFactory::prefix_
private

Definition at line 53 of file NamedThreadFactory.h.

Referenced by getNamePrefix(), newThread(), and setNamePrefix().

std::atomic<uint64_t> folly::NamedThreadFactory::suffix_
private

Definition at line 54 of file NamedThreadFactory.h.

Referenced by newThread().


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