• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ InterlockedCompareExchange函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中InterlockedCompareExchange函数的典型用法代码示例。如果您正苦于以下问题:C++ InterlockedCompareExchange函数的具体用法?C++ InterlockedCompareExchange怎么用?C++ InterlockedCompareExchange使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了InterlockedCompareExchange函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: Start

void CManagedSearch::Start()
{
	if ( InterlockedCompareExchange( (LONG*)&m_bActive, TRUE, FALSE ) )
		return;

	CQuickLock oLock( SearchManager.m_pSection );

	if ( SearchManager.Add( this ) )
	{
		m_tExecute		= 0;
		m_tLastED2K		= 0;
		m_tMoreResults	= 0;
		m_nQueryCount	= 0;
		m_pNodes.RemoveAll();
	}
}
开发者ID:lemonxiao0,项目名称:peerproject,代码行数:16,代码来源:ManagedSearch.cpp


示例2: and

    inline ::LONG and ( volatile ::LONG& x, ::LONG y )
    {
#if defined(InterlockedAnd)
        return InterlockedAnd(&x, y);
#else
        LONG i;
        LONG j;
        j = x;
        do {
            i = j;
            j = InterlockedCompareExchange(&x, i&y, i);
        }
        while (i != j);
        return j;
#endif
    }
开发者ID:AndreLouisCaron,项目名称:w32,代码行数:16,代码来源:and.hpp


示例3: ClasspStopIdleTimer

/*++

ClasspStopIdleTimer

Routine Description:

    Stop the idle timer if running. Also reset the timer counters.

Arguments:

    FdoData - Pointer to the private fdo data

Return Value:

    None

--*/
VOID
ClasspStopIdleTimer(
    PCLASS_PRIVATE_FDO_DATA FdoData
    )
{
    LONG timerStarted;

    TracePrint((TRACE_LEVEL_INFORMATION, TRACE_FLAG_TIMER, "ClasspStopIdleTimer: Stop idle timer\n"));

    timerStarted = InterlockedCompareExchange(&FdoData->IdleTimerStarted, 0, 1);

    if (timerStarted) {
        (VOID)KeCancelTimer(&FdoData->IdleTimer);
    }
    return;
}
开发者ID:0xhack,项目名称:Windows-driver-samples,代码行数:33,代码来源:clntirp.c


示例4: git_threads_init

int git_threads_init(void)
{
	int error = 0;

	/* Enter the lock */
	while (InterlockedCompareExchange(&_mutex, 1, 0)) { Sleep(0); }

	/* Only do work on a 0 -> 1 transition of the refcount */
	if (1 == git_atomic_inc(&git__n_inits))
		error = synchronized_threads_init();

	/* Exit the lock */
	InterlockedExchange(&_mutex, 0);

	return error;
}
开发者ID:DaneTheory,项目名称:libgit2,代码行数:16,代码来源:global.c


示例5: winMutexInit

static int winMutexInit(void) {
    /* The first to increment to 1 does actual initialization */
    if( InterlockedCompareExchange(&winMutex_lock, 1, 0)==0 ) {
        int i;
        for(i=0; i<ArraySize(winMutex_staticMutexes); i++) {
            InitializeCriticalSection(&winMutex_staticMutexes[i].mutex);
        }
        winMutex_isInit = 1;
    } else {
        /* Someone else is in the process of initing the static mutexes */
        while( !winMutex_isInit ) {
            Sleep(1);
        }
    }
    return SQLITE_OK;
}
开发者ID:tianzhou,项目名称:Sqlite_3_7_5_VisualStudio,代码行数:16,代码来源:mutex_w32.c


示例6: mono_rand_open

gboolean
mono_rand_open (void)
{
	static gint32 status = 0;
	if (status != 0 || InterlockedCompareExchange (&status, 1, 0) != 0) {
		while (status != 2)
			mono_thread_info_yield ();
		return TRUE;
	}

	srand (time (NULL));

	status = 2;

	return TRUE;
}
开发者ID:0ostreamo0,项目名称:mono,代码行数:16,代码来源:mono-rand.c


示例7: lock

		void SpinMutex::lock()
		{
			for (;;)
			{
				if(InterlockedCompareExchange((LONG*)&m_id, 1, 0) == 0)
				{
					::MemoryBarrier();
					return;
				}

				while(m_id)
				{
					Sleep(0);
				}
			}
		}
开发者ID:HoRangDev,项目名称:LumixEngine,代码行数:16,代码来源:spin_mutex.cpp


示例8: ossl_init_once_run

static void ossl_init_once_run(OPENSSL_INIT_ONCE *once, void (*init)(void))
{
    LONG volatile *lock = (LONG *)once;
    LONG result;

    if (*lock == ONCE_DONE)
        return;

    do {
        result = InterlockedCompareExchange(lock, ONCE_ININIT, ONCE_UNINITED);
        if (result == ONCE_UNINITED) {
            init();
            *lock = ONCE_DONE;
            return;
        }
    } while (result == ONCE_ININIT);
}
开发者ID:alfiesyukur,项目名称:openssl,代码行数:17,代码来源:init.c


示例9: WdmAudTimerRoutine

VOID
NTAPI
WdmAudTimerRoutine(
    IN PDEVICE_OBJECT DeviceObject,
    IN PVOID Context)
{
    PWDMAUD_DEVICE_EXTENSION DeviceExtension;

    /* get device extension */
    DeviceExtension = (PWDMAUD_DEVICE_EXTENSION)DeviceObject->DeviceExtension;

    if (InterlockedCompareExchange((volatile long *)&DeviceExtension->WorkItemActive, 1, 0) == 0)
    {
        /* queue work item */
        IoQueueWorkItem(DeviceExtension->WorkItem, WdmAudInitWorkerRoutine, DelayedWorkQueue, (PVOID)DeviceExtension);
    }
}
开发者ID:hoangduit,项目名称:reactos,代码行数:17,代码来源:entry.c


示例10: EXPORTNUM

// ******************************************************************
// * 0x0033 - InterlockedCompareExchange()
// ******************************************************************
// Source:ReactOS
XBSYSAPI EXPORTNUM(51) xboxkrnl::LONG FASTCALL xboxkrnl::KRNL(InterlockedCompareExchange)
(
	IN OUT PLONG VOLATILE Destination,
	IN LONG  Exchange,
	IN LONG  Comparand
)
{
	LOG_FUNC_BEGIN
		LOG_FUNC_ARG(Destination)
		LOG_FUNC_ARG(Exchange)
		LOG_FUNC_ARG(Comparand)
		LOG_FUNC_END;

	LONG res = InterlockedCompareExchange((NtDll::PLONG)Destination, (NtDll::LONG)Exchange, (NtDll::LONG)Comparand);

	RETURN(res);
}
开发者ID:ILOVEPIE,项目名称:Cxbx-Reloaded,代码行数:21,代码来源:EmuKrnl.cpp


示例11: pollSubStatus_MainThread

    bool pollSubStatus_MainThread(t_enum_status &outNewSubStatus)
    {
        assert(isMainThread());
        bool subStatusChanged= false;

        // Atomically fetch the status from the WorkerThread
        LONG newSubStatus= InterlockedCompareExchange(&subStatus_WorkerThread, subStatus_WorkerThread, subStatus_WorkerThread);

        if (newSubStatus != subStatus_MainThread)
        {
            subStatus_MainThread= newSubStatus;
            outNewSubStatus= static_cast<t_enum_status>(newSubStatus);
            subStatusChanged= true;
        }

        return subStatusChanged;
    }
开发者ID:cboulay,项目名称:PSMoveService,代码行数:17,代码来源:BluetoothRequestsWin32.cpp


示例12: BackupStart

void BackupStart(TCHAR *backup_filename)
{
    TCHAR *tm = NULL;
    LONG cur_state;

    cur_state = InterlockedCompareExchange((volatile LONG*)&m_state, 1, 0);
    if (cur_state != 0) { /* Backup allready in process. */
        ShowPopup(TranslateT("Database back up in process..."), TranslateT("Error"), NULL); /* Show error message :) */
        return;
    }
    if (backup_filename != NULL)
        tm = mir_tstrdup(backup_filename);
    if (mir_forkthread(BackupThread, (void*)tm) == INVALID_HANDLE_VALUE) {
        InterlockedExchange((volatile LONG*)&m_state, 0); /* Backup done. */
        mir_free(tm);
    }
}
开发者ID:truefriend-cz,项目名称:miranda-ng,代码行数:17,代码来源:backup.cpp


示例13: while

        void Lcg::setSeed(long seed) {
            if(isThreadSafe_) {
#ifdef NIWA_RANDOM_LCG_LOCK_FREE
                LONG backup;

                do {
                    backup = value_;
                } while(backup != InterlockedCompareExchange(&value_, seed, backup));
#else
                EnterCriticalSection(&mutex_);
                value_ = static_cast<unsigned int>(seed);
                LeaveCriticalSection(&mutex_);
#endif
            } else {
                value_ = static_cast<unsigned int>(seed);
            }
        }
开发者ID:uttumuttu,项目名称:niwa,代码行数:17,代码来源:Lcg.cpp


示例14: threadpool_start_thread

static gboolean
threadpool_start_thread (ThreadPool *tp)
{
	gint n;
	guint32 stack_size;

	stack_size = (!tp->is_io) ? 0 : SMALL_STACK;
	while (!mono_runtime_is_shutting_down () && (n = tp->nthreads) < tp->max_threads) {
		if (InterlockedCompareExchange (&tp->nthreads, n + 1, n) == n) {
			mono_perfcounter_update_value (tp->pc_nthreads, TRUE, 1);
			mono_thread_create_internal (mono_get_root_domain (), tp->async_invoke, tp, TRUE, stack_size);
			return TRUE;
		}
	}

	return FALSE;
}
开发者ID:Lavesson,项目名称:mono,代码行数:17,代码来源:threadpool.c


示例15: kqueue

int VISIBLE
kqueue(void)
{
	struct kqueue *kq;
    struct kqueue *tmp;

#ifdef _WIN32
    if (InterlockedCompareExchange(&kq_init_begin, 0, 1) == 0) {
        libkqueue_init();
    } else {
        while (kq_init_complete == 0) {
            sleep(1);
        }
    }
#else
    (void) pthread_mutex_lock(&kq_mtx);
    (void) pthread_once(&kq_is_initialized, libkqueue_init);
    (void) pthread_mutex_unlock(&kq_mtx);
#endif

    kq = calloc(1, sizeof(*kq));
    if (kq == NULL)
        return (-1);

	tracing_mutex_init(&kq->kq_mtx, NULL);

    if (kqops.kqueue_init(kq) < 0) {
        free(kq);
        return (-1);
    }

    dbg_printf("created kqueue, fd=%d", kq->kq_id);

    tmp = map_delete(kqmap, kq->kq_id);
    if (tmp != NULL) {
        dbg_puts("FIXME -- memory leak here");
        // TODO: kqops.kqueue_free(tmp), or (better yet) decrease it's refcount
    }
    if (map_insert(kqmap, kq->kq_id, kq) < 0) {
        dbg_puts("map insertion failed");
        kqops.kqueue_free(kq);
        return (-1);
    }

    return (kq->kq_id);
}
开发者ID:GalenRhodes,项目名称:libkqueue,代码行数:46,代码来源:kqueue.c


示例16: ApsWriteLogEntry

VOID
ApsWriteLogEntry(
	__in ULONG ProcessId,
	__in APS_LOG_LEVEL Level,
	__in PSTR Format,
	...
	)
{
	ULONG IsLogging;
	va_list Argument;
	PAPS_LOG_ENTRY Entry;
	CHAR Buffer[APS_LOG_TEXT_LIMIT];

	//
	// Check whether logging's enabled
	//

	IsLogging = InterlockedCompareExchange(&ApsLogObject.Flag, 0, 0);
	if (!IsLogging) {
		return;
	}

	va_start(Argument, Format);
	StringCchVPrintfA(Buffer, MAX_PATH, Format, Argument);
	va_end(Argument);

	Entry = (PAPS_LOG_ENTRY)ApsMalloc(sizeof(APS_LOG_ENTRY));
	Entry->ProcessId = ProcessId;
	Entry->Level = Level;

	GetLocalTime(&Entry->TimeStamp);
	StringCchCopyA(Entry->Text, APS_LOG_TEXT_LIMIT, Buffer);

	//
	// Queue record entry to logging queue, note that this routine can be
	// called concurrently, so logging object's lock must be acquired to
	// protect the log record queue
	//

	EnterCriticalSection(&ApsLogObject.Lock);
	InsertTailList(&ApsLogObject.ListHead, &Entry->ListEntry);
	ApsLogObject.ListDepth += 1;
	LeaveCriticalSection(&ApsLogObject.Lock);

	return;
}
开发者ID:HeckMina,项目名称:dprofiler,代码行数:46,代码来源:apslog.c


示例17: x264_threading_init

int x264_threading_init( void )
{
    LONG state;
    while( (state = InterlockedCompareExchange( &threading_is_init, -1, 0 )) != 0 )
    {
        /* if already init, then do nothing */
        if( state > 0 )
            return 0;
    }
    if( threading_init() < 0 )
    {
        InterlockedExchange( &threading_is_init, 0 );
        return -1;
    }
    InterlockedExchange( &threading_is_init, 1 );
    return 0;
}
开发者ID:xing2fan,项目名称:x264,代码行数:17,代码来源:osdep.c


示例18: RtlInterlockedSetClearBits

ULONG
FASTCALL
RtlInterlockedSetClearBits (
    IN OUT PULONG Flags,
    IN ULONG sFlag,
    IN ULONG cFlag
    )

/*++

Routine Description:

    This function atomically sets and clears the specified flags in the target

Arguments:

    Flags - Pointer to variable containing current mask.

    sFlag  - Flags to set in target

    CFlag  - Flags to clear in target

Return Value:

    ULONG - Old value of mask before modification

--*/

{

    ULONG NewFlags, OldFlags;

    OldFlags = *Flags;
    NewFlags = (OldFlags | sFlag) & ~cFlag;
    while (NewFlags != OldFlags) {
        NewFlags = InterlockedCompareExchange ((PLONG) Flags, (LONG) NewFlags, (LONG) OldFlags);
        if (NewFlags == OldFlags) {
            break;
        }

        OldFlags = NewFlags;
        NewFlags = (NewFlags | sFlag) & ~cFlag;
    }

    return OldFlags;
}
开发者ID:AlexiaChen,项目名称:wrk_study,代码行数:46,代码来源:intbits.c


示例19: Uninitialize

HRESULT CUnkownReport::Uninitialize()
{
    HRESULT hr  = S_OK;
    if ( !InterlockedCompareExchange( &m_lInit, 0, 1 ) )
    {
        hr = S_FALSE;
        goto Exit0;
    }

    m_submitList.RemoveAll();
    m_reportHighList.RemoveAll();
    m_reportMidList.RemoveAll();
    m_reportLowList.RemoveAll();

    if ( m_hNotifyReport )
    {
        m_hNotifyReport.Close();
    }

    if ( m_hNotifyStop )
    {
        m_hNotifyStop.Set();

        AWinRunnable::WaitExit( INFINITE );

        m_hNotifyStop.Close();
    }

    m_reportFileDB.Uninitialize();

    if ( m_spiBackup )
    {
        m_spiBackup.Release();
    }

    m_spiBakFinder.Release();

    if ( m_spiUploader )
    {
        m_spiUploader->Uninitialize();
        m_spiUploader.Release();
    }
Exit0:
    return hr;
}
开发者ID:dreamsxin,项目名称:PcManager,代码行数:45,代码来源:unknownreport.cpp


示例20: WorkOnFifoFE

void WorkOnFifoFE(SWR_CONTEXT *pContext, uint32_t workerId, uint32_t &curDrawFE)
{
    // Try to grab the next DC from the ring
    uint32_t drawEnqueued = GetEnqueuedDraw(pContext);
    while (IDComparesLess(curDrawFE, drawEnqueued))
    {
        uint32_t dcSlot = curDrawFE % pContext->MAX_DRAWS_IN_FLIGHT;
        DRAW_CONTEXT *pDC = &pContext->dcRing[dcSlot];
        if (pDC->isCompute || pDC->doneFE)
        {
            CompleteDrawContextInl(pContext, workerId, pDC);
            curDrawFE++;
        }
        else
        {
            break;
        }
    }

    uint32_t lastRetiredFE = curDrawFE - 1;
    uint32_t curDraw = curDrawFE;
    while (IDComparesLess(curDraw, drawEnqueued))
    {
        uint32_t dcSlot = curDraw % pContext->MAX_DRAWS_IN_FLIGHT;
        DRAW_CONTEXT *pDC = &pContext->dcRing[dcSlot];

        if (!pDC->isCompute && !pDC->FeLock)
        {
            if (CheckDependencyFE(pContext, pDC, lastRetiredFE))
            {
                return;
            }

            uint32_t initial = InterlockedCompareExchange((volatile uint32_t*)&pDC->FeLock, 1, 0);
            if (initial == 0)
            {
                // successfully grabbed the DC, now run the FE
                pDC->FeWork.pfnWork(pContext, pDC, workerId, &pDC->FeWork.desc);

                CompleteDrawFE(pContext, workerId, pDC);
            }
        }
        curDraw++;
    }
}
开发者ID:daniel-schuermann,项目名称:mesa,代码行数:45,代码来源:threads.cpp



注:本文中的InterlockedCompareExchange函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ InterlockedCompareExchangePointer函数代码示例发布时间:2022-05-30
下一篇:
C++ Integer函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap