OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #ifndef WEBRTC_BASE_ONETIMEEVENT_H_ | 11 #ifndef WEBRTC_BASE_ONETIMEEVENT_H_ |
12 #define WEBRTC_BASE_ONETIMEEVENT_H_ | 12 #define WEBRTC_BASE_ONETIMEEVENT_H_ |
13 | 13 |
14 #include "webrtc/base/criticalsection.h" | |
15 #include "webrtc/typedefs.h" | |
16 | 14 |
17 namespace webrtc { | 15 // This header is deprecated and is just left here temporarily during |
18 // Provides a simple way to perform an operation (such as logging) one | 16 // refactoring. See https://bugs.webrtc.org/7634 for more details. |
19 // time in a certain scope. | 17 #include "webrtc/rtc_base/onetimeevent.h" |
20 // Example: | |
21 // OneTimeEvent firstFrame; | |
22 // ... | |
23 // if (firstFrame()) { | |
24 // LOG(LS_INFO) << "This is the first frame". | |
25 // } | |
26 class OneTimeEvent { | |
27 public: | |
28 OneTimeEvent() {} | |
29 bool operator()() { | |
30 rtc::CritScope cs(&critsect_); | |
31 if (happened_) { | |
32 return false; | |
33 } | |
34 happened_ = true; | |
35 return true; | |
36 } | |
37 | |
38 private: | |
39 bool happened_ = false; | |
40 rtc::CriticalSection critsect_; | |
41 }; | |
42 | |
43 // A non-thread-safe, ligher-weight version of the OneTimeEvent class. | |
44 class ThreadUnsafeOneTimeEvent { | |
45 public: | |
46 ThreadUnsafeOneTimeEvent() {} | |
47 bool operator()() { | |
48 if (happened_) { | |
49 return false; | |
50 } | |
51 happened_ = true; | |
52 return true; | |
53 } | |
54 | |
55 private: | |
56 bool happened_ = false; | |
57 }; | |
58 | |
59 } // namespace webrtc | |
60 | 18 |
61 #endif // WEBRTC_BASE_ONETIMEEVENT_H_ | 19 #endif // WEBRTC_BASE_ONETIMEEVENT_H_ |
OLD | NEW |