summaryrefslogtreecommitdiffstats
path: root/ppapi/thunk
diff options
context:
space:
mode:
authordmichael@chromium.org <dmichael@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-11 18:58:22 +0000
committerdmichael@chromium.org <dmichael@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-11 18:58:22 +0000
commit67c125db892ec5222d74012da3c6d353cdf24671 (patch)
treef8380f814530c5b6a05543c91cc3c68212454ad3 /ppapi/thunk
parent339651d588733a950864e7cac566b614421ca9cd (diff)
downloadchromium_src-67c125db892ec5222d74012da3c6d353cdf24671.zip
chromium_src-67c125db892ec5222d74012da3c6d353cdf24671.tar.gz
chromium_src-67c125db892ec5222d74012da3c6d353cdf24671.tar.bz2
Add global lock for Enter* classes. Add ScopedProxyLock for non-thunk proxies. Add multi-threading test for PPB_Var.
BUG=92909 TEST=None yet Review URL: http://codereview.chromium.org/8016008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@104931 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/thunk')
-rw-r--r--ppapi/thunk/enter.cc1
-rw-r--r--ppapi/thunk/enter.h58
2 files changed, 43 insertions, 16 deletions
diff --git a/ppapi/thunk/enter.cc b/ppapi/thunk/enter.cc
index da3f85c..7e9f70a 100644
--- a/ppapi/thunk/enter.cc
+++ b/ppapi/thunk/enter.cc
@@ -4,6 +4,7 @@
#include "ppapi/thunk/enter.h"
+#include "base/lazy_instance.h"
#include "ppapi/thunk/ppb_instance_api.h"
#include "ppapi/thunk/resource_creation_api.h"
diff --git a/ppapi/thunk/enter.h b/ppapi/thunk/enter.h
index dd6a632..34fb706 100644
--- a/ppapi/thunk/enter.h
+++ b/ppapi/thunk/enter.h
@@ -9,6 +9,7 @@
#include "ppapi/c/pp_resource.h"
#include "ppapi/proxy/interface_id.h"
#include "ppapi/shared_impl/function_group_base.h"
+#include "ppapi/shared_impl/proxy_lock.h"
#include "ppapi/shared_impl/resource.h"
#include "ppapi/shared_impl/tracker_base.h"
#include "ppapi/shared_impl/resource_tracker.h"
@@ -19,7 +20,7 @@
namespace ppapi {
namespace thunk {
-// EnterHost* helper objects: These objects wrap a call from the C PPAPI into
+// Enter* helper objects: These objects wrap a call from the C PPAPI into
// the internal implementation. They make sure the lock is acquired and will
// automatically set up some stuff for you.
//
@@ -29,19 +30,47 @@ namespace thunk {
// The |report_error| arguments to the constructor should indicate if errors
// should be logged to the console. If the calling function expects that the
// input values are correct (the normal case), this should be set to true. In
-// some case like |IsFoo(PP_Resource)| the caller is quersioning whether their
+// some case like |IsFoo(PP_Resource)| the caller is questioning whether their
// handle is this type, and we don't want to report an error if it's not.
//
-// Standalone functions: EnterHostFunction
+// Standalone functions: EnterFunction
// Automatically gets the implementation for the function API for the
// supplied PP_Instance.
//
-// Resource member functions: EnterHostResource
+// Resource member functions: EnterResource
// Automatically interprets the given PP_Resource as a resource ID and sets
// up the resource object for you.
-template<typename FunctionsT>
-class EnterFunction {
+namespace subtle {
+
+// This helps us define our RAII Enter classes easily. To make an RAII class
+// which locks the proxy lock on construction and unlocks on destruction,
+// inherit from |LockOnEntry<true>|. For cases where you don't want to lock,
+// inherit from |LockOnEntry<false>|. This allows us to share more code between
+// Enter* and Enter*NoLock classes.
+template <bool lock_on_entry>
+struct LockOnEntry;
+
+template <>
+struct LockOnEntry<false> {
+// TODO(dmichael) assert the lock is held.
+};
+
+template <>
+struct LockOnEntry<true> {
+ LockOnEntry() {
+ ppapi::ProxyLock::Acquire();
+ }
+ ~LockOnEntry() {
+ ppapi::ProxyLock::Release();
+ }
+};
+
+} // namespace subtle
+
+
+template<typename FunctionsT, bool lock_on_entry = true>
+class EnterFunction : subtle::LockOnEntry<lock_on_entry> {
public:
EnterFunction(PP_Instance instance, bool report_error)
: functions_(NULL) {
@@ -51,6 +80,7 @@ class EnterFunction {
functions_ = base->GetAs<FunctionsT>();
// TODO(brettw) check error and if report_error is set, do something.
}
+
~EnterFunction() {}
bool succeeded() const { return !!functions_; }
@@ -65,13 +95,11 @@ class EnterFunction {
};
// Like EnterResource but assumes the lock is already held.
-// TODO(brettw) actually implement locks, this is just a placeholder for now.
template<typename FunctionsT>
-class EnterFunctionNoLock : public EnterFunction<FunctionsT> {
+class EnterFunctionNoLock : public EnterFunction<FunctionsT, false> {
public:
EnterFunctionNoLock(PP_Instance instance, bool report_error)
- : EnterFunction<FunctionsT>(instance, report_error) {
- // TODO(brettw) assert the lock is held.
+ : EnterFunction<FunctionsT, false>(instance, report_error) {
}
};
@@ -95,8 +123,8 @@ class EnterFunctionGivenResource : public EnterFunction<FunctionsT> {
// EnterResource ---------------------------------------------------------------
-template<typename ResourceT>
-class EnterResource {
+template<typename ResourceT, bool lock_on_entry = true>
+class EnterResource : subtle::LockOnEntry<lock_on_entry> {
public:
EnterResource(PP_Resource resource, bool report_error)
: object_(NULL) {
@@ -121,13 +149,11 @@ class EnterResource {
};
// Like EnterResource but assumes the lock is already held.
-// TODO(brettw) actually implement locks, this is just a placeholder for now.
template<typename ResourceT>
-class EnterResourceNoLock : public EnterResource<ResourceT> {
+class EnterResourceNoLock : public EnterResource<ResourceT, false> {
public:
EnterResourceNoLock(PP_Resource resource, bool report_error)
- : EnterResource<ResourceT>(resource, report_error) {
- // TODO(brettw) assert the lock is held.
+ : EnterResource<ResourceT, false>(resource, report_error) {
}
};