-
Notifications
You must be signed in to change notification settings - Fork 55
/
thread.h
61 lines (45 loc) · 1.39 KB
/
thread.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright 2016 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROMIUMOS_WIDE_PROFILING_COMPAT_CROS_DETAIL_THREAD_H_
#define CHROMIUMOS_WIDE_PROFILING_COMPAT_CROS_DETAIL_THREAD_H_
#include "base/synchronization/waitable_event.h"
#include "base/threading/simple_thread.h"
namespace quipper {
class Thread : public quipper::compat::ThreadInterface,
public base::DelegateSimpleThread::Delegate {
public:
explicit Thread(const string& name_prefix) : thread_(this, name_prefix) {}
void Start() override {
thread_.Start();
}
void Join() override {
thread_.Join();
}
pid_t tid() override {
return thread_.tid();
}
protected:
void Run() override = 0;
private:
base::DelegateSimpleThread thread_;
};
class Notification : public quipper::compat::NotificationInterface {
public:
Notification() : event_(true /* manual_reset */,
false /* initially_signaled */) {
}
void Wait() override {
event_.Wait();
}
bool WaitWithTimeout(int timeout_ms) override {
return event_.TimedWait(base::TimeDelta::FromMilliseconds(timeout_ms));
}
void Notify() override {
event_.Signal();
}
private:
base::WaitableEvent event_;
};
} // namespace quipper
#endif // CHROMIUMOS_WIDE_PROFILING_COMPAT_CROS_DETAIL_THREAD_H_