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

Side by Side Diff: ppapi/cpp/non_thread_safe_ref_count.h

Issue 9122012: gcl change rev (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « ppapi/cpp/completion_callback.h ('k') | ppapi/cpp/paint_aggregator.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef PPAPI_CPP_NON_THREAD_SAFE_REF_COUNT_H_
6 #define PPAPI_CPP_NON_THREAD_SAFE_REF_COUNT_H_
7
8 #include "ppapi/cpp/core.h"
9 #include "ppapi/cpp/logging.h"
10 #include "ppapi/cpp/module.h"
11
12 /// @file
13 /// This file defines the APIs for maintaining a reference counter.
14 namespace pp {
15
16 /// A simple reference counter that is not thread-safe. <strong>Note:</strong>
17 /// in Debug mode, it checks that it is either called on the main thread, or
18 /// always called on another thread.
19 class NonThreadSafeRefCount {
20 public:
21 /// Default constructor. In debug mode, this checks that the object is being
22 /// created on the main thread.
23 NonThreadSafeRefCount()
24 : ref_(0) {
25 #ifndef NDEBUG
26 is_main_thread_ = Module::Get()->core()->IsMainThread();
27 #endif
28 }
29
30 /// Destructor.
31 ~NonThreadSafeRefCount() {
32 PP_DCHECK(is_main_thread_ == Module::Get()->core()->IsMainThread());
33 }
34
35 /// AddRef() increments the reference counter.
36 ///
37 /// @return An int32_t with the incremented reference counter.
38 int32_t AddRef() {
39 PP_DCHECK(is_main_thread_ == Module::Get()->core()->IsMainThread());
40 return ++ref_;
41 }
42
43 /// Release() decrements the reference counter.
44 ///
45 /// @return An int32_t with the decremeneted reference counter.
46 int32_t Release() {
47 PP_DCHECK(is_main_thread_ == Module::Get()->core()->IsMainThread());
48 return --ref_;
49 }
50
51 private:
52 int32_t ref_;
53 #ifndef NDEBUG
54 bool is_main_thread_;
55 #endif
56 };
57
58 } // namespace pp
59
60 #endif // PPAPI_CPP_NON_THREAD_SAFE_REF_COUNT_H_
OLDNEW
« no previous file with comments | « ppapi/cpp/completion_callback.h ('k') | ppapi/cpp/paint_aggregator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698