Shaka Player Embedded
thread.h
Go to the documentation of this file.
1 // Copyright 2018 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef SHAKA_EMBEDDED_DEBUG_THREAD_H_
16 #define SHAKA_EMBEDDED_DEBUG_THREAD_H_
17 
18 #include <functional>
19 #include <string>
20 #include <thread>
21 
22 namespace shaka {
23 
24 class Thread final {
25  public:
26  Thread(const std::string& name, std::function<void()> callback);
27  Thread(const Thread&) = delete;
28  Thread(Thread&&) = delete;
29  ~Thread();
30 
32  std::string name() const {
33  return name_;
34  }
35 
37  bool joinable() const {
38  return thread_.joinable();
39  }
40 
42  std::thread::id get_id() const {
43  return thread_.get_id();
44  }
45 
46 #ifdef DEBUG_DEADLOCKS
47 
51  std::thread::id get_original_id() const {
52  return original_id_;
53  }
54 #endif
55 
56  void join() {
57  thread_.join();
58  }
59 
60  private:
61  const std::string name_;
62  std::thread thread_;
63 #ifdef DEBUG_DEADLOCKS
64  std::thread::id original_id_;
65 #endif
66 };
67 
68 } // namespace shaka
69 
70 #endif // SHAKA_EMBEDDED_DEBUG_THREAD_H_
std::string name() const
Definition: thread.h:32
void join()
Definition: thread.h:56
Thread(const std::string &name, std::function< void()> callback)
Definition: thread.cc:45
std::thread::id get_id() const
Definition: thread.h:42
bool joinable() const
Definition: thread.h:37