proxygen
ScopedEventBaseThread.h
Go to the documentation of this file.
1 /*
2  * Copyright 2015-present Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <memory>
20 #include <thread>
21 
24 
25 namespace folly {
26 
27 class EventBaseManager;
28 template <class Iter>
29 class Range;
31 
40  public:
42  explicit ScopedEventBaseThread(const StringPiece& name);
44  explicit ScopedEventBaseThread(
45  EventBaseManager* ebm,
46  const StringPiece& name);
48 
50  return &eb_;
51  }
52 
53  EventBase* getEventBase() override {
54  return &eb_;
55  }
56 
57  std::thread::id getThreadId() const {
58  return th_.get_id();
59  }
60 
61  void add(Func func) override {
62  getEventBase()->add(std::move(func));
63  }
64 
65  private:
68 
69  ScopedEventBaseThread(const ScopedEventBaseThread& other) = delete;
71 
73  union {
74  mutable EventBase eb_;
75  };
76  std::thread th_;
78 };
79 
80 } // namespace folly
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void add(Cob fn) override
Implements the Executor interface.
Definition: EventBase.h:624
ScopedEventBaseThread & operator=(ScopedEventBaseThread &&other)=delete
void add(Func func) override
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
const char * name
Definition: http_parser.c:437
EventBase * getEventBase() override
std::thread::id getThreadId() const
Range< const char * > StringPiece