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


C++ unique_lock::lock方法代码示例

本文整理汇总了C++中std::unique_lock::lock方法的典型用法代码示例。如果您正苦于以下问题:C++ unique_lock::lock方法的具体用法?C++ unique_lock::lock怎么用?C++ unique_lock::lock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在std::unique_lock的用法示例。


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

示例1: stop_client

void F::stop_client (std::unique_lock <std::mutex> &lock)
{
  bool wasLocked;

  if (lock) {
    wasLocked = true;
  }

  if (!wasLocked) {
    lock.lock();
  }

  if (client) {
    client->stop();
  }

  terminate = true;

  lock.unlock();

  GST_DEBUG ("Waiting for client thread to finish");
  clientThread.join();

  if (wasLocked) {
    lock.lock();
  }
}
开发者ID:ArenaCloud,项目名称:kurento-media-server,代码行数:27,代码来源:BaseTest.cpp

示例2: DeviceCmdSetMode

CS_StatusValue UsbCameraImpl::DeviceCmdSetMode(
    std::unique_lock<wpi::mutex>& lock, const Message& msg) {
  VideoMode newMode;
  if (msg.kind == Message::kCmdSetMode) {
    newMode.pixelFormat = msg.data[0];
    newMode.width = msg.data[1];
    newMode.height = msg.data[2];
    newMode.fps = msg.data[3];
    m_modeSetPixelFormat = true;
    m_modeSetResolution = true;
    m_modeSetFPS = true;
  } else if (msg.kind == Message::kCmdSetPixelFormat) {
    newMode = m_mode;
    newMode.pixelFormat = msg.data[0];
    m_modeSetPixelFormat = true;
  } else if (msg.kind == Message::kCmdSetResolution) {
    newMode = m_mode;
    newMode.width = msg.data[0];
    newMode.height = msg.data[1];
    m_modeSetResolution = true;
  } else if (msg.kind == Message::kCmdSetFPS) {
    newMode = m_mode;
    newMode.fps = msg.data[0];
    m_modeSetFPS = true;
  }

  // If the pixel format or resolution changed, we need to disconnect and
  // reconnect
  if (newMode.pixelFormat != m_mode.pixelFormat ||
      newMode.width != m_mode.width || newMode.height != m_mode.height) {
    m_mode = newMode;
    lock.unlock();
    bool wasStreaming = m_streaming;
    if (wasStreaming) DeviceStreamOff();
    if (m_fd >= 0) {
      DeviceDisconnect();
      DeviceConnect();
    }
    if (wasStreaming) DeviceStreamOn();
    Notifier::GetInstance().NotifySourceVideoMode(*this, newMode);
    lock.lock();
  } else if (newMode.fps != m_mode.fps) {
    m_mode = newMode;
    lock.unlock();
    // Need to stop streaming to set FPS
    bool wasStreaming = m_streaming;
    if (wasStreaming) DeviceStreamOff();
    DeviceSetFPS();
    if (wasStreaming) DeviceStreamOn();
    Notifier::GetInstance().NotifySourceVideoMode(*this, newMode);
    lock.lock();
  }

  return CS_OK;
}
开发者ID:FRCTeam1967,项目名称:FRCTeam1967,代码行数:55,代码来源:UsbCameraImpl.cpp

示例3: threadFunc

  void threadFunc()
  {
    
    pauseLock.lock();
    while(isContinuing)
      {
	while (isPaused)
	  {
	    pauseCondition.wait(pauseLock);
	  }
	auto t0=g_clock::now();
	//
	consumeInput();
	//
	timeStep();
	// Render
	cbMutex.lock();
	if(nullptr!=cb)
	  {
	    (*cb)(mField,current,nullptr);
	  }
	cbMutex.unlock();
	// Cap game speed
	while(std::chrono::duration_cast<sleep_time>(g_clock::now()-t0).count() < frame_err)
	  {
	    std::this_thread::sleep_for(sleep_time(1));
	  }
      }

  }
开发者ID:01d55,项目名称:UnitTestris,代码行数:30,代码来源:TetrisGame.cpp

示例4: deallocateXLarge

void Heap::deallocateXLarge(std::unique_lock<StaticMutex>& lock, void* object)
{
    Range toDeallocate = m_xLargeObjects.pop(&findXLarge(lock, object));

    lock.unlock();
    vmDeallocate(toDeallocate.begin(), toDeallocate.size());
    lock.lock();
}
开发者ID:rhythmkay,项目名称:webkit,代码行数:8,代码来源:Heap.cpp

示例5: clearJobs

void DinicVertexLayerP::clearJobs(std::unique_lock<std::mutex>& lock, bool check)
{
	if (!lock.owns_lock())
	{
		lock.lock();
	}
	jobs.clear();
	jobs.swap(queueJobs);
	runJobs = vector<bool>(jobs.size(), false);
	assert(queueJobs.empty());
	if (check) assert(jobs.empty());
}
开发者ID:noahisch,项目名称:ParallelMaxFlow,代码行数:12,代码来源:DinicVertexLayer.cpp

示例6: runItemWithoutLock

void WorkQueue::runItemWithoutLock(std::unique_lock<std::mutex> &lock) {
    Item item = std::move(item_heap.front());
    std::pop_heap(std::begin(item_heap), std::end(item_heap));
    item_heap.pop_back();

    idle_flag = false;
    lock.unlock();
    item.func();
    lock.lock();
    idle_flag = true;
    cond.notify_all();
}
开发者ID:matthewbot,项目名称:Kube,代码行数:12,代码来源:WorkQueue.cpp

示例7: DeviceSet

bool UsbCameraProperty::DeviceSet(std::unique_lock<wpi::mutex>& lock,
                                  IAMVideoProcAmp* pProcAmp,
                                  int newValue) const {
  if (!pProcAmp) return true;

  lock.unlock();
  if (SUCCEEDED(
          pProcAmp->Set(tagVideoProc, newValue, VideoProcAmp_Flags_Manual))) {
    lock.lock();
    return true;
  }

  return false;
}
开发者ID:AustinShalit,项目名称:allwpilib,代码行数:14,代码来源:UsbCameraProperty.cpp

示例8: DeviceGet

bool UsbCameraProperty::DeviceGet(std::unique_lock<wpi::mutex>& lock,
                                  IAMVideoProcAmp* pProcAmp) {
  if (!pProcAmp) return true;

  lock.unlock();
  long newValue = 0, paramFlag = 0;  // NOLINT(runtime/int)
  if (SUCCEEDED(pProcAmp->Get(tagVideoProc, &newValue, &paramFlag))) {
    lock.lock();
    value = newValue;
    return true;
  }

  return false;
}
开发者ID:AustinShalit,项目名称:allwpilib,代码行数:14,代码来源:UsbCameraProperty.cpp

示例9: remove_oldest

	void file_pool::remove_oldest(std::unique_lock<std::mutex>& l)
	{
		file_set::iterator i = std::min_element(m_files.begin(), m_files.end()
			, boost::bind(&lru_file_entry::last_use, boost::bind(&file_set::value_type::second, _1))
				< boost::bind(&lru_file_entry::last_use, boost::bind(&file_set::value_type::second, _2)));
		if (i == m_files.end()) return;

		file_handle file_ptr = i->second.file_ptr;
		m_files.erase(i);

		// closing a file may be long running operation (mac os x)
		l.unlock();
		file_ptr.reset();
		l.lock();
	}
开发者ID:Meonardo,项目名称:libtorrent,代码行数:15,代码来源:file_pool.cpp

示例10: finishRelease

void PageInfo::finishRelease(std::unique_lock<std::mutex> lock) {
	delete[] p_buffer;
	
	lock.unlock();
	p_cache->p_cacheHost->afterRelease(this);
	lock.lock();
	
	if(p_waitQueue.empty()) {
		auto iterator = p_cache->p_presentPages.find(p_number);
		assert(iterator != p_cache->p_presentPages.end());
		p_cache->p_presentPages.erase(iterator);
		delete this;
	}else{
		lock.unlock();
		p_cache->p_cacheHost->requestAcquire(this);
	}
}
开发者ID:avdgrinten,项目名称:d3b,代码行数:17,代码来源:page-cache.cpp

示例11: disable

void natpmp::disable(error_code const& ec, std::unique_lock<std::mutex>& l)
{
	m_disabled = true;

	for (std::vector<mapping_t>::iterator i = m_mappings.begin()
		, end(m_mappings.end()); i != end; ++i)
	{
		if (i->protocol == none) continue;
		int const proto = i->protocol;
		i->protocol = none;
		int index = i - m_mappings.begin();
		l.unlock();
		m_callback(index, address(), 0, proto, ec);
		l.lock();
	}
	close_impl(l);
}
开发者ID:glassez,项目名称:libtorrent,代码行数:17,代码来源:natpmp.cpp

示例12: try_remove_change

bool StatefulWriter::try_remove_change(std::chrono::microseconds& microseconds,
        std::unique_lock<std::recursive_mutex>& lock)
{
    logInfo(RTPS_WRITER, "Starting process try remove change for writer " << getGuid());

    SequenceNumber_t min_low_mark;

    for(auto it = matched_readers.begin(); it != matched_readers.end(); ++it)
    {
        std::lock_guard<std::recursive_mutex> rguard(*(*it)->mp_mutex);

        if(min_low_mark == SequenceNumber_t() || (*it)->get_low_mark() < min_low_mark)
        {
            min_low_mark = (*it)->get_low_mark();
        }
    }

    SequenceNumber_t calc = min_low_mark < get_seq_num_min() ? SequenceNumber_t() :
        (min_low_mark - get_seq_num_min()) + 1;
    unsigned int may_remove_change = 1;

    if(calc <= SequenceNumber_t())
    {
        lock.unlock();
        std::unique_lock<std::mutex> may_lock(may_remove_change_mutex_);
        may_remove_change_ = 0;
        may_remove_change_cond_.wait_for(may_lock, microseconds,
                [&]() { return may_remove_change_ > 0; });
        may_remove_change = may_remove_change_;
        may_lock.unlock();
        lock.lock();
    }

    // Some changes acked
    if(may_remove_change == 1)
    {
        return mp_history->remove_min_change();
    }
    // Waiting a change was removed.
    else if(may_remove_change == 2)
    {
        return true;
    }

    return false;
}
开发者ID:esteve,项目名称:Fast-RTPS,代码行数:46,代码来源:StatefulWriter.cpp

示例13: releaseItem

void CacheHost::releaseItem(Cacheable *item,
		std::unique_lock<std::mutex> &lock) {
	assert(lock.owns_lock());
	
	assert(item != &p_sentinel);
	item->p_alive = false;
	p_activeFootprint -= item->getFootprint();

	// remove the item from the list
	Cacheable *less_recently = item->p_lessRecentlyUsed;
	Cacheable *more_recently = item->p_moreRecentlyUsed;
	less_recently->p_moreRecentlyUsed = more_recently;
	more_recently->p_lessRecentlyUsed = less_recently;

	lock.unlock();
	item->release();
	lock.lock();
}
开发者ID:avdgrinten,项目名称:d3b,代码行数:18,代码来源:page-cache.cpp

示例14: UnlockAndFlushToBodyReader

int HttpMessage::UnlockAndFlushToBodyReader(std::unique_lock<butil::Mutex>& mu) {
    if (_body.empty()) {
        mu.unlock();
        return 0;
    }
    butil::IOBuf body_seen = _body.movable();
    ProgressiveReader* r = _body_reader;
    mu.unlock();
    for (size_t i = 0; i < body_seen.backing_block_num(); ++i) {
        butil::StringPiece blk = body_seen.backing_block(i);
        butil::Status st = r->OnReadOnePart(blk.data(), blk.size());
        if (!st.ok()) {
            mu.lock();
            _body_reader = NULL;
            mu.unlock();
            r->OnEndOfMessage(st);
            return -1;
        }
    }
    return 0;
}
开发者ID:yzhenma,项目名称:brpc,代码行数:21,代码来源:http_message.cpp

示例15: log

void natpmp::log(char const* msg, std::unique_lock<std::mutex>& l)
{
	l.unlock();
	m_log_callback(msg);
	l.lock();
}
开发者ID:glassez,项目名称:libtorrent,代码行数:6,代码来源:natpmp.cpp


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