本文整理汇总了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();
}
示例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);
}
}
示例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);
}
示例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;
}
示例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();
}
}
示例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();
}
示例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);
}
示例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);
}
示例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);
}
示例10: AddInstance
void SFont::AddInstance( SFontInstance * pcInstance )
{
g_cFontLock.Lock();
__assertw( g_cFontLock.IsLocked() );
m_cInstances[pcInstance->m_cInstanceProperties] = pcInstance;
g_cFontLock.Unlock();
}
示例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 );
}
示例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();
}
示例13: GetFamilyCount
int FontServer::GetFamilyCount() const
{
int nCount;
g_cFontLock.Lock();
nCount = m_cFamilies.size();
g_cFontLock.Unlock();
return ( nCount );
}
示例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 );
}
示例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();
}