• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ std::unique_lock类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了unique_lock类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: catch

std::cv_status s4u::ConditionVariable::wait_for(std::unique_lock<Mutex>& lock, double timeout) {
  try {
    simcall_cond_wait_timeout(cond_, lock.mutex()->mutex_, timeout);
    return std::cv_status::timeout;
  }
  catch (xbt_ex& e) {

    // If the exception was a timeout, we have to take the lock again:
    if (e.category == timeout_error) {
      try {
        lock.mutex()->lock();
        return std::cv_status::timeout;
      }
      catch (...) {
        std::terminate();
      }
    }

    // Another exception: should we reaquire the lock?
    std::terminate();
  }
  catch (...) {
    std::terminate();
  }
}
开发者ID:oar-team,项目名称:simgrid-batsim,代码行数:25,代码来源:s4u_conditionVariable.cpp


示例3: maybe_notify

	void alert_manager::maybe_notify(alert* a, std::unique_lock<std::mutex>& lock)
	{
		if (m_alerts[m_generation].size() == 1)
		{
			lock.unlock();

			// we just posted to an empty queue. If anyone is waiting for
			// alerts, we need to notify them. Also (potentially) call the
			// user supplied m_notify callback to let the client wake up its
			// message loop to poll for alerts.
			if (m_notify) m_notify();

			// TODO: 2 keep a count of the number of threads waiting. Only if it's
			// > 0 notify them
			m_condition.notify_all();
		}
		else
		{
			lock.unlock();
		}

#ifndef TORRENT_DISABLE_EXTENSIONS
		for (auto& e : m_ses_extensions)
			e->on_alert(a);
#else
		TORRENT_UNUSED(a);
#endif
	}
开发者ID:digideskio,项目名称:libtorrent,代码行数:28,代码来源:alert_manager.cpp


示例4: proceed

void Solver::proceed(std::unique_lock<std::mutex>& lock)
{
	assert(lock.mutex() == &workerMutex && lock.owns_lock());
	wakeMainThreadRequested = true;
	wakeMainThread.notify_one();
	wakeWorkerThread.wait(lock, [&]() { return wakeWorkerThreadRequested; });
	wakeWorkerThreadRequested = false;
}
开发者ID:hmarkus,项目名称:dflat-2,代码行数:8,代码来源:Solver.cpp


示例5: unregister

void SyncSession::unregister(std::unique_lock<std::mutex>& lock)
{
    REALM_ASSERT(lock.owns_lock());
    REALM_ASSERT(m_state == &State::inactive); // Must stop an active session before unregistering.

    lock.unlock();
    SyncManager::shared().unregister_session(m_realm_path);
}
开发者ID:gerlandiolucena,项目名称:iosvisits,代码行数:8,代码来源:sync_session.cpp


示例6: 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


示例7: 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


示例8: 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


示例9: check_buffer_level

	// checks to see if we're no longer exceeding the high watermark,
	// and if we're in fact below the low watermark. If so, we need to
	// post the notification messages to the peers that are waiting for
	// more buffers to received data into
	void disk_buffer_pool::check_buffer_level(std::unique_lock<std::mutex>& l)
	{
		TORRENT_ASSERT(l.owns_lock());
		if (!m_exceeded_max_size || m_in_use > m_low_watermark) return;

		m_exceeded_max_size = false;

		std::vector<std::weak_ptr<disk_observer>> cbs;
		m_observers.swap(cbs);
		l.unlock();
		m_ios.post(std::bind(&watermark_callback, std::move(cbs)));
	}
开发者ID:ajax16384,项目名称:libtorrent,代码行数:16,代码来源:disk_buffer_pool.cpp


示例10: 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


示例11: 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


示例12: 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


示例13: 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


示例14: push_and_notify_

 channel_op_status push_and_notify_( ptr_t new_node,
                                     std::unique_lock< mutex > & lk) noexcept {
     push_tail_( new_node);
     lk.unlock();
     not_empty_cond_.notify_one();
     return channel_op_status::success;
 }
开发者ID:tempbottle,项目名称:boost-fiber,代码行数:7,代码来源:unbounded_channel.hpp


示例15: addFunctionToHeap

void FunctionScheduler::addFunctionToHeap(
    const std::unique_lock<std::mutex>& lock,
    RepeatFunc&& func) {
  // This function should only be called with mutex_ already locked.
  DCHECK(lock.mutex() == &mutex_);
  DCHECK(lock.owns_lock());

  functions_.emplace_back(std::move(func));
  if (running_) {
    functions_.back().resetNextRunTime(steady_clock::now());
    std::push_heap(functions_.begin(), functions_.end(), fnCmp_);
    // Signal the running thread to wake up and see if it needs to change
    // its current scheduling decision.
    runningCondvar_.notify_one();
  }
}
开发者ID:1Hgm,项目名称:folly,代码行数:16,代码来源:FunctionScheduler.cpp


示例16: run

 bool io_service_thread_pool::run(std::unique_lock<compat::mutex>& l,
     std::size_t num_threads)
 {
     HPX_ASSERT(l.owns_lock());
     compat::barrier startup(1);
     return threads_.run(num_threads, false, &startup);
 }
开发者ID:K-ballo,项目名称:hpx,代码行数:7,代码来源:io_service_thread_pool.cpp


示例17: advance_state

void SyncSession::advance_state(std::unique_lock<std::mutex>& lock, const State& state)
{
    REALM_ASSERT(lock.owns_lock());
    REALM_ASSERT(&state != m_state);
    m_state = &state;
    m_state->enter_state(lock, *this);
}
开发者ID:gerlandiolucena,项目名称:iosvisits,代码行数:7,代码来源:sync_session.cpp


示例18: handle_reconnect

 void handle_reconnect(std::unique_lock<std::mutex>& lock, SyncSession& session) const override
 {
     // Ask the binding to retry getting the token for this session.
     std::shared_ptr<SyncSession> session_ptr = session.shared_from_this();
     lock.unlock();
     session.m_config.bind_session_handler(session_ptr->m_realm_path, session_ptr->m_config, session_ptr);
 }
开发者ID:AlanAherne,项目名称:BabyTunes,代码行数:7,代码来源:sync_session.cpp


示例19: erase

 virtual void erase (std::unique_lock <std::mutex>& guard, std::shared_ptr <Resource> resource) noexcept {
    assert (guard.mutex () == &m_mutex);
    
    resource_iterator ii = m_resources.find (resource->getId ());
    
    if (ii != resource_end ())
       m_resources.erase (ii);
 }
开发者ID:ciscoruiz,项目名称:emc2,代码行数:8,代码来源:ResourceContainer.hpp


示例20: 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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ std::unique_ptr类代码示例发布时间:2022-05-31
下一篇:
C++ std::u32string类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap