Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(278)

Side by Side Diff: webrtc/base/onetimeevent.h

Issue 2877023002: Move webrtc/{base => rtc_base} (Closed)
Patch Set: update presubmit.py and DEPS include rules Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_
OLDNEW
« no previous file with comments | « webrtc/base/numerics/percentile_filter_unittest.cc ('k') | webrtc/base/onetimeevent_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698