当前位置: 首页>>代码示例>>C++>>正文


C++ TryEnterCriticalSection函数代码示例

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


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

示例1: lock_with_timeout

	status_t lock_with_timeout(bigtime_t time)// だめだめ
	{
		#ifdef NTK_WINNT
			bigtime_t start_time = GetTickCount();//timeGetTime();

			while(TryEnterCriticalSection(&m_critical_section))
			{
				if(GetTickCount() - start_time > time)//timeGetTime()
					return Locker::status::TIME_OUT_ERROR;

				snooze(1);// 数値は適当
			}

			++m_lock_count;
			return st::OK;
		#else
			time = time;
			return status_t(st::ERR,
				"TryEnterCriticalSection: Windows9x ではサポートされてないようです。");
		#endif
	}
开发者ID:snori,项目名称:ntk,代码行数:21,代码来源:locker.cpp

示例2: diff

bool MutexImpl::tryLockImpl(long milliseconds)
{
	const int sleepMillis = 5;
	Timestamp now;
	Timestamp::TimeDiff diff(Timestamp::TimeDiff(milliseconds)*1000);
	do
	{
		try
		{
			if (TryEnterCriticalSection(&_cs) == TRUE)
				return true;
		}
		catch (...)
		{
			throw SystemException("cannot lock mutex");
		}
		Sleep(sleepMillis);
	}
	while (!now.isElapsed(diff));
	return false;
}
开发者ID:jacobxy,项目名称:test,代码行数:21,代码来源:Mutex_WIN32.cpp

示例3: loom_mutex_trylock_real

int loom_mutex_trylock_real(const char *file, int line, MutexHandle m)
{
#ifndef NTELEMETRY
    TmU64 matchId;
#endif

    lmAssert(m != 0, "loom_mutex_lock_real - tried to lock NULL");

    tmTryLockEx(gTelemetryContext, &matchId, 1000, file, line, m, "mutex_trylock");

    if (TryEnterCriticalSection((CRITICAL_SECTION *)m))
    {
        tmEndTryLockEx(gTelemetryContext, matchId, file, line, m, TMLR_SUCCESS);
        tmSetLockState(gTelemetryContext, m, TMLS_LOCKED, "mutex_trylock");
        return 1;
    }
    else
    {
        tmEndTryLockEx(gTelemetryContext, matchId, file, line, m, TMLR_FAILED);
        return 0;
    }
}
开发者ID:Ivory27,项目名称:LoomSDK,代码行数:22,代码来源:platformThread.c

示例4: return

bool PdfMutex::TryLock()
{
#ifdef PODOFO_MULTI_THREAD
#ifdef _WIN32
    return (TryEnterCriticalSection( &m_cs ) ? true : false);
#else
    int nRet = pthread_mutex_trylock( &m_mutex );
    if( nRet == 0 )
	    return true;
    else if( nRet == EBUSY )
	    return false;
    else
    {
	    PODOFO_RAISE_ERROR( ePdfError_MutexError );
    }
#endif // _WIN32
#endif // PODOFO_MULTI_THREAD

    // If we have no multithreading support always
    // simulate succesfull locking
    return true;
}
开发者ID:arunjalota,项目名称:paperman,代码行数:22,代码来源:PdfMutex.cpp

示例5: FlushBuffer

VOID FlushBuffer(BOOL Force)
{
    if (!Force) {
        BOOL Entered = TryEnterCriticalSection(&CriticalSect);
        if(!Entered)
            return;
    } else
        EnterCriticalSection(&CriticalSect);

    if (BufLen != 0) {
        Buf[BufLen] = 0;
        Buf[BufLen+1] = 0;
        DoFlushBuffer(Buf, BufLen);
        // Update 'BackSpaces' for next invocation of DoFlushBuffer
        BackSpaces = min(0, BackSpaces + OutputPos + BufLen);
        OutputPos = BufPos - BufLen;
        BufPos = 0;
        BufLen = 0;
    }

    LeaveCriticalSection(&CriticalSect);
}
开发者ID:ElfridaDwi,项目名称:winghci,代码行数:22,代码来源:RtfWindow.c

示例6: pthread_mutex_trylock_annotate_np

int pthread_mutex_trylock_annotate_np(pthread_mutex_t *mutex, const char* file, int line)
{
  int contention = 0;
  pthread_np_assert_live_mutex(mutex,"trylock");
  if (*mutex == PTHREAD_MUTEX_INITIALIZER) {
    pthread_mutex_lock(&mutex_init_lock);
    if (*mutex == PTHREAD_MUTEX_INITIALIZER) {
      pthread_mutex_init(mutex, NULL);
    }
    pthread_mutex_unlock(&mutex_init_lock);
  }
  if ((*mutex)->owner) {
    pthshow("Mutex #x%p -> #x%p: tried contention; owned by #x%p, wanted by #x%p",
            mutex, *mutex,
            (*mutex)->owner,
            pthread_self());
    pthshow("Mutex #x%p -> #x%p: contention notes: old %s +%d, new %s +%d",
            mutex, *mutex,
            (*mutex)->file,(*mutex)->line, file, line);
    contention = 1;
  }
  if (TryEnterCriticalSection(&(*mutex)->cs)) {
    if (contention) {
      pthshow("Mutex #x%p -> #x%p: contention end; left by #x%p, taken by #x%p",
              mutex, *mutex,
              (*mutex)->owner,
              pthread_self());
      pthshow("Mutex #x%p -> #x%p: contention notes: old %s +%d, new %s +%d",
              mutex, *mutex,
              (*mutex)->file,(*mutex)->line, file, line);
    }
    (*mutex)->owner = pthread_self();
    (*mutex)->file = file;
    (*mutex)->line = line;
    return 0;
  }
  else
    return EBUSY;
}
开发者ID:Ferada,项目名称:sbcl,代码行数:39,代码来源:pthreads_win32.c

示例7: CPLAcquireMutex

int CPLAcquireMutex( void *hMutexIn, double dfWaitInSeconds )

{
#ifdef USE_WIN32_MUTEX
    HANDLE hMutex = (HANDLE) hMutexIn;
    DWORD  hr;

    hr = WaitForSingleObject( hMutex, (int) (dfWaitInSeconds * 1000) );
    
    return hr != WAIT_TIMEOUT;
#else
    CRITICAL_SECTION *pcs = (CRITICAL_SECTION *)hMutexIn;
    BOOL ret;

    while( (ret = TryEnterCriticalSection(pcs)) == 0 && dfWaitInSeconds > 0.0 )
    {
        CPLSleep( MIN(dfWaitInSeconds,0.125) );
        dfWaitInSeconds -= 0.125;
    }
    
    return ret;
#endif
}
开发者ID:imincik,项目名称:pkg-gdal,代码行数:23,代码来源:cpl_multiproc.cpp

示例8: winMutexTry

static int winMutexTry(sqlite3_mutex *p){
  int rc = SQLITE_BUSY;
  assert( p->id==SQLITE_MUTEX_RECURSIVE || winMutexNotheld(p) );
  /*
  ** The sqlite3_mutex_try() routine is very rarely used, and when it
  ** is used it is merely an optimization.  So it is OK for it to always
  ** fail.  
  **
  ** The TryEnterCriticalSection() interface is only available on WinNT.
  ** And some windows compilers complain if you try to use it without
  ** first doing some #defines that prevent SQLite from building on Win98.
  ** For that reason, we will omit this optimization for now.  See
  ** ticket #2685.
  */
#if 0
  if( mutexIsNT() && TryEnterCriticalSection(&p->mutex) ){
    p->owner = GetCurrentThreadId();
    p->nRef++;
    rc = SQLITE_OK;
  }
#endif
  return rc;
}
开发者ID:KnowNo,项目名称:test-code-backup,代码行数:23,代码来源:mutex_w32.c

示例9: switch

bool recursive_mutex::scoped_lock::internal_try_acquire( recursive_mutex& m ) {
#if _WIN32||_WIN64
    switch( m.state ) {
      case INITIALIZED:
        break;
      case DESTROYED:
        __TBB_ASSERT(false,"recursive_mutex::scoped_lock: mutex already destroyed");
        break;
      default:
        __TBB_ASSERT(false,"recursive_mutex::scoped_lock: illegal mutex state");
        break;
    }
#endif /* _WIN32||_WIN64 */
    bool result;
#if _WIN32||_WIN64
    result = TryEnterCriticalSection(&m.impl)!=0;
#else
    result = pthread_mutex_trylock(&m.impl)==0;
#endif /* _WIN32||_WIN64 */
    if( result )
        my_mutex = &m;
    return result;
}
开发者ID:LucaMarradi,项目名称:dealii,代码行数:23,代码来源:recursive_mutex.cpp

示例10: epicsMutexOsdTryLock

/*
 * epicsMutexOsdTryLock ()
 */
epicsMutexLockStatus epicsMutexOsdTryLock ( epicsMutexOSD * pSem ) 
{ 
    if ( thisIsNT ) {
        if ( TryEnterCriticalSection ( &pSem->os.criticalSection ) ) {
            return epicsMutexLockOK;
        }
        else {
            return epicsMutexLockTimeout;
        }
    }
    else {
        DWORD status = WaitForSingleObject ( pSem->os.mutex, 0 );
        if ( status != WAIT_OBJECT_0 ) {
            if (status == WAIT_TIMEOUT) {
                return epicsMutexLockTimeout;
            }
            else {
                return epicsMutexLockError;
            }
        }
    }
    return epicsMutexLockOK;
}
开发者ID:ukaea,项目名称:epics,代码行数:26,代码来源:osdMutex.c

示例11: hal_replytimereq

static TBOOL hal_replytimereq(struct TTimeRequest *tr)
{
	TBOOL success = TFALSE;
	struct TMessage *msg = TGETMSGPTR(tr);
	struct TMsgPort *mp = msg->tmsg_RPort;
	CRITICAL_SECTION *mplock = THALGetObject((TAPTR) &mp->tmp_Lock,
		CRITICAL_SECTION);
	if (TryEnterCriticalSection(mplock))
	{
		struct TTask *sigtask = mp->tmp_SigTask;
		struct HALThread *t =
			THALGetObject((TAPTR) &sigtask->tsk_Thread, struct HALThread);
#ifndef HAL_USE_ATOMICS
		if (TryEnterCriticalSection(&t->hth_SigLock))
#endif
		{
			tr->ttr_Req.io_Error = 0;
			msg->tmsg_Flags = TMSG_STATUS_REPLIED | TMSGF_QUEUED;
			TAddTail(&mp->tmp_MsgList, &msg->tmsg_Node);
#ifndef HAL_USE_ATOMICS
			if (mp->tmp_Signal & ~t->hth_SigState)
			{
				t->hth_SigState |= mp->tmp_Signal;
				SetEvent(t->hth_SigEvent);
			}
			LeaveCriticalSection(&t->hth_SigLock);
#else
			if (mp->tmp_Signal &
					~(TUINT) InterlockedOr(&t->hth_SigState, mp->tmp_Signal))
				SetEvent(t->hth_SigEvent);
#endif
			success = TTRUE;
		}
		LeaveCriticalSection(mplock);
	}
	return success;
}
开发者ID:callcc,项目名称:tekui,代码行数:37,代码来源:hal.c

示例12: Update

PLUGIN_EXPORT double Update(void* data)
{
	MeasureData* measure = (MeasureData*)data;

	if (TryEnterCriticalSection(&g_CriticalSection))
	{
		if (!g_Thread)
		{
			++g_UpdateCount;
			if (g_UpdateCount > g_InstanceCount)
			{
				if (HasRecycleBinChanged())
				{
					// Delay next check.
					g_UpdateCount = g_InstanceCount * -2;

					DWORD id;
					HANDLE thread = CreateThread(NULL, 0, QueryRecycleBinThreadProc, NULL, 0, &id);
					if (thread)
					{
						CloseHandle(thread);
						g_Thread = true;
					}
				}
				else
				{
					g_UpdateCount = 0;
				}
			}
		}

		LeaveCriticalSection(&g_CriticalSection);
	}

	return measure->count ? g_BinCount : g_BinSize;
}
开发者ID:JamesAC,项目名称:rainmeter,代码行数:36,代码来源:RecycleManager.cpp

示例13: TryLock

 bool TryLock() {
     return TryEnterCriticalSection(&critical_section) != 0;
 };
开发者ID:CnZoom,项目名称:XcSoarPull,代码行数:3,代码来源:CriticalSection.hpp

示例14: TryEnterCriticalSection

//==============================================================================
Bool Mutex::tryLock()
{
	CRITICAL_SECTION* mtx = reinterpret_cast<CRITICAL_SECTION*>(m_impl);
	BOOL enter = TryEnterCriticalSection(mtx);
	return enter;
}
开发者ID:zhouxh1023,项目名称:anki-3d-engine,代码行数:7,代码来源:ThreadWindows.cpp

示例15: TryLock

bit OwnedLock::TryLock() const
{
 if (TryEnterCriticalSection((CRITICAL_SECTION*)hand)) return true;
                                                  else return false;	
}
开发者ID:PeterZhouSZ,项目名称:hyperion,代码行数:5,代码来源:locks.cpp


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