Move some functions to allow them to be inlined with clang
authorKoundinya Veluri <kouvel@microsoft.com>
Tue, 20 Oct 2015 17:37:01 +0000 (10:37 -0700)
committerKoundinya Veluri <kouvel@microsoft.com>
Thu, 22 Oct 2015 04:34:12 +0000 (21:34 -0700)
For the moment, GetThread, _rotl/_rotr, Interlocked..., and similar functions were moved to allow inlining them with clang.

The plan is to eventually enable link-time optimization (LTO) to cover inlining across translation units.

Renamed some code files in PAL tests to compile as C++ to use the C++ inline semantics.

50 files changed:
Documentation/building/unix-test-instructions.md
src/pal/inc/pal.h
src/pal/src/CMakeLists.txt
src/pal/src/cruntime/misc.cpp
src/pal/src/misc/interlock.cpp [deleted file]
src/pal/src/misc/miscpalapi.cpp
src/pal/tests/palsuite/c_runtime/_rotl/test1/CMakeLists.txt
src/pal/tests/palsuite/c_runtime/_rotl/test1/test1.cpp [moved from src/pal/tests/palsuite/c_runtime/_rotl/test1/test1.c with 100% similarity]
src/pal/tests/palsuite/c_runtime/_rotr/test1/CMakeLists.txt
src/pal/tests/palsuite/c_runtime/_rotr/test1/test1.cpp [moved from src/pal/tests/palsuite/c_runtime/_rotr/test1/test1.c with 100% similarity]
src/pal/tests/palsuite/miscellaneous/InterLockedExchangeAdd/test1/CMakeLists.txt
src/pal/tests/palsuite/miscellaneous/InterLockedExchangeAdd/test1/test.cpp [moved from src/pal/tests/palsuite/miscellaneous/InterLockedExchangeAdd/test1/test.c with 100% similarity]
src/pal/tests/palsuite/miscellaneous/InterlockedBit/test1/CMakeLists.txt
src/pal/tests/palsuite/miscellaneous/InterlockedBit/test1/test.cpp [moved from src/pal/tests/palsuite/miscellaneous/InterlockedBit/test1/test.c with 84% similarity]
src/pal/tests/palsuite/miscellaneous/InterlockedBit/test2/CMakeLists.txt
src/pal/tests/palsuite/miscellaneous/InterlockedBit/test2/test.cpp [moved from src/pal/tests/palsuite/miscellaneous/InterlockedBit/test2/test.c with 84% similarity]
src/pal/tests/palsuite/miscellaneous/InterlockedCompareExchange/test1/CMakeLists.txt
src/pal/tests/palsuite/miscellaneous/InterlockedCompareExchange/test1/test.cpp [moved from src/pal/tests/palsuite/miscellaneous/InterlockedCompareExchange/test1/test.c with 100% similarity]
src/pal/tests/palsuite/miscellaneous/InterlockedCompareExchange/test2/CMakeLists.txt
src/pal/tests/palsuite/miscellaneous/InterlockedCompareExchange/test2/test.cpp [moved from src/pal/tests/palsuite/miscellaneous/InterlockedCompareExchange/test2/test.c with 100% similarity]
src/pal/tests/palsuite/miscellaneous/InterlockedCompareExchange64/test1/CMakeLists.txt
src/pal/tests/palsuite/miscellaneous/InterlockedCompareExchange64/test1/test.cpp [moved from src/pal/tests/palsuite/miscellaneous/InterlockedCompareExchange64/test1/test.c with 100% similarity]
src/pal/tests/palsuite/miscellaneous/InterlockedCompareExchange64/test2/CMakeLists.txt
src/pal/tests/palsuite/miscellaneous/InterlockedCompareExchange64/test2/test.cpp [moved from src/pal/tests/palsuite/miscellaneous/InterlockedCompareExchange64/test2/test.c with 100% similarity]
src/pal/tests/palsuite/miscellaneous/InterlockedCompareExchangePointer/test1/CMakeLists.txt
src/pal/tests/palsuite/miscellaneous/InterlockedCompareExchangePointer/test1/test.cpp [moved from src/pal/tests/palsuite/miscellaneous/InterlockedCompareExchangePointer/test1/test.c with 98% similarity]
src/pal/tests/palsuite/miscellaneous/InterlockedDecrement/test1/CMakeLists.txt
src/pal/tests/palsuite/miscellaneous/InterlockedDecrement/test1/test.cpp [moved from src/pal/tests/palsuite/miscellaneous/InterlockedDecrement/test1/test.c with 100% similarity]
src/pal/tests/palsuite/miscellaneous/InterlockedDecrement/test2/CMakeLists.txt
src/pal/tests/palsuite/miscellaneous/InterlockedDecrement/test2/test.cpp [moved from src/pal/tests/palsuite/miscellaneous/InterlockedDecrement/test2/test.c with 100% similarity]
src/pal/tests/palsuite/miscellaneous/InterlockedDecrement64/test1/CMakeLists.txt
src/pal/tests/palsuite/miscellaneous/InterlockedDecrement64/test1/test.cpp [moved from src/pal/tests/palsuite/miscellaneous/InterlockedDecrement64/test1/test.c with 100% similarity]
src/pal/tests/palsuite/miscellaneous/InterlockedDecrement64/test2/CMakeLists.txt
src/pal/tests/palsuite/miscellaneous/InterlockedDecrement64/test2/test.cpp [moved from src/pal/tests/palsuite/miscellaneous/InterlockedDecrement64/test2/test.c with 100% similarity]
src/pal/tests/palsuite/miscellaneous/InterlockedExchange/test1/CMakeLists.txt
src/pal/tests/palsuite/miscellaneous/InterlockedExchange/test1/test.cpp [moved from src/pal/tests/palsuite/miscellaneous/InterlockedExchange/test1/test.c with 100% similarity]
src/pal/tests/palsuite/miscellaneous/InterlockedExchange64/test1/CMakeLists.txt
src/pal/tests/palsuite/miscellaneous/InterlockedExchange64/test1/test.cpp [moved from src/pal/tests/palsuite/miscellaneous/InterlockedExchange64/test1/test.c with 100% similarity]
src/pal/tests/palsuite/miscellaneous/InterlockedExchangePointer/test1/CMakeLists.txt
src/pal/tests/palsuite/miscellaneous/InterlockedExchangePointer/test1/InterlockedExchangePointer.cpp [moved from src/pal/tests/palsuite/miscellaneous/InterlockedExchangePointer/test1/InterlockedExchangePointer.c with 100% similarity]
src/pal/tests/palsuite/miscellaneous/InterlockedIncrement/test1/CMakeLists.txt
src/pal/tests/palsuite/miscellaneous/InterlockedIncrement/test1/test.cpp [moved from src/pal/tests/palsuite/miscellaneous/InterlockedIncrement/test1/test.c with 100% similarity]
src/pal/tests/palsuite/miscellaneous/InterlockedIncrement/test2/CMakeLists.txt
src/pal/tests/palsuite/miscellaneous/InterlockedIncrement/test2/test.cpp [moved from src/pal/tests/palsuite/miscellaneous/InterlockedIncrement/test2/test.c with 100% similarity]
src/pal/tests/palsuite/miscellaneous/InterlockedIncrement64/test1/CMakeLists.txt
src/pal/tests/palsuite/miscellaneous/InterlockedIncrement64/test1/test.cpp [moved from src/pal/tests/palsuite/miscellaneous/InterlockedIncrement64/test1/test.c with 100% similarity]
src/pal/tests/palsuite/miscellaneous/InterlockedIncrement64/test2/CMakeLists.txt
src/pal/tests/palsuite/miscellaneous/InterlockedIncrement64/test2/test.cpp [moved from src/pal/tests/palsuite/miscellaneous/InterlockedIncrement64/test2/test.c with 100% similarity]
src/vm/threads.cpp
src/vm/threads.inl

index d891331..dc630e5 100644 (file)
@@ -32,12 +32,12 @@ Run tests:
 
 > ```bash
 > ~/coreclr$ tests/runtest.sh
->     --testRootDir="~/test/Windows_NT.x64.Debug"
->     --testNativeBinDir="~/coreclr/bin/obj/Linux.x64.Debug/tests"
->     --coreClrBinDir="~/coreclr/bin/Product/Linux.x64.Debug"
->     --mscorlibDir="/media/coreclr/bin/Product/Linux.x64.Debug"
->     --coreFxBinDir="~/corefx/bin/Linux.AnyCPU.Debug"
->     --coreFxNativeBinDir="~/corefx/bin/Linux.x64.Debug"
+>     --testRootDir=~/test/Windows_NT.x64.Debug
+>     --testNativeBinDir=~/coreclr/bin/obj/Linux.x64.Debug/tests
+>     --coreClrBinDir=~/coreclr/bin/Product/Linux.x64.Debug
+>     --mscorlibDir=/media/coreclr/bin/Product/Linux.x64.Debug
+>     --coreFxBinDir=~/corefx/bin/Linux.AnyCPU.Debug
+>     --coreFxNativeBinDir=~/corefx/bin/Linux.x64.Debug
 > ```
 
 Test results will go into:
index 8846f4b..9fa2e35 100644 (file)
@@ -5198,132 +5198,353 @@ typedef EXCEPTION_DISPOSITION (PALAPI *PVECTORED_EXCEPTION_HANDLER)(
 // significant set bit, or 0 if if mask is zero.
 //
 // The same is true for BitScanForward, except that the GCC function is __builtin_ffs.
-
+EXTERN_C
 PALIMPORT
+inline
 unsigned char
 PALAPI
 BitScanForward(
-             IN OUT PDWORD Index,
-             IN UINT qwMask);
+    IN OUT PDWORD Index,
+    IN UINT qwMask)
+{
+    unsigned char bRet = FALSE;
+    int iIndex = __builtin_ffsl(qwMask);
+    if (iIndex != 0)
+    {
+        // Set the Index after deducting unity
+        *Index = (DWORD)(iIndex - 1);
+        bRet = TRUE;
+    }
+
+    return bRet;
+}
 
+EXTERN_C
 PALIMPORT
-LONG
+inline
+unsigned char
 PALAPI
-InterlockedIncrement(
-             IN OUT LONG volatile *lpAddend);
+BitScanForward64(
+    IN OUT PDWORD Index,
+    IN UINT64 qwMask)
+{
+    unsigned char bRet = FALSE;
+    int iIndex = __builtin_ffsl(qwMask);
+    if (iIndex != 0)
+    {
+        // Set the Index after deducting unity
+        *Index = (DWORD)(iIndex - 1);
+        bRet = TRUE;
+    }
+
+    return bRet;
+}
+
+/*++
+Function:
+InterlockedIncrement
+
+The InterlockedIncrement function increments (increases by one) the
+value of the specified variable and checks the resulting value. The
+function prevents more than one thread from using the same variable
+simultaneously.
+
+Parameters
+
+lpAddend 
+[in/out] Pointer to the variable to increment. 
+
+Return Values
 
+The return value is the resulting incremented value. 
+
+--*/
+EXTERN_C
 PALIMPORT
+inline
 LONG
 PALAPI
-InterlockedDecrement(
-             IN OUT LONG volatile *lpAddend);
+InterlockedIncrement(
+    IN OUT LONG volatile *lpAddend)
+{
+    return __sync_add_and_fetch(lpAddend, (LONG)1);
+}
 
+EXTERN_C
 PALIMPORT
-LONG
+inline
+LONGLONG
 PALAPI
-InterlockedExchange(
-            IN OUT LONG volatile *Target,
-            IN LONG Value);
+InterlockedIncrement64(
+    IN OUT LONGLONG volatile *lpAddend)
+{
+    return __sync_add_and_fetch(lpAddend, (LONGLONG)1);
+}
+
+/*++
+Function:
+InterlockedDecrement
+
+The InterlockedDecrement function decrements (decreases by one) the
+value of the specified variable and checks the resulting value. The
+function prevents more than one thread from using the same variable
+simultaneously.
+
+Parameters
 
+lpAddend 
+[in/out] Pointer to the variable to decrement. 
+
+Return Values
+
+The return value is the resulting decremented value.
+
+--*/
+EXTERN_C
 PALIMPORT
+inline
 LONG
 PALAPI
-InterlockedCompareExchange(
-               IN OUT LONG volatile *Destination,
-               IN LONG Exchange,
-               IN LONG Comperand);
+InterlockedDecrement(
+    IN OUT LONG volatile *lpAddend)
+{
+    return __sync_sub_and_fetch(lpAddend, (LONG)1);
+}
 
+EXTERN_C
 PALIMPORT
-LONG
+inline
+LONGLONG
 PALAPI
-InterlockedCompareExchangeAcquire(
-               IN OUT LONG volatile *Destination,
-               IN LONG Exchange,
-               IN LONG Comperand);
+InterlockedDecrement64(
+    IN OUT LONGLONG volatile *lpAddend)
+{
+    return __sync_sub_and_fetch(lpAddend, (LONGLONG)1);
+}
+
+/*++
+Function:
+InterlockedExchange
+
+The InterlockedExchange function atomically exchanges a pair of
+values. The function prevents more than one thread from using the same
+variable simultaneously.
+
+Parameters
+
+Target 
+[in/out] Pointer to the value to exchange. The function sets
+this variable to Value, and returns its prior value.
+Value 
+[in] Specifies a new value for the variable pointed to by Target. 
+
+Return Values
+
+The function returns the initial value pointed to by Target. 
 
+--*/
+EXTERN_C
 PALIMPORT
+inline
 LONG
 PALAPI
-InterlockedCompareExchangeRelease(
-               IN OUT LONG volatile *Destination,
-               IN LONG Exchange,
-               IN LONG Comperand);
-               
+InterlockedExchange(
+    IN OUT LONG volatile *Target,
+    IN LONG Value)
+{
+    return __sync_swap(Target, Value);
+}
+
+EXTERN_C
 PALIMPORT
-LONG
+inline
+LONGLONG
 PALAPI
-InterlockedExchangeAdd(
-               IN OUT LONG volatile *Addend,
-               IN LONG Value);
-               
+InterlockedExchange64(
+    IN OUT LONGLONG volatile *Target,
+    IN LONGLONG Value)
+{
+    return __sync_swap(Target, Value);
+}
+
+/*++
+Function:
+InterlockedCompareExchange
+
+The InterlockedCompareExchange function performs an atomic comparison
+of the specified values and exchanges the values, based on the outcome
+of the comparison. The function prevents more than one thread from
+using the same variable simultaneously.
+
+If you are exchanging pointer values, this function has been
+superseded by the InterlockedCompareExchangePointer function.
+
+Parameters
+
+Destination     [in/out] Specifies the address of the destination value. The sign is ignored.
+Exchange        [in]     Specifies the exchange value. The sign is ignored.
+Comperand       [in]     Specifies the value to compare to Destination. The sign is ignored.
+
+Return Values
+
+The return value is the initial value of the destination.
+
+--*/
+EXTERN_C
 PALIMPORT
+inline
 LONG
 PALAPI
-InterlockedAnd(
-               IN OUT LONG volatile *Destination,
-               IN LONG Value);
+InterlockedCompareExchange(
+    IN OUT LONG volatile *Destination,
+    IN LONG Exchange,
+    IN LONG Comperand)
+{
+    return __sync_val_compare_and_swap(
+        Destination, /* The pointer to a variable whose value is to be compared with. */
+        Comperand, /* The value to be compared */
+        Exchange /* The value to be stored */);
+}
 
+EXTERN_C
 PALIMPORT
+inline
 LONG
 PALAPI
-InterlockedOr(
-              IN OUT LONG volatile *Destination,
-              IN LONG Value);
+InterlockedCompareExchangeAcquire(
+    IN OUT LONG volatile *Destination,
+    IN LONG Exchange,
+    IN LONG Comperand)
+{
+    // TODO: implement the version with only the acquire semantics
+    return __sync_val_compare_and_swap(
+        Destination, /* The pointer to a variable whose value is to be compared with. */
+        Comperand, /* The value to be compared */
+        Exchange /* The value to be stored */);
+}
 
+EXTERN_C
 PALIMPORT
-UCHAR
+inline
+LONG
 PALAPI
-InterlockedBitTestAndReset(
-               IN OUT LONG volatile *Base,
-               IN LONG Bit);
+InterlockedCompareExchangeRelease(
+    IN OUT LONG volatile *Destination,
+    IN LONG Exchange,
+    IN LONG Comperand)
+{
+    // TODO: implement the version with only the release semantics
+    return __sync_val_compare_and_swap(
+        Destination, /* The pointer to a variable whose value is to be compared with. */
+        Comperand, /* The value to be compared */
+        Exchange /* The value to be stored */);
+}
 
+// See the 32-bit variant in interlock2.s
+EXTERN_C
 PALIMPORT
-UCHAR
+inline
+LONGLONG
 PALAPI
-InterlockedBitTestAndSet(
-               IN OUT LONG volatile *Base,
-               IN LONG Bit);
+InterlockedCompareExchange64(
+    IN OUT LONGLONG volatile *Destination,
+    IN LONGLONG Exchange,
+    IN LONGLONG Comperand)
+{
+    return __sync_val_compare_and_swap(
+        Destination, /* The pointer to a variable whose value is to be compared with. */
+        Comperand, /* The value to be compared */
+        Exchange /* The value to be stored */);
+}
+
+/*++
+Function:
+InterlockedExchangeAdd
+
+The InterlockedExchangeAdd function atomically adds the value of 'Value'
+to the variable that 'Addend' points to.
+
+Parameters
 
+lpAddend
+[in/out] Pointer to the variable to to added.
+
+Return Values
+
+The return value is the original value that 'Addend' pointed to.
+
+--*/
+EXTERN_C
 PALIMPORT
-unsigned char
+inline
+LONG
 PALAPI
-BitScanForward64(
-             IN OUT PDWORD Index,
-             IN UINT64 qwMask);
+InterlockedExchangeAdd(
+    IN OUT LONG volatile *Addend,
+    IN LONG Value)
+{
+    return __sync_fetch_and_add(Addend, Value);
+}
 
+EXTERN_C
 PALIMPORT
+inline
 LONGLONG
 PALAPI
-InterlockedIncrement64(
-             IN OUT LONGLONG volatile *lpAddend);
+InterlockedExchangeAdd64(
+    IN OUT LONGLONG volatile *Addend,
+    IN LONGLONG Value)
+{
+    return __sync_fetch_and_add(Addend, Value);
+}
 
+EXTERN_C
 PALIMPORT
-LONGLONG
+inline
+LONG
 PALAPI
-InterlockedDecrement64(
-             IN OUT LONGLONG volatile *lpAddend);
+InterlockedAnd(
+    IN OUT LONG volatile *Destination,
+    IN LONG Value)
+{
+    return __sync_fetch_and_and(Destination, Value);
+}
 
+EXTERN_C
 PALIMPORT
-LONGLONG
+inline
+LONG
 PALAPI
-InterlockedExchange64(
-            IN OUT LONGLONG volatile *Target,
-            IN LONGLONG Value);
-            
+InterlockedOr(
+    IN OUT LONG volatile *Destination,
+    IN LONG Value)
+{
+    return __sync_fetch_and_or(Destination, Value);
+}
+
+EXTERN_C
 PALIMPORT
-LONGLONG
+inline
+UCHAR
 PALAPI
-InterlockedExchangeAdd64(
-               IN OUT LONGLONG volatile *Addend,
-               IN LONGLONG Value);
+InterlockedBitTestAndReset(
+    IN OUT LONG volatile *Base,
+    IN LONG Bit)
+{
+    return (InterlockedAnd(Base, ~(1 << Bit)) & (1 << Bit)) != 0;
+}
 
+EXTERN_C
 PALIMPORT
-LONGLONG
+inline
+UCHAR
 PALAPI
-InterlockedCompareExchange64(
-               IN OUT LONGLONG volatile *Destination,
-               IN LONGLONG Exchange,
-               IN LONGLONG Comperand);
+InterlockedBitTestAndSet(
+    IN OUT LONG volatile *Base,
+    IN LONG Bit)
+{
+    return (InterlockedOr(Base, (1 << Bit)) & (1 << Bit)) != 0;
+}
 
 #if defined(BIT64)
 #define InterlockedExchangePointer(Target, Value) \
@@ -5339,11 +5560,23 @@ InterlockedCompareExchange64(
     ((PVOID)(UINT_PTR)InterlockedCompareExchange((PLONG)(UINT_PTR)(Destination), (LONG)(UINT_PTR)(ExChange), (LONG)(UINT_PTR)(Comperand)))
 #endif
 
+/*++
+Function:
+MemoryBarrier
+
+The MemoryBarrier function creates a full memory barrier.
+
+--*/
+EXTERN_C
 PALIMPORT
+inline
 VOID
 PALAPI
 MemoryBarrier(
-    VOID);
+    VOID)
+{
+    __sync_synchronize();
+}
 
 PALIMPORT
 VOID
@@ -5912,13 +6145,47 @@ inline WCHAR *PAL_wcsstr(WCHAR *_S, const WCHAR *_P)
 }
 #endif
 
-PALIMPORT unsigned int __cdecl _rotl(unsigned int, int);
+/*++
+Function:
+_rotl
+
+See MSDN doc.
+--*/
+EXTERN_C
+PALIMPORT
+inline
+unsigned int __cdecl _rotl(unsigned int value, int shift)
+{
+    unsigned int retval = 0;
+
+    shift &= 0x1f;
+    retval = (value << shift) | (value >> (sizeof(int) * CHAR_BIT - shift));
+    return retval;
+}
+
 // On 64 bit unix, make the long an int.
 #ifdef BIT64
 #define _lrotl _rotl
 #endif // BIT64
 
-PALIMPORT unsigned int __cdecl _rotr(unsigned int, int);
+/*++
+Function:
+_rotr
+
+See MSDN doc.
+--*/
+EXTERN_C
+PALIMPORT
+inline
+unsigned int __cdecl _rotr(unsigned int value, int shift)
+{
+    unsigned int retval;
+
+    shift &= 0x1f;
+    retval = (value >> shift) | (value << (sizeof(int) * CHAR_BIT - shift));
+    return retval;
+}
+
 PALIMPORT int __cdecl abs(int);
 PALIMPORT double __cdecl fabs(double); 
 #ifndef PAL_STDCPP_COMPAT
index f1a2546..03b3ea6 100644 (file)
@@ -135,7 +135,6 @@ set(SOURCES
   misc/error.cpp
   misc/errorstrings.cpp
   misc/fmtmessage.cpp
-  misc/interlock.cpp
   misc/miscpalapi.cpp
   misc/msgbox.cpp
   misc/strutil.cpp
index 2c48214..fa8504f 100644 (file)
@@ -72,48 +72,6 @@ namespace CorUnix
 
 /*++
 Function:
-  _rotl
-
-See MSDN doc.
---*/
-unsigned int
-__cdecl 
-_rotl( unsigned int value, int shift )
-{
-    unsigned int retval = 0;
-
-    PERF_ENTRY(_rotl);
-    ENTRY("_rotl( value:%u shift=%d )\n", value, shift );   
-    shift &= 0x1f;
-    retval = ( value << shift ) | ( value >> ( sizeof( int ) * CHAR_BIT - shift ));
-    LOGEXIT("_rotl returns unsigned int %u\n", retval);
-    PERF_EXIT(_rotl);
-    return retval;
-}
-
-/*++
-Function:
-  _rotr
-
-See MSDN doc.
---*/
-unsigned int
-__cdecl 
-_rotr( unsigned int value, int shift )
-{
-    unsigned int retval;
-
-    PERF_ENTRY(_rotr);
-    ENTRY("_rotr( value:%u shift=%d )\n", value, shift );    
-    shift &= 0x1f;
-    retval = ( value >> shift ) | ( value << ( sizeof( int ) * CHAR_BIT - shift ) );
-    LOGEXIT("_rotr returns unsigned int %u\n", retval);
-    PERF_EXIT(_rotr);
-    return retval;
-}
-
-/*++
-Function:
   _gcvt_s
 
 See MSDN doc.
diff --git a/src/pal/src/misc/interlock.cpp b/src/pal/src/misc/interlock.cpp
deleted file mode 100644 (file)
index c63566a..0000000
+++ /dev/null
@@ -1,305 +0,0 @@
-//
-// Copyright (c) Microsoft. All rights reserved.
-// Licensed under the MIT license. See LICENSE file in the project root for full license information. 
-//
-
-/*++
-
-
-
-Module Name:
-
-    interlock.c
-
-Abstract:
-
-    Implementation of Interlocked functions for the Intel x86
-    platform. These functions are processor dependent.
-
-
-
---*/
-
-#include "pal/palinternal.h"
-
-
-//
-// We need the following methods to have volatile arguments for compatibility with Win32
-//
-#undef volatile
-
-
-/*++
-Function:
-  InterlockedIncrement
-
-The InterlockedIncrement function increments (increases by one) the
-value of the specified variable and checks the resulting value. The
-function prevents more than one thread from using the same variable
-simultaneously.
-
-Parameters
-
-lpAddend 
-       [in/out] Pointer to the variable to increment. 
-
-Return Values
-
-The return value is the resulting incremented value. 
-
---*/
-LONG
-PALAPI
-InterlockedIncrement(
-             IN OUT LONG volatile *lpAddend)
-{
-    return __sync_add_and_fetch(lpAddend, (LONG)1);
-}
-
-LONGLONG
-PALAPI
-InterlockedIncrement64(
-             IN OUT LONGLONG volatile *lpAddend)
-{
-    return __sync_add_and_fetch(lpAddend, (LONGLONG)1);
-}
-
-/*++
-Function:
-  InterlockedDecrement
-
-The InterlockedDecrement function decrements (decreases by one) the
-value of the specified variable and checks the resulting value. The
-function prevents more than one thread from using the same variable
-simultaneously.
-
-Parameters
-
-lpAddend 
-       [in/out] Pointer to the variable to decrement. 
-
-Return Values
-
-The return value is the resulting decremented value.
-
---*/
-LONG
-PALAPI
-InterlockedDecrement(
-             IN OUT LONG volatile *lpAddend)
-{
-    return __sync_sub_and_fetch(lpAddend, (LONG)1);
-}
-
-LONGLONG
-PALAPI
-InterlockedDecrement64(
-             IN OUT LONGLONG volatile *lpAddend)
-{
-    return __sync_sub_and_fetch(lpAddend, (LONGLONG)1);
-}
-
-/*++
-Function:
-  InterlockedExchange
-
-The InterlockedExchange function atomically exchanges a pair of
-values. The function prevents more than one thread from using the same
-variable simultaneously.
-
-Parameters
-
-Target 
-       [in/out] Pointer to the value to exchange. The function sets
-       this variable to Value, and returns its prior value.
-Value 
-       [in] Specifies a new value for the variable pointed to by Target. 
-
-Return Values
-
-The function returns the initial value pointed to by Target. 
-
---*/
-LONG
-PALAPI
-InterlockedExchange(
-            IN OUT LONG volatile *Target,
-            IN LONG Value)
-{
-    return __sync_swap(Target, Value);
-}
-
-LONGLONG
-PALAPI
-InterlockedExchange64(
-            IN OUT LONGLONG volatile *Target,
-            IN LONGLONG Value)
-{
-    return __sync_swap(Target, Value);
-}
-
-/*++
-Function:
-  InterlockedCompareExchange
-
-The InterlockedCompareExchange function performs an atomic comparison
-of the specified values and exchanges the values, based on the outcome
-of the comparison. The function prevents more than one thread from
-using the same variable simultaneously.
-
-If you are exchanging pointer values, this function has been
-superseded by the InterlockedCompareExchangePointer function.
-
-Parameters
-
-Destination     [in/out] Specifies the address of the destination value. The sign is ignored. 
-Exchange        [in]     Specifies the exchange value. The sign is ignored. 
-Comperand       [in]     Specifies the value to compare to Destination. The sign is ignored. 
-
-Return Values
-
-The return value is the initial value of the destination.
-
---*/
-LONG
-PALAPI
-InterlockedCompareExchange(
-               IN OUT LONG volatile *Destination,
-               IN LONG Exchange,
-               IN LONG Comperand)
-{
-    return __sync_val_compare_and_swap(
-        Destination, /* The pointer to a variable whose value is to be compared with. */
-        Comperand, /* The value to be compared */
-        Exchange /* The value to be stored */);
-}
-
-LONG
-PALAPI
-InterlockedCompareExchangeAcquire(
-               IN OUT LONG volatile *Destination,
-               IN LONG Exchange,
-               IN LONG Comperand)
-{
-    // TODO: implement the version with only the acquire semantics
-    return __sync_val_compare_and_swap(
-        Destination, /* The pointer to a variable whose value is to be compared with. */
-        Comperand, /* The value to be compared */
-        Exchange /* The value to be stored */);
-}
-
-LONG
-PALAPI
-InterlockedCompareExchangeRelease(
-               IN OUT LONG volatile *Destination,
-               IN LONG Exchange,
-               IN LONG Comperand)
-{
-    // TODO: implement the version with only the release semantics
-    return __sync_val_compare_and_swap(
-        Destination, /* The pointer to a variable whose value is to be compared with. */
-        Comperand, /* The value to be compared */
-        Exchange /* The value to be stored */);
-}
-               
-// See the 32-bit variant in interlock2.s
-LONGLONG
-PALAPI
-InterlockedCompareExchange64(
-               IN OUT LONGLONG volatile *Destination,
-               IN LONGLONG Exchange,
-               IN LONGLONG Comperand)
-{
-    return __sync_val_compare_and_swap(
-        Destination, /* The pointer to a variable whose value is to be compared with. */
-        Comperand, /* The value to be compared */
-        Exchange /* The value to be stored */);
-}
-
-/*++
-Function:
-InterlockedExchangeAdd
-
-The InterlockedExchangeAdd function atomically adds the value of 'Value'
-to the variable that 'Addend' points to.
-
-Parameters
-
-lpAddend
-[in/out] Pointer to the variable to to added.
-
-Return Values
-
-The return value is the original value that 'Addend' pointed to.
-
---*/
-LONG
-PALAPI
-InterlockedExchangeAdd(
-               IN OUT LONG volatile *Addend,
-               IN LONG Value)
-{
-    return __sync_fetch_and_add(Addend, Value);
-}
-
-LONGLONG
-PALAPI
-InterlockedExchangeAdd64(
-               IN OUT LONGLONG volatile *Addend,
-               IN LONGLONG Value)
-{
-    return __sync_fetch_and_add(Addend, Value);
-}
-             
-LONG
-PALAPI
-InterlockedAnd(
-               IN OUT LONG volatile *Destination,
-               IN LONG Value)
-{
-    return __sync_fetch_and_and(Destination, Value);
-}
-              
-LONG
-PALAPI
-InterlockedOr(
-              IN OUT LONG volatile *Destination,
-              IN LONG Value)
-{
-    return __sync_fetch_and_or(Destination, Value);
-}
-
-UCHAR
-PALAPI
-InterlockedBitTestAndReset(
-               IN OUT LONG volatile *Base,
-               IN LONG Bit)
-{
-    return (InterlockedAnd(Base, ~(1 << Bit)) & (1 << Bit)) != 0;
-}
-
-UCHAR
-PALAPI
-InterlockedBitTestAndSet(
-               IN OUT LONG volatile *Base,
-               IN LONG Bit)
-{
-    return (InterlockedOr(Base, (1 << Bit)) & (1 << Bit)) != 0;
-}
-
-/*++
-Function:
-MemoryBarrier
-
-The MemoryBarrier function creates a full memory barrier.
-
---*/
-void
-PALAPI
-MemoryBarrier(
-    VOID)
-{
-    __sync_synchronize();
-}
-
-#define volatile DoNotUseVolatileKeyword
index 0aeeb89..9f3750e 100644 (file)
@@ -159,51 +159,6 @@ PAL_GetPALDirectoryA(
     return bRet;
 }
 
-// Define _BitScanForward64 and BitScanForward
-// Per MSDN, BitScanForward64 will search the mask data from LSB to MSB for a set bit.
-// If one is found, its bit position is returned in the outPDWORD argument and 1 is returned.
-// Otherwise, 0 is returned.
-//
-// On GCC, the equivalent function is __builtin_ffsl. It returns 1+index of the least
-// significant set bit, or 0 if if mask is zero.
-unsigned char
-PALAPI
-BitScanForward64(
-        IN OUT PDWORD Index,
-        IN UINT64 qwMask)
-{
-    unsigned char bRet = FALSE;
-    int iIndex = __builtin_ffsl(qwMask);
-    if (iIndex != 0)
-    {
-        // Set the Index after deducting unity
-        *Index = (DWORD)(iIndex-1);
-        bRet = TRUE;
-    }
-
-    return bRet;
-}
-
-// On GCC, the equivalent function is __builtin_ffs. It returns 1+index of the least
-// significant set bit, or 0 if if mask is zero.
-unsigned char
-PALAPI
-BitScanForward(
-        IN OUT PDWORD Index,
-        IN UINT wMask)
-{
-    unsigned char bRet = FALSE;
-    int iIndex = __builtin_ffs(wMask);
-    if (iIndex != 0)
-    {
-        // Set the Index after deducting unity
-        *Index = (DWORD)(iIndex-1);
-        bRet = TRUE;
-    }
-    
-    return bRet;
-}
-
 BOOL
 PALAPI
 PAL_Random(
index fdf177c..bafaa23 100644 (file)
@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2)
 set(CMAKE_INCLUDE_CURRENT_DIR ON)
 
 set(SOURCES
-  test1.c
+  test1.cpp
 )
 
 add_executable(paltest_rotl_test1
index 563d66b..c0c76fe 100644 (file)
@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2)
 set(CMAKE_INCLUDE_CURRENT_DIR ON)
 
 set(SOURCES
-  test1.c
+  test1.cpp
 )
 
 add_executable(paltest_rotr_test1
index 6a94623..e5ba709 100644 (file)
@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2)
 set(CMAKE_INCLUDE_CURRENT_DIR ON)
 
 set(SOURCES
-  test.c
+  test.cpp
 )
 
 add_executable(paltest_interlockedexchangeadd_test1
index 3dc8f29..a70802e 100644 (file)
@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2)
 set(CMAKE_INCLUDE_CURRENT_DIR ON)
 
 set(SOURCES
-  test.c
+  test.cpp
 )
 
 add_executable(paltest_interlockedbit_test1
@@ -24,12 +24,12 @@ typedef struct tag_TEST_DATA
 
 TEST_DATA test_data[] =
 {
-    { 0x00000000,  3, 0x00000000, 0 },
-    { 0x12341234,  2, 0x12341230, 1 },
-    { 0x12341234,  3, 0x12341234, 0 },
-    { 0x12341234, 31, 0x12341234, 0 },
-    { 0x12341234, 28, 0x02341234, 1 },
-    { 0xffffffff, 28, 0xefffffff, 1 }
+    { (LONG)0x00000000,  3, (LONG)0x00000000, 0 },
+    { (LONG)0x12341234,  2, (LONG)0x12341230, 1 },
+    { (LONG)0x12341234,  3, (LONG)0x12341234, 0 },
+    { (LONG)0x12341234, 31, (LONG)0x12341234, 0 },
+    { (LONG)0x12341234, 28, (LONG)0x02341234, 1 },
+    { (LONG)0xffffffff, 28, (LONG)0xefffffff, 1 }
 };
 
 int __cdecl main(int argc, char *argv[]) {
index 64d6581..6b50a75 100644 (file)
@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2)
 set(CMAKE_INCLUDE_CURRENT_DIR ON)
 
 set(SOURCES
-  test.c
+  test.cpp
 )
 
 add_executable(paltest_interlockedbit_test2
@@ -24,12 +24,12 @@ typedef struct tag_TEST_DATA
 
 TEST_DATA test_data[] =
 {
-    { 0x00000000,  2, 0x00000004, 0 },
-    { 0x12341234,  2, 0x12341234, 1 },
-    { 0x12341234,  3, 0x1234123c, 0 },
-    { 0x12341234, 31, 0x92341234, 0 },
-    { 0x12341234, 28, 0x12341234, 1 },
-    { 0xffffffff, 28, 0xffffffff, 1 }
+    { (LONG)0x00000000,  2, (LONG)0x00000004, 0 },
+    { (LONG)0x12341234,  2, (LONG)0x12341234, 1 },
+    { (LONG)0x12341234,  3, (LONG)0x1234123c, 0 },
+    { (LONG)0x12341234, 31, (LONG)0x92341234, 0 },
+    { (LONG)0x12341234, 28, (LONG)0x12341234, 1 },
+    { (LONG)0xffffffff, 28, (LONG)0xffffffff, 1 }
 };
 
 int __cdecl main(int argc, char *argv[]) {
index a3f4f74..d9e8672 100644 (file)
@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2)
 set(CMAKE_INCLUDE_CURRENT_DIR ON)
 
 set(SOURCES
-  test.c
+  test.cpp
 )
 
 add_executable(paltest_interlockedcompareexchange_test1
index fdf0521..038d375 100644 (file)
@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2)
 set(CMAKE_INCLUDE_CURRENT_DIR ON)
 
 set(SOURCES
-  test.c
+  test.cpp
 )
 
 add_executable(paltest_interlockedcompareexchange_test2
index 6000db2..722603e 100644 (file)
@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2)
 set(CMAKE_INCLUDE_CURRENT_DIR ON)
 
 set(SOURCES
-  test.c
+  test.cpp
 )
 
 add_executable(paltest_interlockedcompareexchange64_test1
index 2a82236..f052ca0 100644 (file)
@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2)
 set(CMAKE_INCLUDE_CURRENT_DIR ON)
 
 set(SOURCES
-  test.c
+  test.cpp
 )
 
 add_executable(paltest_interlockedcompareexchange64_test2
@@ -52,7 +52,7 @@ int __cdecl main(int argc, char *argv[])
        (5 in this case) 
     */
   
-    if((int)ReturnValue != 5) 
+    if((int)(size_t)ReturnValue != 5) 
     {
         Fail("ERROR: The return value should be the value of the "
              "variable before the exchange took place, which was 5.  "
index 8b6fbfd..6cd307d 100644 (file)
@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2)
 set(CMAKE_INCLUDE_CURRENT_DIR ON)
 
 set(SOURCES
-  test.c
+  test.cpp
 )
 
 add_executable(paltest_interlockeddecrement_test1
index 320019e..331d89d 100644 (file)
@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2)
 set(CMAKE_INCLUDE_CURRENT_DIR ON)
 
 set(SOURCES
-  test.c
+  test.cpp
 )
 
 add_executable(paltest_interlockeddecrement_test2
index c942a33..727a328 100644 (file)
@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2)
 set(CMAKE_INCLUDE_CURRENT_DIR ON)
 
 set(SOURCES
-  test.c
+  test.cpp
 )
 
 add_executable(paltest_interlockeddecrement64_test1
index d5462ca..ecea639 100644 (file)
@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2)
 set(CMAKE_INCLUDE_CURRENT_DIR ON)
 
 set(SOURCES
-  test.c
+  test.cpp
 )
 
 add_executable(paltest_interlockeddecrement64_test2
index 39911d2..a1a7f86 100644 (file)
@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2)
 set(CMAKE_INCLUDE_CURRENT_DIR ON)
 
 set(SOURCES
-  test.c
+  test.cpp
 )
 
 add_executable(paltest_interlockedexchange_test1
index 832868e..3f4cd5e 100644 (file)
@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2)
 set(CMAKE_INCLUDE_CURRENT_DIR ON)
 
 set(SOURCES
-  test.c
+  test.cpp
 )
 
 add_executable(paltest_interlockedexchange64_test1
index e43533d..b085896 100644 (file)
@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2)
 set(CMAKE_INCLUDE_CURRENT_DIR ON)
 
 set(SOURCES
-  InterlockedExchangePointer.c
+  InterlockedExchangePointer.cpp
 )
 
 add_executable(paltest_interlockedexchangepointer_test1
index 258d4bc..f87dc72 100644 (file)
@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2)
 set(CMAKE_INCLUDE_CURRENT_DIR ON)
 
 set(SOURCES
-  test.c
+  test.cpp
 )
 
 add_executable(paltest_interlockedincrement_test1
index 124f95a..e8c5278 100644 (file)
@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2)
 set(CMAKE_INCLUDE_CURRENT_DIR ON)
 
 set(SOURCES
-  test.c
+  test.cpp
 )
 
 add_executable(paltest_interlockedincrement_test2
index 2520ac5..d7bec46 100644 (file)
@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2)
 set(CMAKE_INCLUDE_CURRENT_DIR ON)
 
 set(SOURCES
-  test.c
+  test.cpp
 )
 
 add_executable(paltest_interlockedincrement64_test1
index 4d85e40..be571a5 100644 (file)
@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8.12.2)
 set(CMAKE_INCLUDE_CURRENT_DIR ON)
 
 set(SOURCES
-  test.c
+  test.cpp
 )
 
 add_executable(paltest_interlockedincrement64_test2
index 5e4c05f..2be41fc 100644 (file)
@@ -328,16 +328,6 @@ GVAL_IMPL_INIT(DWORD, gAppDomainTLSIndex, TLS_OUT_OF_INDEXES);   // index ( (-1)
 
 #ifndef DACCESS_COMPILE
 #ifdef FEATURE_IMPLICIT_TLS
-EXTERN_C Thread* STDCALL GetThread()
-{
-    return gCurrentThreadInfo.m_pThread;
-}
-
-EXTERN_C AppDomain* STDCALL GetAppDomain()
-{
-    return gCurrentThreadInfo.m_pAppDomain;
-}
-
 BOOL SetThread(Thread* t)
 {
        LIMITED_METHOD_CONTRACT
index d3d3405..db47ce8 100644 (file)
 #include "appdomain.hpp"
 #include "frames.h"
 
+#ifndef DACCESS_COMPILE
+#ifdef FEATURE_IMPLICIT_TLS
+
+#ifndef __llvm__
+EXTERN_C __declspec(thread) ThreadLocalInfo gCurrentThreadInfo;
+#else // !__llvm__
+EXTERN_C __thread ThreadLocalInfo gCurrentThreadInfo;
+#endif // !__llvm__
+
+EXTERN_C inline Thread* STDCALL GetThread()
+{
+    return gCurrentThreadInfo.m_pThread;
+}
+
+EXTERN_C inline AppDomain* STDCALL GetAppDomain()
+{
+    return gCurrentThreadInfo.m_pAppDomain;
+}
+
+#endif // FEATURE_IMPLICIT_TLS
+#endif // !DACCESS_COMPILE
+
 #ifdef ENABLE_GET_THREAD_GENERIC_FULL_CHECK
 // See code:GetThreadGenericFullCheck
 inline /* static */ BOOL Thread::ShouldEnforceEEThreadNotRequiredContracts()