本文整理汇总了C++中Cond::Wait方法的典型用法代码示例。如果您正苦于以下问题:C++ Cond::Wait方法的具体用法?C++ Cond::Wait怎么用?C++ Cond::Wait使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cond
的用法示例。
在下文中一共展示了Cond::Wait方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: lower_bound
VPtr lower_bound(const K& key) {
VPtr val;
list<VPtr> to_release;
{
Mutex::Locker l(lock);
bool retry = false;
do {
retry = false;
if (weak_refs.empty())
break;
typename map<K, WeakVPtr>::iterator i = weak_refs.lower_bound(key);
if (i == weak_refs.end())
--i;
val = i->second.lock();
if (val) {
lru_add(i->first, val, &to_release);
} else {
retry = true;
}
if (retry)
cond.Wait(lock);
} while (retry);
}
return val;
}
示例2: lookup_or_create
VPtr lookup_or_create(const K &key) {
VPtr val;
list<VPtr> to_release;
{
Mutex::Locker l(lock);
bool retry = false;
do {
retry = false;
typename map<K, pair<WeakVPtr, V*>, C>::iterator i = weak_refs.find(key);
if (i != weak_refs.end()) {
val = i->second.first.lock();
if (val) {
lru_add(key, val, &to_release);
return val;
} else {
retry = true;
}
}
if (retry)
cond.Wait(lock);
} while (retry);
V *new_value = new V();
VPtr new_val(new_value, Cleanup(this, key));
weak_refs.insert(make_pair(key, make_pair(new_val, new_value)));
lru_add(key, new_val, &to_release);
return new_val;
}
}
示例3: lookup
VPtr lookup(const K& key) {
VPtr val;
list<VPtr> to_release;
{
Mutex::Locker l(lock);
++waiting;
bool retry = false;
do {
retry = false;
typename map<K, pair<WeakVPtr, V*>, C>::iterator i = weak_refs.find(key);
if (i != weak_refs.end()) {
val = i->second.first.lock();
if (val) {
lru_add(key, val, &to_release);
} else {
retry = true;
}
}
if (retry)
cond.Wait(lock);
} while (retry);
--waiting;
}
return val;
}
示例4: lookup
VPtr lookup(const K &key) {
Mutex::Locker l(lock);
while (1) {
if (contents.count(key)) {
VPtr retval = contents[key].lock();
if (retval)
return retval;
} else {
break;
}
cond.Wait(lock);
Mutex::Locker l(lock);
}
return VPtr();
}
示例5: lookup_or_create
VPtr lookup_or_create(const K &key, const A &arg) {
Mutex::Locker l(lock);
while (1) {
if (contents.count(key)) {
VPtr retval = contents[key].lock();
if (retval)
return retval;
} else {
break;
}
cond.Wait(lock);
}
VPtr retval(new V(arg), OnRemoval(this, key));
contents[key] = retval;
return retval;
}
示例6: lookup
VPtr lookup(const K &key) {
Mutex::Locker l(lock);
waiting++;
while (1) {
typename map<K, pair<WeakVPtr, V*> >::iterator i =
contents.find(key);
if (i != contents.end()) {
VPtr retval = i->second.first.lock();
if (retval) {
waiting--;
return retval;
}
} else {
break;
}
cond.Wait(lock);
}
waiting--;
return VPtr();
}
示例7: lookup
VPtr lookup(K key) {
VPtr val;
list<VPtr> to_release;
{
Mutex::Locker l(lock);
bool retry = false;
do {
retry = false;
if (weak_refs.count(key)) {
val = weak_refs[key].lock();
if (val) {
lru_add(key, val, &to_release);
} else {
retry = true;
}
}
if (retry)
cond.Wait(lock);
} while (retry);
}
return val;
}
示例8: lookup_or_create
VPtr lookup_or_create(const K &key, const A &arg) {
Mutex::Locker l(lock);
waiting++;
while (1) {
typename map<K, pair<WeakVPtr, V*> >::iterator i =
contents.find(key);
if (i != contents.end()) {
VPtr retval = i->second.first.lock();
if (retval) {
waiting--;
return retval;
}
} else {
break;
}
cond.Wait(lock);
}
V *ptr = new V(arg);
VPtr retval(ptr, OnRemoval(this, key));
contents.insert(make_pair(key, make_pair(retval, ptr)));
waiting--;
return retval;
}
示例9: Wait
bool Wait(unsigned timeout_ms=5000) {
const ScopeLock protect(mutex);
return done || (cond.Wait(mutex, timeout_ms) && done);
}
示例10: WaitUntilNotRunning
void WaitUntilNotRunning() {
while (running)
cond.Wait(mutex);
}