本文整理汇总了C++中InterlockedCompareExchange函数的典型用法代码示例。如果您正苦于以下问题:C++ InterlockedCompareExchange函数的具体用法?C++ InterlockedCompareExchange怎么用?C++ InterlockedCompareExchange使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了InterlockedCompareExchange函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
}
示例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
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例7: lock
void SpinMutex::lock()
{
for (;;)
{
if(InterlockedCompareExchange((LONG*)&m_id, 1, 0) == 0)
{
::MemoryBarrier();
return;
}
while(m_id)
{
Sleep(0);
}
}
}
示例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);
}
示例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);
}
}
示例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);
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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;
}
示例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);
}