| Index: ppapi/thunk/enter.h
|
| diff --git a/ppapi/thunk/enter.h b/ppapi/thunk/enter.h
|
| index dd6a6325c17e6fcf844646151146c758873e4c28..34fb706a5ba30c913aec660179b03f54ab38036e 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) {
|
| }
|
| };
|
|
|
|
|