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.
5 #ifndef PPAPI_UTILITY_NON_THREAD_SAFE_REF_COUNT_H_
6 #define PPAPI_UTILITY_NON_THREAD_SAFE_REF_COUNT_H_
8 #include "ppapi/cpp/core.h"
9 #include "ppapi/cpp/logging.h"
10 #include "ppapi/cpp/module.h"
13 /// This file defines the APIs for maintaining a reference counter.
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
{
21 /// Default constructor. In debug mode, this checks that the object is being
22 /// created on the main thread.
23 NonThreadSafeRefCount()
26 is_main_thread_
= Module::Get()->core()->IsMainThread();
31 ~NonThreadSafeRefCount() {
32 PP_DCHECK(is_main_thread_
== Module::Get()->core()->IsMainThread());
35 /// AddRef() increments the reference counter.
37 /// @return An int32_t with the incremented reference counter.
39 PP_DCHECK(is_main_thread_
== Module::Get()->core()->IsMainThread());
43 /// Release() decrements the reference counter.
45 /// @return An int32_t with the decremeneted reference counter.
47 PP_DCHECK(is_main_thread_
== Module::Get()->core()->IsMainThread());
60 #endif // PPAPI_UTILITY_NON_THREAD_SAFE_REF_COUNT_H_