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

Side by Side Diff: experimental/flocking_geese/threading/ref_count.h

Issue 10928195: First round of dead file removal (Closed) Base URL: https://github.com/samclegg/nativeclient-sdk.git@master
Patch Set: Created 8 years, 3 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
(Empty)
1 // Copyright (c) 2011 The Native Client 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 REF_COUNT_H_
6 #define REF_COUNT_H_
7
8 #include "threading/scoped_mutex_lock.h"
9
10 namespace threading {
11
12 // A thread-safe reference counter for class CompletionCallbackFactory.
13 class RefCount {
14 public:
15 RefCount() : ref_(0) {
16 pthread_mutex_init(&mutex_, NULL);
17 }
18 ~RefCount() {
19 pthread_mutex_destroy(&mutex_);
20 }
21
22 int32_t AddRef() {
23 int32_t ret_val = 0;
24 threading::ScopedMutexLock scoped_mutex(&mutex_);
25 if (scoped_mutex.is_valid()) {
26 ret_val = ++ref_;
27 }
28 return ret_val;
29 }
30
31 int32_t Release() {
32 int32_t ret_val = -1;
33 threading::ScopedMutexLock scoped_mutex(&mutex_);
34 if (scoped_mutex.is_valid()) {
35 ret_val = --ref_;
36 }
37 return ret_val;
38 }
39
40 private:
41 int32_t ref_;
42 pthread_mutex_t mutex_;
43 };
44
45 } // namespace threading
46 #endif // REF_COUNT_H_
OLDNEW
« no previous file with comments | « experimental/flocking_geese/threading/pthread_ext.h ('k') | experimental/flocking_geese/threading/scoped_mutex_lock.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698