summaryrefslogtreecommitdiffstats
path: root/ppapi/proxy/proxy_non_thread_safe_ref_count.h
blob: 855c87c6db0e795318c7d23aedac62838df66549 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef PPAPI_PROXY_PROXY_NON_THREAD_SAFE_REF_COUNT_H_
#define PPAPI_PROXY_PROXY_NON_THREAD_SAFE_REF_COUNT_H_

#include "base/message_loop.h"
#include "ppapi/cpp/completion_callback.h"

namespace ppapi {
namespace proxy {

// This class is just like ppapi/cpp/non_thread_safe_ref_count.h but rather
// than using pp::Module::core (which doesn't exist), it uses Chrome threads
// which do.
class ProxyNonThreadSafeRefCount {
 public:
  ProxyNonThreadSafeRefCount() : ref_(0) {
#ifndef NDEBUG
    message_loop_ = MessageLoop::current();
#endif
  }

  ~ProxyNonThreadSafeRefCount() {
    PP_DCHECK(message_loop_ == MessageLoop::current());
  }

  int32_t AddRef() {
    PP_DCHECK(message_loop_ == MessageLoop::current());
    return ++ref_;
  }

  int32_t Release() {
    PP_DCHECK(message_loop_ == MessageLoop::current());
    return --ref_;
  }

 private:
  int32_t ref_;
#ifndef NDEBUG
  MessageLoop* message_loop_;
#endif
};

}  // namespace proxy
}  // namespace ppapi

#endif  // PPAPI_PROXY_PROXY_NON_THREAD_SAFE_REF_COUNT_H_