本文整理汇总了C++中std::unique_lock::unlock方法的典型用法代码示例。如果您正苦于以下问题:C++ unique_lock::unlock方法的具体用法?C++ unique_lock::unlock怎么用?C++ unique_lock::unlock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::unique_lock
的用法示例。
在下文中一共展示了unique_lock::unlock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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
}
示例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;
}
示例3: 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();
}
}
示例4: 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);
}
示例5: 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;
}
示例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();
}
示例7: access_token_expired
bool access_token_expired(std::unique_lock<std::mutex>& lock, SyncSession& session) const override
{
session.advance_state(lock, waiting_for_access_token);
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);
return false;
}
示例8: 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);
}
示例9: 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);
}
}
示例10: pushConnection
// helper for releasing connection and placing it in pool
inline void pushConnection( std::unique_lock<std::mutex> &locker, ConPool &pool, redisConnection* con )
{
pool.second.push(con);
locker.unlock();
// notify other threads for their wake up in case of they are waiting
// about empty connection queue
pool.first.notify_one();
}
示例11: schedule
void RepeatedTimerTask::schedule(std::unique_lock<raft_mutex_t>& lck) {
_next_duetime =
butil::milliseconds_from_now(adjust_timeout_ms(_timeout_ms));
if (bthread_timer_add(&_timer, _next_duetime, on_timedout, this) != 0) {
lck.unlock();
LOG(ERROR) << "Fail to add timer";
return on_timedout(this);
}
}
示例12: resume
void SingleTaskScheduler::resume(std::unique_lock<Spinlock> lock) {
assert(task_->status == Suspended || task_->status == Listening);
assert(!task_->scheduled);
task_->status = Running;
task_->scheduled = false;
task_->resumes += 1;
resumed.store(true, std::memory_order_release);
lock.unlock();
}
示例13: FindNextEventInternal
bool Listener::FindNextEventInternal(
std::unique_lock<std::mutex> &lock,
Broadcaster *broadcaster, // nullptr for any broadcaster
const ConstString *broadcaster_names, // nullptr for any event
uint32_t num_broadcaster_names, uint32_t event_type_mask, EventSP &event_sp,
bool remove) {
// NOTE: callers of this function must lock m_events_mutex using a
// Mutex::Locker
// and pass the locker as the first argument. m_events_mutex is no longer
// recursive.
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EVENTS));
if (m_events.empty())
return false;
Listener::event_collection::iterator pos = m_events.end();
if (broadcaster == nullptr && broadcaster_names == nullptr &&
event_type_mask == 0) {
pos = m_events.begin();
} else {
pos = std::find_if(m_events.begin(), m_events.end(),
EventMatcher(broadcaster, broadcaster_names,
num_broadcaster_names, event_type_mask));
}
if (pos != m_events.end()) {
event_sp = *pos;
if (log != nullptr)
log->Printf("%p '%s' Listener::FindNextEventInternal(broadcaster=%p, "
"broadcaster_names=%p[%u], event_type_mask=0x%8.8x, "
"remove=%i) event %p",
static_cast<void *>(this), GetName(),
static_cast<void *>(broadcaster),
static_cast<const void *>(broadcaster_names),
num_broadcaster_names, event_type_mask, remove,
static_cast<void *>(event_sp.get()));
if (remove) {
m_events.erase(pos);
// Unlock the event queue here. We've removed this event and are about to
// return
// it so it should be okay to get the next event off the queue here - and
// it might
// be useful to do that in the "DoOnRemoval".
lock.unlock();
event_sp->DoOnRemoval();
}
return true;
}
event_sp.reset();
return false;
}
示例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;
}
示例15: 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();
}