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


C++ Locker类代码示例

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


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

示例1: removeSessionsRecords

/**
 * Removes the specified set of session ids from the persistent sessions collection and returns the
 * number of sessions actually removed.
 */
int removeSessionsRecords(OperationContext* opCtx,
                          SessionsCollection& sessionsCollection,
                          const LogicalSessionIdSet& sessionIdsToRemove) {
    if (sessionIdsToRemove.empty()) {
        return 0;
    }

    Locker* locker = opCtx->lockState();

    Locker::LockSnapshot snapshot;
    invariant(locker->saveLockStateAndUnlock(&snapshot));

    const auto guard = MakeGuard([&] {
        UninterruptibleLockGuard noInterrupt(opCtx->lockState());
        locker->restoreLockState(opCtx, snapshot);
    });

    // Top-level locks are freed, release any potential low-level (storage engine-specific
    // locks). If we are yielding, we are at a safe place to do so.
    opCtx->recoveryUnit()->abandonSnapshot();

    // Track the number of yields in CurOp.
    CurOp::get(opCtx)->yielded();

    auto removed =
        uassertStatusOK(sessionsCollection.findRemovedSessions(opCtx, sessionIdsToRemove));
    uassertStatusOK(sessionsCollection.removeTransactionRecords(opCtx, removed));

    return removed.size();
}
开发者ID:EvgeniyPatlan,项目名称:percona-server-mongodb,代码行数:34,代码来源:transaction_reaper.cpp

示例2: yieldAllLocks

// static
void QueryYield::yieldAllLocks(OperationContext* opCtx,
                               stdx::function<void()> whileYieldingFn,
                               const NamespaceString& planExecNS) {
    // Things have to happen here in a specific order:
    //   * Release lock mgr locks
    //   * Go to sleep
    //   * Call the whileYieldingFn
    //   * Reacquire lock mgr locks

    Locker* locker = opCtx->lockState();

    Locker::LockSnapshot snapshot;

    // Nothing was unlocked, just return, yielding is pointless.
    if (!locker->saveLockStateAndUnlock(&snapshot)) {
        return;
    }

    // Top-level locks are freed, release any potential low-level (storage engine-specific
    // locks). If we are yielding, we are at a safe place to do so.
    opCtx->recoveryUnit()->abandonSnapshot();

    // Track the number of yields in CurOp.
    CurOp::get(opCtx)->yielded();

    MONGO_FAIL_POINT_BLOCK(setYieldAllLocksHang, config) {
        StringData ns{config.getData().getStringField("namespace")};
        if (ns.empty() || ns == planExecNS.ns()) {
            MONGO_FAIL_POINT_PAUSE_WHILE_SET(setYieldAllLocksHang);
        }
    }
开发者ID:EvgeniyPatlan,项目名称:percona-server-mongodb,代码行数:32,代码来源:query_yield.cpp

示例3: rasterModelChanged

void OpenRasterUIComponent::rasterModelChanged() {
    Locker<const AbstractRasterModel> rasterModel = MainWindow::instance()->rasterModelForRead();
    bool isUsable = rasterModel() ? rasterModel()->isUsable() : false;
    rasterModel.unlock();

    /* Enable "close raster" only if map view and raster is available */
    closeRasterAction->setEnabled(MainWindow::instance()->mapView() && isUsable);
}
开发者ID:mosra,项目名称:kompas-qt,代码行数:8,代码来源:OpenRasterUIComponent.cpp

示例4: BeginDraw

bool CVideoDevice::BeginDraw(CDirectxBase* newFocus, ID3D10Device1*& pDevice, Locker& devLock)
{
	devLock.set(m_drawLock);
	devLock.lock();
	pDevice = m_pDevice;
	bool bFocusChange = m_currentFocus != newFocus;
	m_currentFocus = newFocus;
	return bFocusChange;
}
开发者ID:mstramb,项目名称:modHpsdr,代码行数:9,代码来源:device.cpp

示例5: wait

void CondVar::wait(Locker &l)
{
    Service *pService = Service::getFiberService();

    if (pService)
    {
        l.unlock();

        m_blocks.put(pService->m_running);
        pService->switchtonext();

        l.lock();
    }
}
开发者ID:java10000,项目名称:fibjs,代码行数:14,代码来源:fbCondVar.cpp

示例6: main

int main()
{
    typedef std::queue<char> Queue;
    LockObject<Queue> shared_queue;
    std::atomic<bool> quit;
    
    // producer adds items to the queue
    std::thread producer([&shared_queue, &quit]()
    {
        while (!quit)
        {
            Locker<Queue> lock = shared_queue.lock(); // locks the mutex        
            Queue & queue = lock.get();
            for (char c = ' '; c <= '~'; ++c)
            {
                queue.push(c);
            }
        }
    });
    
    // consumer thread removes items from the queue
    std::thread consumer([&shared_queue, &quit]()
    {
        while (!quit)
        {
            std::string current;
            {
                Locker<Queue> lock = shared_queue.lock(); // locks the mutex        
                Queue & queue = lock.get(); 
                if (queue.empty()) return;
                while (!queue.empty())
                {
                    current.push_back(std::move(queue.front()));
                    queue.pop();
                }
            }
            std::cout << current << '\n';
            current.clear();
        }
    });    
    
    std::this_thread::sleep_for(std::chrono::milliseconds(1));
    quit = true;
    producer.join();
    consumer.join();
}
开发者ID:CCJY,项目名称:coliru,代码行数:46,代码来源:main.cpp

示例7: yieldAllLocks

// static
void QueryYield::yieldAllLocks(OperationContext* txn,
                               RecordFetcher* fetcher,
                               const std::string& planExecNS) {
    // Things have to happen here in a specific order:
    //   1) Tell the RecordFetcher to do any setup which needs to happen inside locks
    //   2) Release lock mgr locks
    //   3) Go to sleep
    //   4) Touch the record we're yielding on, if there is one (RecordFetcher::fetch)
    //   5) Reacquire lock mgr locks

    Locker* locker = txn->lockState();

    Locker::LockSnapshot snapshot;

    if (fetcher) {
        fetcher->setup();
    }

    // Nothing was unlocked, just return, yielding is pointless.
    if (!locker->saveLockStateAndUnlock(&snapshot)) {
        return;
    }

    // Top-level locks are freed, release any potential low-level (storage engine-specific
    // locks). If we are yielding, we are at a safe place to do so.
    txn->recoveryUnit()->abandonSnapshot();

    MONGO_FAIL_POINT_BLOCK(setYieldAllLocksWait, customWait) {
        const BSONObj& data = customWait.getData();
        BSONElement customWaitNS = data["namespace"];
        if (!customWaitNS || planExecNS == customWaitNS.str()) {
            sleepFor(stdx::chrono::milliseconds(data["waitForMillis"].numberInt()));
        }
    }

    // Track the number of yields in CurOp.
    CurOp::get(txn)->yielded();

    if (fetcher) {
        fetcher->fetch();
    }

    locker->restoreLockState(snapshot);
}
开发者ID:AnkyrinRepeat,项目名称:mongo,代码行数:45,代码来源:query_yield.cpp

示例8: thread_insert

//MultThread Insert
void* thread_insert(void *arg)
{
	printf("thread_insert....\n");
	//printf("thread_insert pid is %lu\n",(unsigned long)pthread_self());
	Locker* testLock = (Locker *)arg;
	testLock->lock(testLock);
	//pthread_mutex_lock(&mylock);
	if(0 == gddlink_update)
	{
		pthread_cond_signal(&cond);
	}
	gddlink_update=1;
	InsertDDLink(&L,&num[global_count%10]);
	printf("Insert element %d\n",num[global_count%10]);
	//pthread_mutex_unlock(&mylock);
	testLock->unlock(testLock);

	//return &estatus;
	pthread_exit(NULL);
}
开发者ID:finalshow820,项目名称:C_Project,代码行数:21,代码来源:dd_link_2_2.c

示例9: thread_display

//MultThread Display
void* thread_display(void *arg)
{
	printf("thread_dispaly....\n");
	//printf("thread_dispaly pid is %lu\n",(unsigned long)pthread_self());
	//pthread_mutex_lock(&mylock);
	Locker* testLock = (Locker *)arg;
	testLock->lock(testLock);
	while(0 == gddlink_update)
	{
		//pthread_cond_wait(&cond, &mylock);
		pthread_cond_wait(&cond, testLock->getlock(testLock));
	}

	gddlink_update=0;
	//printf("Disply DDLink,Global is %d\n",global_count);
	DDLinkForeach(&L, DDLinkForeachPrint,print_int);
	//pthread_mutex_unlock(&mylock);
	testLock->unlock(testLock);
	printf("\n");
	//return &estatus;
	pthread_exit(NULL);
}
开发者ID:finalshow820,项目名称:C_Project,代码行数:23,代码来源:dd_link_2_2.c

示例10: AddInstance

void SFont::AddInstance( SFontInstance * pcInstance )
{
	g_cFontLock.Lock();
	__assertw( g_cFontLock.IsLocked() );
	m_cInstances[pcInstance->m_cInstanceProperties] = pcInstance;
	g_cFontLock.Unlock();
}
开发者ID:rickcaudill,项目名称:Pyro,代码行数:7,代码来源:sfont.cpp

示例11: GetStringWidth

int SFontInstance::GetStringWidth( const char *pzString, int nLength )
{
	int nWidth = 0;

	g_cFontLock.Lock();
	while( nLength > 0 )
	{
		int nCharLen = utf8_char_length( *pzString );

		if( nCharLen > nLength )
		{
			break;
		}
		Glyph *pcGlyph = GetGlyph( FT_Get_Char_Index( m_pcFont->GetTTFace(), utf8_to_unicode( pzString ) ) );

		pzString += nCharLen;
		nLength -= nCharLen;
		if( pcGlyph == NULL )
		{
			dbprintf( "Error: GetStringWidth() failed to load glyph\n" );
			continue;
		}
		nWidth += pcGlyph->m_nAdvance.x;
	}
	g_cFontLock.Unlock();
	return ( nWidth );
}
开发者ID:rickcaudill,项目名称:Pyro,代码行数:27,代码来源:sfont.cpp

示例12: sizeof

SFontInstance::SFontInstance( SFont * pcFont, const FontProperty & cFP )
{
	m_bFixedWidth = pcFont->IsFixedWidth();
	g_cFontLock.Lock();

	m_pcFont = pcFont;
	m_nGlyphCount = pcFont->GetGlyphCount();

	if( m_nGlyphCount > 0 )
	{
		m_ppcGlyphTable = new Glyph *[m_nGlyphCount];
		memset( m_ppcGlyphTable, 0, m_nGlyphCount * sizeof( Glyph * ) );
	}
	else
	{
		m_ppcGlyphTable = NULL;
	}
	m_cInstanceProperties = cFP;

	FT_Face psFace = m_pcFont->GetTTFace();

	if( psFace->face_flags & FT_FACE_FLAG_SCALABLE )
	{
		FT_Set_Char_Size( psFace, m_cInstanceProperties.m_nPointSize, m_cInstanceProperties.m_nPointSize, 96, 96 );
	}
	else
	{
		FT_Set_Pixel_Sizes( psFace, 0, ( m_cInstanceProperties.m_nPointSize * 96 / 72 ) / 64 );
	}
	FT_Size psSize = psFace->size;


	m_nNomWidth = psSize->metrics.x_ppem;
	m_nNomHeight = psSize->metrics.y_ppem;

	if( psSize->metrics.descender > 0 )
	{
		m_nDescender = -( psSize->metrics.descender + 63 ) / 64;
//      m_nLineGap   = (psSize->metrics.height - (psSize->metrics.ascender + psSize->metrics.descender) + 63) / 64;
	}
	else
	{
		m_nDescender = ( psSize->metrics.descender + 63 ) / 64;
//      m_nLineGap   = (psSize->metrics.height - (psSize->metrics.ascender - psSize->metrics.descender) + 63) / 64;
	}
	m_nAscender = ( psSize->metrics.ascender + 63 ) / 64;
	m_nLineGap = ( psSize->metrics.height + 63 ) / 64 - ( m_nAscender - m_nDescender );
	m_nAdvance = ( psSize->metrics.max_advance + 63 ) / 64;

//    printf( "Size1(%d): %ld, %ld, %ld (%ld, %ld, %ld)\n", nPointSize, psSize->metrics.ascender, psSize->metrics.descender, psSize->metrics.height,
//          psSize->metrics.ascender / 64, psSize->metrics.descender / 64, psSize->metrics.height / 64 );

	// Register our self with the font

	m_pcFont->AddInstance( this );

	g_cFontLock.Unlock();
}
开发者ID:rickcaudill,项目名称:Pyro,代码行数:58,代码来源:sfont.cpp

示例13: GetFamilyCount

int FontServer::GetFamilyCount() const
{
	int nCount;

	g_cFontLock.Lock();
	nCount = m_cFamilies.size();
	g_cFontLock.Unlock();
	return ( nCount );
}
开发者ID:rickcaudill,项目名称:Pyro,代码行数:9,代码来源:sfont.cpp

示例14: SetProperties

status_t SFontInstance::SetProperties( const FontProperty & cFP )
{
	g_cFontLock.Lock();

	m_pcFont->RemoveInstance( this );

	m_cInstanceProperties = cFP;

	FT_Face psFace = m_pcFont->GetTTFace();

	if( psFace->face_flags & FT_FACE_FLAG_SCALABLE )
	{
		FT_Set_Char_Size( psFace, m_cInstanceProperties.m_nPointSize, m_cInstanceProperties.m_nPointSize, 96, 96 );
	}
	else
	{
		FT_Set_Pixel_Sizes( psFace, 0, ( m_cInstanceProperties.m_nPointSize * 96 / 72 ) / 64 );
	}

	FT_Size psSize = psFace->size;

	m_nNomWidth = psSize->metrics.x_ppem;
	m_nNomHeight = psSize->metrics.y_ppem;

	if( psSize->metrics.descender > 0 )
	{
		m_nDescender = -( psSize->metrics.descender + 63 ) / 64;
//      m_nLineGap   = (psSize->metrics.height - (psSize->metrics.ascender + psSize->metrics.descender) + 63) / 64;
	}
	else
	{
		m_nDescender = ( psSize->metrics.descender + 63 ) / 64;
//      m_nLineGap   = (psSize->metrics.height - (psSize->metrics.ascender - psSize->metrics.descender) + 63) / 64;
	}
	m_nAscender = ( psSize->metrics.ascender + 63 ) / 64;
	m_nLineGap = ( psSize->metrics.height + 63 ) / 64 - ( m_nAscender - m_nDescender );
	m_nAdvance = ( psSize->metrics.max_advance + 63 ) / 64;

//    printf( "Size2(%d): %ld, %ld, %ld (%ld, %ld, %ld)\n", nPointSize, psSize->metrics.ascender, psSize->metrics.descender, psSize->metrics.height,
//          psSize->metrics.ascender / 64, psSize->metrics.descender / 64, psSize->metrics.height / 64 );

	for( int i = 0; i < m_nGlyphCount; ++i )
	{
		if( m_ppcGlyphTable[i] != NULL )
		{
			delete[]reinterpret_cast < char *>( m_ppcGlyphTable[i] );

			m_ppcGlyphTable[i] = NULL;
		}
	}
	m_pcFont->AddInstance( this );

	g_cFontLock.Unlock();

	return ( 0 );
}
开发者ID:rickcaudill,项目名称:Pyro,代码行数:56,代码来源:sfont.cpp

示例15:

SFontInstance::~SFontInstance()
{
	g_cFontLock.Lock();
	m_pcFont->RemoveInstance( this );

	for( int i = 0; i < m_nGlyphCount; ++i )
	{
		delete[]reinterpret_cast < char *>( m_ppcGlyphTable[i] );
	}
	delete[]m_ppcGlyphTable;

	g_cFontLock.Unlock();
}
开发者ID:rickcaudill,项目名称:Pyro,代码行数:13,代码来源:sfont.cpp


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