$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
From: xushiweizh_at_[hidden]
Date: 2008-05-13 17:18:32
Author: xushiwei
Date: 2008-05-13 17:18:31 EDT (Tue, 13 May 2008)
New Revision: 45343
URL: http://svn.boost.org/trac/boost/changeset/45343
Log:
ticket #1879: TaggedCompareAndSwap
Text files modified: 
   sandbox/memory/boost/detail/winapi/atomic/windows.hpp |    40 ++++++++++++++---                       
   sandbox/memory/boost/detail/winapi/winbase.h          |     2                                         
   sandbox/memory/boost/lockfree/tagged_ptr.hpp          |    89 +++++++-------------------------------- 
   3 files changed, 50 insertions(+), 81 deletions(-)
Modified: sandbox/memory/boost/detail/winapi/atomic/windows.hpp
==============================================================================
--- sandbox/memory/boost/detail/winapi/atomic/windows.hpp	(original)
+++ sandbox/memory/boost/detail/winapi/atomic/windows.hpp	2008-05-13 17:18:31 EDT (Tue, 13 May 2008)
@@ -68,23 +68,47 @@
 #endif
 
 // -------------------------------------------------------------------------
+// TaggedCompareAndSwap
 
-__forceinline bool WINAPI CompareAndSwap64(
-	PLONG64 Destination, LONG64 Exchange, LONG64 Comperand)
+__forceinline bool WINAPI TaggedCompareAndSwap(
+	LONG32 Destination[2], LONG32 Exchange, LONG32 Comperand, LONG32 Tag)
 {
         bool ok;
         __asm {
-		mov eax, long ptr Comperand
-		mov edx, long ptr Comperand + 4
-		mov ebx, long ptr Exchange
-		mov ecx, long ptr Exchange + 4
-		mov edi, long ptr Destination
+		mov eax, Comperand
+		mov edx, Tag
+		mov ebx, Exchange
+		mov ecx, edx
+		inc ecx
+		mov edi, Destination
                 lock cmpxchg8b [edi]
-		setz [ok]
+		setz ok
         }
         return ok;
 }
 
+#if defined(_WIN32)
+
+template <class Type>
+__forceinline bool WINAPI TaggedCompareAndSwap(
+	Type* Destination[2], Type* Exchange, Type* Comperand, Type* Tag)
+{
+	return TaggedCompareAndSwap(
+		(LONG32*)Destination, (LONG32)Exchange, (LONG32)Comperand, (LONG32)Tag);
+}
+
+#elif defined(_WIN64)
+
+template <class Type>
+__forceinline bool WINAPI TaggedCompareAndSwap(
+	Type* Destination[2], Type* Exchange, Type* Comperand, Type* Tag)
+{
+	return TaggedCompareAndSwap(
+		(LONG64*)Destination, (LONG64)Exchange, (LONG64)Comperand, (LONG64)Tag);
+}
+
+#endif
+
 // -------------------------------------------------------------------------
 // $Log: $
 
Modified: sandbox/memory/boost/detail/winapi/winbase.h
==============================================================================
--- sandbox/memory/boost/detail/winapi/winbase.h	(original)
+++ sandbox/memory/boost/detail/winapi/winbase.h	2008-05-13 17:18:31 EDT (Tue, 13 May 2008)
@@ -12,7 +12,7 @@
 #ifndef BOOST_DETAIL_WINAPI_WINBASE_H
 #define BOOST_DETAIL_WINAPI_WINBASE_H
 
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(_WIN64)
 
 #ifndef __wtypes_h__
 #include <wtypes.h>
Modified: sandbox/memory/boost/lockfree/tagged_ptr.hpp
==============================================================================
--- sandbox/memory/boost/lockfree/tagged_ptr.hpp	(original)
+++ sandbox/memory/boost/lockfree/tagged_ptr.hpp	2008-05-13 17:18:31 EDT (Tue, 13 May 2008)
@@ -1,5 +1,5 @@
 //
-//  boost/lockfree/tagged_ptr.hpp
+//  boost/lockfree/tagged.hpp
 //
 //  Copyright (c) 2004 - 2008 xushiwei (xushiweizh_at_[hidden])
 //
@@ -32,105 +32,50 @@
 #define BOOST_LOCKFREE_CALL
 #endif
 
-#if defined(_WIN32) || defined(__BIT32__)
-#define NS_BOOST_LOCKFREE_BIT32
-#elif defined(_WIN64) || defined(__BIT64__) || defined(__x86_64__)
-#define NS_BOOST_LOCKFREE_BIT64
-#else
-#error "Unknown Configurations"
-#endif
-
 NS_BOOST_LOCKFREE_BEGIN
 
 // -------------------------------------------------------------------------
-// class tagged_ptr
+// class tagged
 
-#if defined(NS_BOOST_LOCKFREE_BIT32)
-
-template <class Type>
+template <class E>
 class tagged_ptr
 {
 private:
-	LONG64 m_p;
+	typedef E* Type;
+	Type m_p[2];
 
 public:
-	tagged_ptr() : m_p(0) {}
+	tagged_ptr(Type vInit = Type()) {
+		m_p[0] = vInit;
+	}
         
         template <class FuncT>
         bool BOOST_LOCKFREE_CALL set(FuncT& op)
         {
-		BOOST_DETAIL_ASSERT(sizeof(Type*) == sizeof(LONG32));
-		for (;;)
-		{
-			tagged_ptr vOld = *this;
-			Type* pOld = vOld.get();
-			if (!op.valid(pOld))
-				return false;
-
-			tagged_ptr vNew = vOld;
-			vNew.m_p += (LONG64)1 << 32;
-			*(LONG32*)&vNew.m_p = (LONG32)static_cast<Type*>(op(pOld));
-			if (CompareAndSwap64(&m_p, vNew.m_p, vOld.m_p))
-				return true;
-		}
-	}
-
-	__forceinline Type* BOOST_LOCKFREE_CALL clear()
-	{
-		return (Type*)InterlockedExchangePointer((PVOID*)&m_p, NULL);
-	}
-
-	__forceinline Type* BOOST_LOCKFREE_CALL get() const
-	{
-		return (Type*)(LONG32)m_p;
-	}
-};
-
-#elif defined(NS_BOOST_LOCKFREE_BIT64)
-
-template <class Type>
-class tagged_ptr
-{
-private:
-	ATOMIC_LONG128 m_p;
-
-public:
-	tagged_ptr() : m_p(0) {}
-
-	template <class FuncT>
-	bool BOOST_LOCKFREE_CALL set(FuncT op)
-	{
-		BOOST_DETAIL_ASSERT(sizeof(Type*) == sizeof(LONG64));
                 for (;;)
                 {
-			tagged_ptr vOld = *this;
-			Type* pOld = vOld.get();
-			if (!op.valid(pOld))
+			Type vTag = m_p[1]; // NOTE: getting 'tag' before getting 'data'!
+			Type vOld = get();
+			if (!op.valid(vOld))
                                 return false;
 
-			tagged_ptr vNew = vOld;
-			vNew.m_p += (ATOMIC_LONG128)1 << 64;
-			*(LONG64*)&vNew.m_p = (LONG64)static_cast<Type*>(op(pOld));
-			if (CompareAndSwap128(&m_p, vNew.m_p, vOld.m_p))
+			Type vNew = op(vOld);
+			if (TaggedCompareAndSwap(m_p, vNew, vOld, vTag))
                                 return true;
                 }
         }
 
-	__forceinline Type* BOOST_LOCKFREE_CALL clear()
+	__forceinline Type BOOST_LOCKFREE_CALL clear()
         {
-		return (Type*)InterlockedExchangePointer((PVOID*)&m_p, NULL);
+		return (Type)InterlockedExchangePointer((PVOID*)m_p, NULL);
         }
 
-	__forceinline Type* BOOST_LOCKFREE_CALL get() const
+	__forceinline Type BOOST_LOCKFREE_CALL get() const
         {
-		return (Type*)(LONG64)m_p;
+		return m_p[0];
         }
 };
 
-#else
-#error "Unknown Configurations"
-#endif
-
 // -------------------------------------------------------------------------
 // $Log: $