OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license | |
5 * that can be found in the LICENSE file in the root of the source | |
6 * tree. An additional intellectual property rights grant can be found | |
7 * in the file PATENTS. All contributing project authors may | |
8 * be found in the AUTHORS file in the root of the source tree. | |
9 */ | |
10 | |
11 #ifndef WEBRTC_BASE_ONETIMEEVENT_H_ | |
12 #define WEBRTC_BASE_ONETIMEEVENT_H_ | |
13 | |
14 #include "webrtc/base/scoped_ptr.h" | |
15 #include "webrtc/base/criticalsection.h" | |
16 #include "webrtc/typedefs.h" | |
17 | |
18 namespace webrtc { | |
19 | |
20 // Provides a simple way to perform an operation (such as logging) one | |
21 // time in a certain scope. | |
22 // Example: | |
23 // OneTimeEvent firstFrame; | |
24 // ... | |
25 // if (firstFrame()) { | |
26 // LOG(LS_INFO) << "This is the first frame". | |
27 // } | |
28 class OneTimeEvent { | |
29 public: | |
30 OneTimeEvent() {} | |
31 bool operator()() { | |
32 rtc::CritScope cs(&critsect_); | |
pthatcher1
2016/03/25 22:35:22
Would it make sense to allow the OneTimeEvent to c
skvlad
2016/03/26 02:00:08
I've added the thread-unsafe version, however, out
| |
33 bool first_time = !happened_; | |
34 happened_ = true; | |
35 return first_time; | |
pthatcher1
2016/03/25 22:35:23
Might be a little more clear as:
if (happened_) {
skvlad
2016/03/26 02:00:08
Done.
| |
36 } | |
37 | |
38 private: | |
39 bool happened_ = false; | |
40 rtc::CriticalSection critsect_; | |
41 }; | |
42 | |
43 } // namespace webrtc | |
44 | |
45 #endif // WEBRTC_BASE_ONETIMEEVENT_H_ | |
OLD | NEW |