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

Side by Side Diff: native_client_sdk/src/libraries/utils/ref_object.h

Issue 16325024: Move thread_pool.h into utils so it can be shared by more than one example. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 6 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
OLDNEW
(Empty)
1 /* Copyright (c) 2012 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
6 #ifndef LIBRARIES_UTILS_REF_OBJECT
7 #define LIBRARIES_UTILS_REF_OBJECT
8
9 #include <stdlib.h>
10 #include "pthread.h"
11
12 class RefObject {
13 public:
14 RefObject() {
15 ref_count_ = 1;
16 pthread_mutex_init(&lock_, NULL);
17 }
18
19 int RefCount() const { return ref_count_; }
20
21 void Acquire() {
22 ref_count_++;
23 }
24
25 bool Release() {
26 if (--ref_count_ == 0) {
27 Destroy();
28 delete this;
29 return false;
30 }
31 return true;
32 }
33
34 protected:
35 virtual ~RefObject() {
36 pthread_mutex_destroy(&lock_);
37 }
38
39 // Override to clean up object when last reference is released.
40 virtual void Destroy() {}
41
42 pthread_mutex_t lock_;
43
44 private:
45 int ref_count_;
46 };
47
48 #endif // LIBRARIES_UTILS_REF_OBJECT
OLDNEW
« no previous file with comments | « native_client_sdk/src/libraries/utils/macros.h ('k') | native_client_sdk/src/libraries/utils/thread_safe_queue.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698