亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? sync.cpp

?? Latest USB 802.3, HID printer and mass storage divers from Microsoft for Platform Builder 4.2.
?? CPP
字號:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
/*
 * Enhanced Critical Section API
 *
 * This module defines four functions that parallel the Win32 critical section
 * APIs but that provide some additional functionality.
 *
 * void InitCritSec_Ex (CritSec_Ex *this)
 *      Call this to initialize an enhanced critical section structure.
 *      The caller is responsible for allocating the structure. No other
 *      routines should be called on the structure until it has been
 *      initialized by this function. Do not initialize a structure more
 *      than once (excepting when it has been de-initialized first).
 *      Failure to abide by these rules will yield unpredicatable chaos.
 *
 * void DeleteCritSec_Ex (CritSec_Ex *this)
 *      Deletes the enhanced critical section structure (but doesn't free
 *      it - caller is responsible for that), deallocating all internally
 *      used system resources. Once this call returns, no threads are allowed
 *      to pass the structure to any of these calls except Init.
 *      !!!!!
 *      This call will block until the critical section can be safely deleted.
 *      !!!!!
 *      Once this call is made, all further attempts to Enter the critical
 *      section will fail. All pending Enter requests will be woken from their
 *      blocked states and be forced to fail. If another thread already owns
 *      the critical section then this function will block until that thread
 *      relinquishes control.
 *      The calling thread may or may not own the critical section when it
 *      calls this function. If it does own the critical section, it must
 *      not call Leave once the Delete operation returns, no matter how many
 *      nested Enter calls there were.
 *      If the caller of this function did not already hold the critical
 *      section for some other reason, it is more efficient for it to simply
 *      call Delete than for it to Enter the critical section first. This is
 *      because Delete forces other competing threads to abort whereas with
 *      Enter, a thread must wait its proper turn before initiating the Delete.
 *
 * void PrepareDeleteCritSec_Ex (CritSec_Ex *this)
 *      Initiates the destruction sequence. Using this call is optional.
 *      If used, it should be called only once and must then be followed
 *      up with a call to DeleteCritSec_Ex. This call has a bounded duration
 *      and when it returns other threads will behave as described for
 *      DeleteCritSec_Ex above. It does not wait for any such threads to finish,
 *      however, and so also does not clean up internal resources. That's why
 *      this must be followed up with a call to DeleteCritSec_Ex. Use this call
 *      when the delete operation has to be split into two phases.
 *
 * CritSec_Status EnterCritSec_Ex (CritSec_Ex *this, ULONG ulTimeout)
 *      Attempts to enter the enhanced critical section. The second argument,
 *      ulTimeout, specifies a maximum time (in milliseconds) to wait (as per
 *      the Win32 call WaitForSingleObject). Like Win32 critical sections,
 *      enhanced critical sections may be Enter'd recursively, in which case,
 *      the critical section is not relinquished until Leave has been called
 *      once for each time Enter was called.
 *      Possible return values are:
 *      o CSS_SUCCESS - caller now owns the enhanced critical section.
 *      o CSS_TIMEOUT - the non-INFINITE timeout expired before we gained
 *                      ownership; caller does not own the enhanced critical
 *                      section but may try to Enter it again.
 *      o CSS_DESTROYED - someone has Delete'd the enhanced critical section
 *                      and, as of the time at which this value is first
 *                      returned, it is no longer usable.
 *
 * void LeaveCritSec_Ex (CritSec_Ex *this)
 *      Relinquishes a previously Enter'd enhanced critical section.
 *      This call CAN block and CAN cause the scheduler to run. While the
 *      Win32 critical section it attempts to acquire can only be held for a
 *      bounded period of time, there is no bound to the time we may have to
 *      wait before being granted access to it.
 *      See also notes for Enter and Delete.
 *
 * NOTES:
 * o Using ulTimeout values other than 0 or INFINITE in the Enter call may have
 *   somewhat misleading results due to the implementation. Since it is possible
 *   for a thread to be woken but not be able to acquire the critical section
 *   (because the Win32 API does not give us a way to atomically grab a Win32
 *   critical section while waking up), we can wake up and block one or more
 *   times during the timeout interval, losing the race each time and, depending
 *   upon scheduler details, possibly reset any kernel fairness indications each
 *   time and cause us to timeout even though the section became available
 *   sometime during our interval. For the same reasons, an INFINITE timeout
 *   also leaves us vulnerable to starvation despite any in-kernel remedies.
 *
 * o Since the caller of these functions allocates the memory for the enhanced
 *   critical section structure (though not the internally used resources), we
 *   can guarantee that any number of attempted Enter's after a Delete will
 *   return CSS_DESTROYED, until the caller actually frees said memory. This is
 *   a potentially useful feature in that it prevents the need for an additional
 *   external flag while waiting for a module's auxilliary threads to finish
 *   shutting down.
 */

#include <globals.hpp>
#include "Sync.hpp"

/* - copied from globals.hpp:
typedef enum e_CritSec_Status {
    CSS_SUCCESS, CSS_DESTROYED, CSS_TIMEOUT
} CritSec_Status;

typedef struct s_CritSec_Ex
{
    DWORD m_hOwnerThread;
    UINT m_cOwnerReferences;
    UINT m_cWaitingThreads;
    HANDLE m_hev;
    CRITICAL_SECTION m_cs;
    BOOL m_fClosing;
} CritSec_Ex;

void InitCritSec_Ex (CritSec_Ex *this);
void DeleteCritSec_Ex (CritSec_Ex *this);
CritSec_Status EnterCritSec_Ex (CritSec_Ex *this, ULONG ulTimeout);
void LeaveCritSec_Ex (CritSec_Ex *this);
*/

CritSec_Status CritSec_Ex::EnterCritSec_Ex (ULONG ulTimeout)
{
    DWORD r;
    ULONG tStart, tNow, tLeft;
    CritSec_Status retval;
    BOOL fWaiting;
    DWORD me;

    tStart = GetTickCount();
    r = ! WAIT_TIMEOUT;  // anything other than WAIT_TIMEOUT will suffice
    me = GetCurrentThreadId();

    // Help destruction proceed more quickly by preventing anyone new from using
    // the IPC objects when we're pending destruction. Do this here for speed
    // and again within the critical section for correctness.
    if (m_fClosing)
        return CSS_DESTROYED;

    EnterCriticalSection(&m_cs);
    do {
        fWaiting = FALSE;

        if (m_fClosing) {
            SetEvent(m_hev);
            retval = CSS_DESTROYED;
        }
        else if (r == WAIT_TIMEOUT) {
            retval = CSS_TIMEOUT;
        }
        else if (m_hOwnerThread == 0) {
            m_hOwnerThread = me;
            m_cOwnerReferences = 1;
            retval = CSS_SUCCESS;
        }
        else if (m_hOwnerThread == me) {
            ++m_cOwnerReferences;
            retval = CSS_SUCCESS;
        }
        else {
            // Oh well, we've got to wait.
            ++m_cWaitingThreads;
            fWaiting = TRUE;
        }
        LeaveCriticalSection(&m_cs);

        if (fWaiting) {
            if (ulTimeout != INFINITE) {
                tNow = GetTickCount();
                if (tNow - tStart < ulTimeout)
                    tLeft = ulTimeout - (tNow - tStart);
                else
                    tLeft = 0; // poll one more time
            } else {
                tLeft = INFINITE;
            }
            r = WaitForSingleObject(m_hev, tLeft);
            EnterCriticalSection(&m_cs);
            --m_cWaitingThreads;
        }
    } while (fWaiting);

    return retval;
}

void CritSec_Ex::LeaveCritSec_Ex ()
{
#ifdef POLITE // but not by default // default is to fail so the debugger knows you botched
    if (m_fClosing && m_hOwnerThread == NULL)
        // our caller violated protocol but we'll ignore it
        return;
#endif
    ASSERT(m_hOwnerThread == GetCurrentThreadId());
    
    EnterCriticalSection(&m_cs);

    // this would be symptomatic of a logic error in the caller
    ASSERT(m_cOwnerReferences > 0);

    if (--m_cOwnerReferences == 0) {
        m_hOwnerThread = 0;
        SetEvent(m_hev);
    }

    LeaveCriticalSection(&m_cs);
}

CritSec_Ex::CritSec_Ex()
{
    m_hev = CreateEvent(NULL, FALSE, TRUE, 0);   // initially set!
    if (m_hev == NULL) {
        // simulate InitializeCriticalSection - see docs
        RaiseException(STATUS_NO_MEMORY, 0, 0, NULL);
    }
    InitializeCriticalSection(&m_cs);
    Initialize();
}
void CritSec_Ex::Initialize( )
{
    EnterCriticalSection(&m_cs);
    m_hOwnerThread = 0;
    m_cOwnerReferences = 0;
    m_cWaitingThreads = 0;
    m_fClosing = FALSE;
    LeaveCriticalSection(&m_cs);
}

void CritSec_Ex::PrepareDeleteCritSec_Ex ()
{
    DWORD me = GetCurrentThreadId();
    
    EnterCriticalSection(&m_cs);
    m_fClosing = TRUE;
    if (m_hOwnerThread == me) {
        // m_cOwnerReferences is >=1 but the caller had better not Leave after this...
        m_hOwnerThread = 0;
    }
    LeaveCriticalSection(&m_cs);

    // start waking up threads blocked on this critsec;
    // each thread woken this way will set the event again.
    SetEvent(m_hev);
}

CritSec_Ex::~CritSec_Ex()
{
    BOOL bDone;

    // In case it wasn't already done:
    PrepareDeleteCritSec_Ex();

    EnterCriticalSection(&m_cs);
    bDone = m_hOwnerThread == 0 && m_cWaitingThreads == 0;
    LeaveCriticalSection(&m_cs);

    while (!bDone) {
        // force someone to wake up, leaving the event reset
        // so that the next statement can actually block.
        PulseEvent(m_hev);

        // and wait for the next waiting thread to set the event again
        // which will happen when they relinquish or when they note the
        // m_fClosing flag.
        WaitForSingleObject(m_hev, INFINITE);

        EnterCriticalSection(&m_cs);
        bDone = m_hOwnerThread == 0 && m_cWaitingThreads == 0;
        LeaveCriticalSection(&m_cs);
    }

    CloseHandle(m_hev);
    DeleteCriticalSection(&m_cs);
}


Countdown::Countdown( DWORD cInitial)
{
    count = cInitial;
    hev = CreateEvent(NULL, TRUE, cInitial ? FALSE : TRUE, NULL);
    InitializeCriticalSection(&cs);
    lock = FALSE;
}

BOOL Countdown::IncrCountdown ()
{
    BOOL r = TRUE;

    EnterCriticalSection(&cs);
    if (lock)
        r = FALSE;
    else
        if (count++ == 0)
            ResetEvent(hev);
    LeaveCriticalSection(&cs);

    return r;
}

void Countdown::DecrCountdown ()
{
    EnterCriticalSection(&cs);
    ASSERT(count > 0);
    if (--count == 0)
        SetEvent(hev);
    LeaveCriticalSection(&cs);
}

void Countdown::LockCountdown ()
{
    EnterCriticalSection(&cs);
    lock = TRUE;
    LeaveCriticalSection(&cs);
}


void Countdown::WaitForCountdown (BOOL keepLocked)
{
    LockCountdown();
    
    WaitForSingleObject(hev, INFINITE);
    ASSERT(count == 0);

    lock = keepLocked;
}

Countdown::~Countdown()
{
    WaitForCountdown( TRUE);

    CloseHandle(hev);
    DeleteCriticalSection(&cs);
}


?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲国产精品久久人人爱蜜臀| 国产精品成人网| 日韩精品一二区| 日韩一二三区不卡| 精东粉嫩av免费一区二区三区| 精品免费视频.| 国产传媒一区在线| 亚洲日本护士毛茸茸| 欧美乱妇15p| 国产精品综合二区| 国产精品视频免费| 欧美色爱综合网| 麻豆久久久久久| 国产精品成人在线观看| 在线观看日韩电影| 精彩视频一区二区| 亚洲人成精品久久久久| 欧美麻豆精品久久久久久| 免费在线观看一区二区三区| 日本一区二区视频在线观看| 91啪亚洲精品| 久久精品国产亚洲高清剧情介绍| 久久精品男人天堂av| 日本韩国一区二区| 久久精品av麻豆的观看方式| 中文一区二区完整视频在线观看| 色狠狠桃花综合| 精品一区二区三区视频在线观看| 中文字幕中文在线不卡住| 欧美日韩和欧美的一区二区| 国产一区视频导航| 亚洲成人免费看| 欧美精彩视频一区二区三区| 欧美日本免费一区二区三区| 成人免费视频视频在线观看免费| 亚洲成人高清在线| 国产精品动漫网站| 精品国产91久久久久久久妲己| 99国产精品99久久久久久| 秋霞国产午夜精品免费视频| 国产精品青草久久| 26uuu欧美| 欧美乱妇20p| 色哟哟一区二区在线观看| 国产一区二区三区av电影| 亚洲成年人网站在线观看| 国产精品久久毛片| 欧美电视剧免费观看| 日本久久电影网| 成人av电影在线观看| 国产综合久久久久影院| 日本欧美在线看| 夜夜揉揉日日人人青青一国产精品| 国产欧美一区二区精品婷婷| 欧美精品九九99久久| 欧美最猛黑人xxxxx猛交| 白白色亚洲国产精品| 国内精品视频666| 欧美aaa在线| 天堂成人国产精品一区| 一区二区三区四区不卡在线 | 欧美日精品一区视频| aaa欧美日韩| 成人免费观看av| 国产激情91久久精品导航| 久久国产精品无码网站| 日韩av电影天堂| 日日夜夜一区二区| 亚洲国产另类av| 一区二区三区日韩精品视频| 中文字幕亚洲欧美在线不卡| 中文字幕二三区不卡| 亚洲国产精品国自产拍av| 久久久另类综合| 国产亚洲短视频| 亚洲国产精品精华液2区45| 国产日韩欧美制服另类| 国产欧美视频一区二区三区| 国产午夜亚洲精品午夜鲁丝片| 26uuu久久综合| 国产日韩成人精品| 国产精品麻豆欧美日韩ww| 国产精品毛片大码女人| 综合激情成人伊人| 亚洲一区在线观看视频| 亚洲午夜精品在线| 日韩福利视频网| 精品一区二区三区欧美| 国产成人午夜高潮毛片| 99国内精品久久| 欧美最猛性xxxxx直播| 在线成人av影院| 精品动漫一区二区三区在线观看| 2欧美一区二区三区在线观看视频 337p粉嫩大胆噜噜噜噜噜91av | 欧美乱妇23p| 欧美mv日韩mv| 国产精品久久久久久久久果冻传媒 | 风间由美一区二区三区在线观看 | 精品成人a区在线观看| 久久久精品天堂| 国产精品久久毛片| 亚洲成精国产精品女| 理论电影国产精品| 成人精品国产一区二区4080 | 欧美自拍丝袜亚洲| 日韩一区二区电影网| 国产视频一区二区在线| 中文字幕在线不卡| 午夜亚洲国产au精品一区二区| 精品亚洲国内自在自线福利| gogo大胆日本视频一区| 欧美肥妇bbw| 国产欧美日韩综合| 亚洲一区二区四区蜜桃| 久久成人av少妇免费| 波多野结衣欧美| 91精品国产全国免费观看| 国产日韩欧美精品一区| 亚洲线精品一区二区三区| 美国av一区二区| 99久久精品免费| 精品免费国产一区二区三区四区| 中文字幕国产一区| 爽好多水快深点欧美视频| 国产精品18久久久久久久网站| 欧美无人高清视频在线观看| 久久众筹精品私拍模特| 午夜精品免费在线观看| 成人sese在线| 日韩欧美一二三四区| 亚洲精品视频一区| 久久国产精品无码网站| 欧美色图免费看| 国产午夜精品久久久久久免费视| 亚洲午夜一二三区视频| 成人高清免费在线播放| 日韩精品一区二区三区老鸭窝| 亚洲制服欧美中文字幕中文字幕| 国产又黄又大久久| 91精品欧美综合在线观看最新| 亚洲欧洲精品一区二区三区不卡 | 国产精品资源站在线| 国产三级欧美三级日产三级99| 亚洲国产wwwccc36天堂| 成人爱爱电影网址| 久久精品男人天堂av| 久久国产麻豆精品| 欧美一区三区二区| 午夜一区二区三区在线观看| 一本色道久久综合狠狠躁的推荐| 久久免费偷拍视频| 乱中年女人伦av一区二区| 欧美精品v国产精品v日韩精品| 亚洲男人的天堂网| av电影天堂一区二区在线| 日本一区二区三区免费乱视频| 久久99精品久久只有精品| 欧美一区二区三区免费大片 | 成人免费毛片嘿嘿连载视频| 亚洲精品在线电影| 久久99精品国产麻豆婷婷| 7777精品伊人久久久大香线蕉 | 91在线免费看| 国产精品久久久久久久久免费丝袜| 国产精品一二三区在线| 精品成人私密视频| 国产精品自产自拍| 国产日产欧美精品一区二区三区| 国产乱人伦偷精品视频不卡| 久久你懂得1024| 国产精品一级片| 国产亚洲精久久久久久| 成人夜色视频网站在线观看| 国产精品色一区二区三区| 99精品国产热久久91蜜凸| 亚洲欧美视频在线观看| 欧美视频你懂的| 日日骚欧美日韩| 日韩三级电影网址| 国产成人在线免费| 最新中文字幕一区二区三区| 色综合久久综合| 午夜电影网一区| 精品电影一区二区| 成人av电影免费观看| 夜色激情一区二区| 日韩欧美精品在线| 国产精品一区二区x88av| 亚洲欧洲成人自拍| 欧美性videosxxxxx| 日本伊人色综合网| 国产偷v国产偷v亚洲高清| 99国产精品99久久久久久| 五月开心婷婷久久| 国产偷v国产偷v亚洲高清 | 欧美日韩一区二区三区在线| 首页亚洲欧美制服丝腿| 久久中文字幕电影| 91视视频在线观看入口直接观看www | 亚洲国产高清不卡|