ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

interlocked.h
Go to the documentation of this file.
00001 /******************************************************************************
00002  *                           INTERLOCKED Functions                            *
00003  ******************************************************************************/
00004 //
00005 // Intrinsics (note: taken from our winnt.h)
00006 // FIXME: 64-bit
00007 //
00008 #if defined(__GNUC__)
00009 
00010 static __inline__ BOOLEAN
00011 InterlockedBitTestAndSet(
00012     _Inout_updates_bytes_((Bit+7)/8) _Interlocked_operand_ LONG volatile *Base,
00013     _In_ LONG Bit)
00014 {
00015 #if defined(_M_IX86)
00016   LONG OldBit;
00017   __asm__ __volatile__("lock "
00018                        "btsl %2,%1\n\t"
00019                        "sbbl %0,%0\n\t"
00020                        :"=r" (OldBit),"+m" (*Base)
00021                        :"Ir" (Bit)
00022                        : "memory");
00023   return OldBit;
00024 #else
00025   return (_InterlockedOr(Base, 1 << Bit) >> Bit) & 1;
00026 #endif
00027 }
00028 
00029 static __inline__ BOOLEAN
00030 InterlockedBitTestAndReset(
00031     _Inout_updates_bytes_((Bit+7)/8) _Interlocked_operand_ LONG volatile *Base,
00032     _In_ LONG Bit)
00033 {
00034 #if defined(_M_IX86)
00035   LONG OldBit;
00036   __asm__ __volatile__("lock "
00037                        "btrl %2,%1\n\t"
00038                        "sbbl %0,%0\n\t"
00039                        :"=r" (OldBit),"+m" (*Base)
00040                        :"Ir" (Bit)
00041                        : "memory");
00042   return OldBit;
00043 #else
00044   return (_InterlockedAnd(Base, ~(1 << Bit)) >> Bit) & 1;
00045 #endif
00046 }
00047 
00048 #endif /* defined(__GNUC__) */
00049 
00050 #define BitScanForward _BitScanForward
00051 #define BitScanReverse _BitScanReverse
00052 #define BitTest _bittest
00053 #define BitTestAndComplement _bittestandcomplement
00054 #define BitTestAndSet _bittestandset
00055 #define BitTestAndReset _bittestandreset
00056 #define InterlockedBitTestAndSet _interlockedbittestandset
00057 #define InterlockedBitTestAndReset _interlockedbittestandreset
00058 
00059 #ifdef _M_AMD64
00060 #define BitTest64 _bittest64
00061 #define BitTestAndComplement64 _bittestandcomplement64
00062 #define BitTestAndSet64 _bittestandset64
00063 #define BitTestAndReset64 _bittestandreset64
00064 #define InterlockedBitTestAndSet64 _interlockedbittestandset64
00065 #define InterlockedBitTestAndReset64 _interlockedbittestandreset64
00066 #endif
00067 
00068 #if !defined(__INTERLOCKED_DECLARED)
00069 #define __INTERLOCKED_DECLARED
00070 
00071 #if defined (_X86_)
00072 #if defined(NO_INTERLOCKED_INTRINSICS)
00073 NTKERNELAPI
00074 LONG
00075 FASTCALL
00076 InterlockedIncrement(
00077     _Inout_ _Interlocked_operand_ LONG volatile *Addend);
00078 
00079 NTKERNELAPI
00080 LONG
00081 FASTCALL
00082 InterlockedDecrement(
00083     _Inout_ _Interlocked_operand_ LONG volatile *Addend);
00084 
00085 NTKERNELAPI
00086 LONG
00087 FASTCALL
00088 InterlockedCompareExchange(
00089     _Inout_ _Interlocked_operand_ LONG volatile *Destination,
00090   _In_ LONG Exchange,
00091   _In_ LONG Comparand);
00092 
00093 NTKERNELAPI
00094 LONG
00095 FASTCALL
00096 InterlockedExchange(
00097     _Inout_ _Interlocked_operand_ LONG volatile *Destination,
00098     _In_ LONG Value);
00099 
00100 NTKERNELAPI
00101 LONG
00102 FASTCALL
00103 InterlockedExchangeAdd(
00104     _Inout_ _Interlocked_operand_ LONG volatile *Addend,
00105     _In_ LONG Value);
00106 
00107 #else /* !defined(NO_INTERLOCKED_INTRINSICS) */
00108 
00109 #define InterlockedExchange _InterlockedExchange
00110 #define InterlockedIncrement _InterlockedIncrement
00111 #define InterlockedDecrement _InterlockedDecrement
00112 #define InterlockedExchangeAdd _InterlockedExchangeAdd
00113 #define InterlockedCompareExchange _InterlockedCompareExchange
00114 #define InterlockedOr _InterlockedOr
00115 #define InterlockedAnd _InterlockedAnd
00116 #define InterlockedXor _InterlockedXor
00117 
00118 #endif /* !defined(NO_INTERLOCKED_INTRINSICS) */
00119 
00120 #endif /* defined (_X86_) */
00121 
00122 #if !defined (_WIN64)
00123 /*
00124  * PVOID
00125  * InterlockedExchangePointer(
00126  *   IN OUT PVOID volatile  *Target,
00127  *   IN PVOID  Value)
00128  */
00129 #define InterlockedExchangePointer(Target, Value) \
00130   ((PVOID) InterlockedExchange((PLONG) Target, (LONG) Value))
00131 
00132 /*
00133  * PVOID
00134  * InterlockedCompareExchangePointer(
00135  *   IN OUT PVOID  *Destination,
00136  *   IN PVOID  Exchange,
00137  *   IN PVOID  Comparand)
00138  */
00139 #define InterlockedCompareExchangePointer(Destination, Exchange, Comparand) \
00140   ((PVOID) InterlockedCompareExchange((PLONG) Destination, (LONG) Exchange, (LONG) Comparand))
00141 
00142 #define InterlockedExchangeAddSizeT(a, b) InterlockedExchangeAdd((LONG *)a, b)
00143 #define InterlockedIncrementSizeT(a) InterlockedIncrement((LONG *)a)
00144 #define InterlockedDecrementSizeT(a) InterlockedDecrement((LONG *)a)
00145 
00146 #endif // !defined (_WIN64)
00147 
00148 #if defined (_M_AMD64)
00149 
00150 #define InterlockedExchangeAddSizeT(a, b) InterlockedExchangeAdd64((LONGLONG *)a, (LONGLONG)b)
00151 #define InterlockedIncrementSizeT(a) InterlockedIncrement64((LONGLONG *)a)
00152 #define InterlockedDecrementSizeT(a) InterlockedDecrement64((LONGLONG *)a)
00153 #define InterlockedAnd _InterlockedAnd
00154 #define InterlockedOr _InterlockedOr
00155 #define InterlockedXor _InterlockedXor
00156 #define InterlockedIncrement _InterlockedIncrement
00157 #define InterlockedDecrement _InterlockedDecrement
00158 #define InterlockedAdd _InterlockedAdd
00159 #define InterlockedExchange _InterlockedExchange
00160 #define InterlockedExchangeAdd _InterlockedExchangeAdd
00161 #define InterlockedCompareExchange _InterlockedCompareExchange
00162 #define InterlockedAnd64 _InterlockedAnd64
00163 #define InterlockedOr64 _InterlockedOr64
00164 #define InterlockedXor64 _InterlockedXor64
00165 #define InterlockedIncrement64 _InterlockedIncrement64
00166 #define InterlockedDecrement64 _InterlockedDecrement64
00167 #define InterlockedAdd64 _InterlockedAdd64
00168 #define InterlockedExchange64 _InterlockedExchange64
00169 #define InterlockedExchangeAdd64 _InterlockedExchangeAdd64
00170 #define InterlockedCompareExchange64 _InterlockedCompareExchange64
00171 #define InterlockedCompareExchangePointer _InterlockedCompareExchangePointer
00172 #define InterlockedExchangePointer _InterlockedExchangePointer
00173 #define InterlockedBitTestAndSet64 _interlockedbittestandset64
00174 #define InterlockedBitTestAndReset64 _interlockedbittestandreset64
00175 
00176 #endif // _M_AMD64
00177 
00178 #if defined(_M_AMD64) && !defined(RC_INVOKED) && !defined(MIDL_PASS)
00179 //#if !defined(_X86AMD64_) // FIXME: what's _X86AMD64_ used for?
00180 FORCEINLINE
00181 LONG64
00182 InterlockedAdd64(
00183     _Inout_ _Interlocked_operand_ LONG64 volatile *Addend,
00184     _In_ LONG64 Value)
00185 {
00186   return InterlockedExchangeAdd64(Addend, Value) + Value;
00187 }
00188 //#endif
00189 #endif
00190 
00191 #endif /* !__INTERLOCKED_DECLARED */
00192 
00193 

Generated on Sat May 26 2012 04:32:14 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.