summaryrefslogtreecommitdiffstats
path: root/src/include/util/lockfree
diff options
context:
space:
mode:
authorPatrick Williams <iawillia@us.ibm.com>2011-08-23 15:16:35 -0500
committerA. Patrick Williams III <iawillia@us.ibm.com>2011-08-31 13:39:51 -0500
commitf7b7b56dea28dd69a44a877f7b7073c4496ced9e (patch)
tree640fdb38b13df41c5f0835374033d53b21d163ca /src/include/util/lockfree
parente6b1dcfdee1467cf7f43b64c8dddb87f13bf2f10 (diff)
downloadtalos-hostboot-f7b7b56dea28dd69a44a877f7b7073c4496ced9e.tar.gz
talos-hostboot-f7b7b56dea28dd69a44a877f7b7073c4496ced9e.zip
Ensure scratch operations happen on master core.
Change-Id: I970d645108de041d410599847edce877cb794015 Reviewed-on: http://gfw160.austin.ibm.com:8080/gerrit/275 Tested-by: Jenkins Server Reviewed-by: Daniel M. Crowell <dcrowell@us.ibm.com> Reviewed-by: A. Patrick Williams III <iawillia@us.ibm.com>
Diffstat (limited to 'src/include/util/lockfree')
-rw-r--r--src/include/util/lockfree/atomic_construct.H62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/include/util/lockfree/atomic_construct.H b/src/include/util/lockfree/atomic_construct.H
new file mode 100644
index 000000000..6946a1c60
--- /dev/null
+++ b/src/include/util/lockfree/atomic_construct.H
@@ -0,0 +1,62 @@
+// IBM_PROLOG_BEGIN_TAG
+// This is an automatically generated prolog.
+//
+// $Source: src/include/util/lockfree/atomic_construct.H $
+//
+// IBM CONFIDENTIAL
+//
+// COPYRIGHT International Business Machines Corp. 2011
+//
+// p1
+//
+// Object Code Only (OCO) source materials
+// Licensed Internal Code Source Materials
+// IBM HostBoot Licensed Internal Code
+//
+// The source code for this program is not published or other-
+// wise divested of its trade secrets, irrespective of what has
+// been deposited with the U.S. Copyright Office.
+//
+// Origin: 30
+//
+// IBM_PROLOG_END
+#ifndef __UTIL_LOCKFREE_ATOMIC_CONSTRUCT_H
+#define __UTIL_LOCKFREE_ATOMIC_CONSTRUCT_H
+
+namespace Util
+{
+ namespace Lockfree
+ {
+
+ /** @brief Atomically construct an object and assign it to a pointer.
+ *
+ * This function will check if a pointer is still NULL and
+ * construct an object, atomically, if needed. If the pointer is
+ * not NULL, the current instance will be left alone.
+ *
+ * @param[in] ptr - Pointer-pointer to the object.
+ *
+ * Example:
+ * Foo* iv_foo; //<--- instance variable in class.
+ * atomic_construct(&iv_foo);
+ *
+ * @note It is possible for multiple instances to temporarily exist,
+ * if this code is called from multiple CPUs, but only the one
+ * instance will exist outside the lifetime of this function.
+ */
+ template<typename _T>
+ void atomic_construct(_T** ptr)
+ {
+ if (__sync_bool_compare_and_swap(ptr, NULL, NULL))
+ {
+ _T* instance = new _T();
+ if (!__sync_bool_compare_and_swap(ptr, NULL, instance))
+ {
+ delete instance;
+ }
+ }
+ }
+ };
+};
+
+#endif
OpenPOWER on IntegriCloud