Ejemplo n.º 1
0
int __cdecl main(int argc, char *argv[]) 
{
    LONGLONG TheValue = 0;
    LONGLONG TheReturn;
  
    /*
     * Initialize the PAL and return FAILURE if this fails
     */

    if(0 != (PAL_Initialize(argc, argv)))
    {
        return FAIL;
    }

/*
**  Run only on 64 bit platforms
*/
#if defined(BIT64) && defined(PLATFORM_UNIX)
    /* Compare START_VALUE with BaseVariableToManipulate, they're equal, 
       so exchange 
    */
    InterlockedDecrement64(&TheValue);
    TheReturn = InterlockedDecrement64(&TheValue);

    /* Decremented twice, it should be -2 now */
    if(TheValue != -2) 
    {
#ifdef PLATFORM_UNIX
        Fail("ERROR: After being decremented twice, the value should be -2, "
             "but it is really %ll.",TheValue);
#else
        Fail("ERROR: After being decremented twice, the value should be -2, "
             "but it is really %I64.",TheValue);
#endif
    }
  
    /* Check to make sure it returns itself */
    if(TheReturn != TheValue) 
    {
#ifdef PLATFORM_UNIX
        Fail("ERROR: The function should have returned the new value of %d "
             "but instead returned %ll.",TheValue,TheReturn);    
#else
        Fail("ERROR: After being decremented twice, the value should be -2, "
             "but it is really %I64.",TheValue);
#endif
    }
#endif  //defined(BIT64) && defined(PLATFORM_UNIX)
    PAL_Terminate();
    return PASS; 
} 
Ejemplo n.º 2
0
INLINE int64_t CompleteDrawContext(SWR_CONTEXT* pContext, DRAW_CONTEXT* pDC)
{
    int64_t result = InterlockedDecrement64(&pDC->threadsDone);
    SWR_ASSERT(result >= 0);

    if (result == 0)
    {
        // Cleanup memory allocations
        pDC->pArena->Reset(true);
        if (!pDC->isCompute)
        {
            pDC->pTileMgr->initialize();
        }
        if (pDC->cleanupState)
        {
            pDC->pState->pArena->Reset(true);
        }

        _ReadWriteBarrier();

        pContext->dcRing.Dequeue();  // Remove from tail
    }

    return result;
}
Ejemplo n.º 3
0
            int64_t Atomics::DecrementAndGet64(int64_t* ptr)
            {
#ifdef _WIN64
                return InterlockedDecrement64(reinterpret_cast<LONG64*>(ptr));
#else 
                while (true)
                {
                    int64_t expVal = *ptr;
                    int64_t newVal = expVal - 1;

                    if (CompareAndSet64(ptr, expVal, newVal))
                        return newVal;
                }
#endif
            }
Ejemplo n.º 4
0
void *mempool_node_get(mempool p)
{
    struct node *node;
    int64 num_used;

    if(p->num_nodes_free < p->elem_realloc_thresh)
        racond_signal(l_async_cond);

    while(1) {

        EnterSpinLock(&p->nodeLock);

        node = p->free_list;
        if(node != NULL)
            p->free_list = node->next;

        LeaveSpinLock(&p->nodeLock);

        if(node != NULL)
            break;

        rathread_yield();
    }

    InterlockedDecrement64(&p->num_nodes_free);

    // Update peak value
    num_used = (p->num_nodes_total - p->num_nodes_free);
    if(num_used > p->peak_nodes_used) {
        InterlockedExchange64(&p->peak_nodes_used, num_used);
    }

#ifdef MEMPOOLASSERT
    node->used = true;
#endif

    return NODE_TO_DATA(node);
}//end: mempool_node_get()
Ejemplo n.º 5
0
int64_t Dec64(volatile int64_t *i)
{
  return (int64_t)InterlockedDecrement64((volatile LONG64 *)i);
}
/**
 @function="BasicPacketInjectionCountersDecrement"
 
   Purpose:  Deccrement the appropriate counters based on the injection handle.                 <br>
                                                                                                <br>
   Notes:                                                                                       <br>
                                                                                                <br>
   MSDN_Ref: HTTP://MSDN.Microsoft.com/En-US/Library/Desktop/MS683581.aspx                      <br>
*/
VOID BasicPacketInjectionCountersDecrement(_In_ HANDLE injectionHandle,
                                           _Inout_ INJECTION_COUNTERS* pCounters)
{
   if(injectionHandle == g_IPv4InboundNetworkInjectionHandle)
      InterlockedDecrement64((LONG64*)&(pCounters->inboundNetwork_IPv4));
   else if(injectionHandle == g_IPv6InboundNetworkInjectionHandle)
      InterlockedDecrement64((LONG64*)&(pCounters->inboundNetwork_IPv6));
   else if(injectionHandle == g_IPv4OutboundNetworkInjectionHandle)
      InterlockedDecrement64((LONG64*)&(pCounters->outboundNetwork_IPv4));
   else if(injectionHandle == g_IPv6OutboundNetworkInjectionHandle)
      InterlockedDecrement64((LONG64*)&(pCounters->outboundNetwork_IPv6));
   else if(injectionHandle == g_IPv4InboundForwardInjectionHandle)
      InterlockedDecrement64((LONG64*)&(pCounters->inboundForward_IPv4));
   else if(injectionHandle == g_IPv6InboundForwardInjectionHandle)
      InterlockedDecrement64((LONG64*)&(pCounters->inboundForward_IPv6));
   else if(injectionHandle == g_IPv4OutboundForwardInjectionHandle)
      InterlockedDecrement64((LONG64*)&(pCounters->outboundForward_IPv4));
   else if(injectionHandle == g_IPv6OutboundForwardInjectionHandle)
      InterlockedDecrement64((LONG64*)&(pCounters->outboundForward_IPv6));
   else if(injectionHandle == g_IPv4InboundTransportInjectionHandle)
      InterlockedDecrement64((LONG64*)&(pCounters->inboundTransport_IPv4));
   else if(injectionHandle == g_IPv6InboundTransportInjectionHandle)
      InterlockedDecrement64((LONG64*)&(pCounters->inboundTransport_IPv6));
   else if(injectionHandle == g_IPv4OutboundTransportInjectionHandle)
      InterlockedDecrement64((LONG64*)&(pCounters->outboundTransport_IPv4));
   else if(injectionHandle == g_IPv6OutboundTransportInjectionHandle)
      InterlockedDecrement64((LONG64*)&(pCounters->outboundTransport_IPv6));

#if(NTDDI_VERSION >= NTDDI_WIN8)

   else if(injectionHandle == g_IPv4InboundMACInjectionHandle)
      InterlockedDecrement64((LONG64*)&(pCounters->inboundMAC_IPv4));
   else if(injectionHandle == g_IPv6InboundMACInjectionHandle)
      InterlockedDecrement64((LONG64*)&(pCounters->inboundMAC_IPv6));
   else if(injectionHandle == g_InboundMACInjectionHandle)
      InterlockedDecrement64((LONG64*)&(pCounters->inboundMAC_Unknown));
   else if(injectionHandle == g_IPv4OutboundMACInjectionHandle)
      InterlockedDecrement64((LONG64*)&(pCounters->outboundMAC_IPv4));
   else if(injectionHandle == g_IPv6OutboundMACInjectionHandle)
      InterlockedDecrement64((LONG64*)&(pCounters->outboundMAC_IPv6));
   else if(injectionHandle == g_OutboundMACInjectionHandle)
      InterlockedDecrement64((LONG64*)&(pCounters->outboundMAC_Unknown));
   else if(injectionHandle == g_IPv4IngressVSwitchEthernetInjectionHandle)
      InterlockedDecrement64((LONG64*)&(pCounters->ingressVSwitch_IPv4));
   else if(injectionHandle == g_IPv6IngressVSwitchEthernetInjectionHandle)
      InterlockedDecrement64((LONG64*)&(pCounters->ingressVSwitch_IPv6));
   else if(injectionHandle == g_IngressVSwitchEthernetInjectionHandle)
      InterlockedDecrement64((LONG64*)&(pCounters->ingressVSwitch_Unknown));
   else if(injectionHandle == g_IPv4EgressVSwitchEthernetInjectionHandle)
      InterlockedDecrement64((LONG64*)&(pCounters->egressVSwitch_IPv4));
   else if(injectionHandle == g_IPv6EgressVSwitchEthernetInjectionHandle)
      InterlockedDecrement64((LONG64*)&(pCounters->egressVSwitch_IPv6));
   else if(injectionHandle == g_EgressVSwitchEthernetInjectionHandle)
      InterlockedDecrement64((LONG64*)&(pCounters->egressVSwitch_Unknown));

#endif /// (NTDDI_VERSION >= NTDDI_WIN8)

   return;
}
Ejemplo n.º 7
0
int64 atomic_decrement(int64 volatile *value) { return InterlockedDecrement64(value); }
_IRQL_requires_same_
inline VOID KrnlHlprClassifyDataReleaseLocalCopy(_Inout_ CLASSIFY_DATA* pClassifyData)
{
#if DBG

   DbgPrintEx(DPFLTR_IHVNETWORK_ID,
              DPFLTR_INFO_LEVEL,
              " ---> KrnlHlprClassifyDataReleaseLocalCopy()\n");

#endif /// DBG
   
   NT_ASSERT(pClassifyData);

   KrnlHlprFwpsClassifyOutDestroyLocalCopy((FWPS_CLASSIFY_OUT**)&(pClassifyData->pClassifyOut));

   pClassifyData->flowContext = 0;

   KrnlHlprFwpsFilterDestroyLocalCopy((FWPS_FILTER**)&(pClassifyData->pFilter));

#if(NTDDI_VERSION >= NTDDI_WIN7)
   
      if(pClassifyData->classifyContextHandle)
         FwpsReleaseClassifyHandle(pClassifyData->classifyContextHandle);
   
#endif /// (NTDDI_VERSION >= NTDDI_WIN7)

   if(pClassifyData->pPacket)
   {
      if(pClassifyData->pClassifyValues)
      {
         if(pClassifyData->pClassifyValues->layerId == FWPS_LAYER_STREAM_V4 ||
            pClassifyData->pClassifyValues->layerId == FWPS_LAYER_STREAM_V4_DISCARD ||
            pClassifyData->pClassifyValues->layerId == FWPS_LAYER_STREAM_V6 ||
            pClassifyData->pClassifyValues->layerId == FWPS_LAYER_STREAM_V6_DISCARD)
            KrnlHlprFwpsStreamCalloutIOPacketDestroyLocalCopy((FWPS_STREAM_CALLOUT_IO_PACKET**)&(pClassifyData->pPacket));
         else if(pClassifyData->chainedNBL)
         {
            BOOLEAN isDispatch	   = (KeGetCurrentIrql() == DISPATCH_LEVEL) ? TRUE : FALSE;
            UINT32  numChainedNBLs  = pClassifyData->numChainedNBLs;

            for(NET_BUFFER_LIST* pCurrentNBL = (NET_BUFFER_LIST*)pClassifyData->pPacket;
                pCurrentNBL &&
                numChainedNBLs;
                numChainedNBLs--)
            {
               NET_BUFFER_LIST* pNextNBL = NET_BUFFER_LIST_NEXT_NBL(pCurrentNBL);

               FwpsDereferenceNetBufferList(pCurrentNBL,
                                            isDispatch);

               pCurrentNBL = pNextNBL;

#if DBG

               InterlockedDecrement64((LONG64*)&(g_OutstandingNBLReferences));

#endif /// DBG

            }
         }
         else
         {
            BOOLEAN isDispatch = (KeGetCurrentIrql() == DISPATCH_LEVEL) ? TRUE : FALSE;

            FwpsDereferenceNetBufferList((NET_BUFFER_LIST*)pClassifyData->pPacket,
                                         isDispatch);

#if DBG

            InterlockedDecrement64((LONG64*)&(g_OutstandingNBLReferences));

#endif /// DBG

         }
      }

      pClassifyData->pPacket = 0;
   }

   KrnlHlprFwpsIncomingMetadataValuesDestroyLocalCopy((FWPS_INCOMING_METADATA_VALUES**)&(pClassifyData->pMetadataValues));

   if(pClassifyData->pClassifyValues)
      KrnlHlprFwpsIncomingValuesDestroyLocalCopy((FWPS_INCOMING_VALUES**)&(pClassifyData->pClassifyValues));

   RtlZeroMemory(pClassifyData,
                 sizeof(CLASSIFY_DATA));

#if DBG
   
   DbgPrintEx(DPFLTR_IHVNETWORK_ID,
              DPFLTR_INFO_LEVEL,
              " <--- KrnlHlprClassifyDataReleaseLocalCopy()\n");

#endif /// DBG
   
   return;
}
Ejemplo n.º 9
0
_ALWAYS_INLINE_ uint64_t _atomic_decrement_impl(register uint64_t *pw) {

	return InterlockedDecrement64((LONGLONG volatile *)pw);
}
Ejemplo n.º 10
0
intptr_t atom_dec(volatile intptr_t *dest)
{
	return InterlockedDecrement64((LONGLONG *)dest);
}
Ejemplo n.º 11
0
WindowsAtomics::Int64 WindowsAtomics::AtomicDecrement(AtomicInt64 &Val)
{
    return InterlockedDecrement64(&Val);
}
Ejemplo n.º 12
0
 template<typename T> static T dec(volatile T*scalar) {
     return (T)InterlockedDecrement64((volatile LONGLONG*)scalar);
 }