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

Unified Diff: native_client_sdk/src/libraries/sdk_util/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 side-by-side diff with in-line comments
Download patch
Index: native_client_sdk/src/libraries/sdk_util/ref_object.h
===================================================================
--- native_client_sdk/src/libraries/sdk_util/ref_object.h (revision 0)
+++ native_client_sdk/src/libraries/sdk_util/ref_object.h (revision 0)
@@ -0,0 +1,49 @@
+/* Copyright (c) 2012 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 LIBRARIES_SDK_UTIL_REF_OBJECT
+#define LIBRARIES_SDK_UTIL_REF_OBJECT
+
+#include <stdlib.h>
+#include "pthread.h"
+
+class RefObject {
+ public:
+ RefObject() {
+ ref_count_ = 1;
+ pthread_mutex_init(&lock_, NULL);
+ }
+
+ int RefCount() const { return ref_count_; }
+
+ void Acquire() {
+ ref_count_++;
+ }
+
+ bool Release() {
+ if (--ref_count_ == 0) {
+ Destroy();
+ delete this;
+ return false;
+ }
+ return true;
+ }
+
+ protected:
+ virtual ~RefObject() {
+ pthread_mutex_destroy(&lock_);
+ }
+
+ // Override to clean up object when last reference is released.
+ virtual void Destroy() {}
+
+ pthread_mutex_t lock_;
+
+ private:
+ int ref_count_;
+};
+
+#endif // LIBRARIES_SDK_UTIL_REF_OBJECT
+
Property changes on: native_client_sdk/src/libraries/sdk_util/ref_object.h
___________________________________________________________________
Added: svn:eol-style
+ LF
« no previous file with comments | « native_client_sdk/src/libraries/sdk_util/macros.h ('k') | native_client_sdk/src/libraries/sdk_util/thread_pool.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698