aboutsummaryrefslogtreecommitdiff
path: root/src/core/u_concurrent_set.h
diff options
context:
space:
mode:
authorGil Pitney <gil.pitney@linaro.org>2016-06-10 23:18:27 +0000
committerGil Pitney <gil.pitney@linaro.org>2016-06-29 22:40:58 +0000
commit52496644a788f2118ed2de7e99f3d184d3d70ca8 (patch)
treea7cdfd2213da21a4f597a98bb3f31dcb7c73ddb7 /src/core/u_concurrent_set.h
parentd10b2c2df4655afc8ecd00d6b9afc4aa634b0e83 (diff)
Merge of select changes from TI OpenCL 01.01.08.03 from git.ti.com/ti-opencl/hostTI_01_01_08_03_Merge
Including: - Use of the Loki library v 0.1.7 for C++ Singleton implementation. - Updated Platform object to be a Singleton class instance. - Better handling of MemObject management with concurrent threads. - Events: added CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST error code. - MapImageEvent() fixes. - KernelEvent() fixes around retaining/releasing objects. - CopyBufferRectEvent() fixes. - ReadWriteBufferRectEvent() fixes. Revalidating Shamrock with these changes resulted in 12 more Khronos conformance tests passing in test_basic, test_buffers, and test_events, and no regressions. Signed-off-by: Gil Pitney <gil.pitney@linaro.org>
Diffstat (limited to 'src/core/u_concurrent_set.h')
-rw-r--r--src/core/u_concurrent_set.h80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/core/u_concurrent_set.h b/src/core/u_concurrent_set.h
new file mode 100644
index 0000000..c2767c9
--- /dev/null
+++ b/src/core/u_concurrent_set.h
@@ -0,0 +1,80 @@
+/******************************************************************************
+ * Copyright (c) 2013-2014, Texas Instruments Incorporated - http://www.ti.com/
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of Texas Instruments Incorporated nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *****************************************************************************/
+/**************************************************************************//**
+*
+* @file u_concurrent_set.h
+* @brief TI implementation class that implements a thread safe set.
+*
+******************************************************************************/
+#ifndef _U_CONCURRENT_SET_H_
+#define _U_CONCURRENT_SET_H_
+
+#include <iostream>
+#include <set>
+#include "u_lockable.h"
+
+/**************************************************************************//**
+* @class concurrent_set
+*
+* @brief A thread safe set implementation
+*
+* @details This implementation wraps a standard stl set with some locking
+* capability to make the member functions mutually exclusive
+* regions. In derives from the class Lockable which defines a type
+* Lock that can be used to define a type in a scope. The result will
+* be that the remainder of the scope (or until unlock is called) is a
+* mutex.
+*
+******************************************************************************/
+template<typename T>
+class concurrent_set : public Lockable
+{
+public:
+ concurrent_set() : S() {}
+ ~concurrent_set() {}
+
+ void insert (T const data) { Lock lock(this); S.insert(data); }
+ void erase (T data) { Lock lock(this); S.erase(data); }
+ bool memberp(T data) const
+ { Lock lock(this); return S.find(data) != S.end(); }
+
+ /*-------------------------------------------------------------------------
+ * The class's data
+ *------------------------------------------------------------------------*/
+private:
+ std::set<T> S; //!< standard stl set
+
+ /*-------------------------------------------------------------------------
+ * Prevent copy construction and assignment
+ *------------------------------------------------------------------------*/
+private:
+ concurrent_set(const concurrent_set&);
+ concurrent_set& operator=(const concurrent_set&);
+};
+
+#endif //_U_CONCURRENT_SET_H_