From: Alexander Karsakov Date: Thu, 13 Mar 2014 06:22:36 +0000 (+0400) Subject: Fixed getPolicy() method to make it thread-safe. X-Git-Tag: submit/tizen_ivi/20141117.190038~2^2~552^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8910508b838363ce4f721e5b463cd04cfd225a1a;p=profile%2Fivi%2Fopencv.git Fixed getPolicy() method to make it thread-safe. --- diff --git a/modules/flann/include/opencv2/flann/any.h b/modules/flann/include/opencv2/flann/any.h index 4a58cf2..8c2edaa 100644 --- a/modules/flann/include/opencv2/flann/any.h +++ b/modules/flann/include/opencv2/flann/any.h @@ -155,13 +155,27 @@ SMALL_POLICY(bool); #undef SMALL_POLICY -/// This function will return a different policy for each type. -template -base_any_policy* get_policy() +template +class SinglePolicy { + SinglePolicy(); + SinglePolicy(const SinglePolicy& other); + SinglePolicy& operator=(const SinglePolicy& other); + +public: + static base_any_policy* get_policy(); + +private: static typename choose_policy::type policy; - return &policy; -} +}; + +template +typename choose_policy::type SinglePolicy::policy; + +/// This function will return a different policy for each type. +template +inline base_any_policy* SinglePolicy::get_policy() { return &policy; } + } // namespace anyimpl struct any @@ -175,26 +189,26 @@ public: /// Initializing constructor. template any(const T& x) - : policy(anyimpl::get_policy()), object(NULL) + : policy(anyimpl::SinglePolicy::get_policy()), object(NULL) { assign(x); } /// Empty constructor. any() - : policy(anyimpl::get_policy()), object(NULL) + : policy(anyimpl::SinglePolicy::get_policy()), object(NULL) { } /// Special initializing constructor for string literals. any(const char* x) - : policy(anyimpl::get_policy()), object(NULL) + : policy(anyimpl::SinglePolicy::get_policy()), object(NULL) { assign(x); } /// Copy constructor. any(const any& x) - : policy(anyimpl::get_policy()), object(NULL) + : policy(anyimpl::SinglePolicy::get_policy()), object(NULL) { assign(x); } @@ -219,7 +233,7 @@ public: any& assign(const T& x) { reset(); - policy = anyimpl::get_policy(); + policy = anyimpl::SinglePolicy::get_policy(); policy->copy_from_value(&x, &object); return *this; } @@ -274,7 +288,7 @@ public: void reset() { policy->static_delete(&object); - policy = anyimpl::get_policy(); + policy = anyimpl::SinglePolicy::get_policy(); } /// Returns true if the two types are the same.