Compare commits
No commits in common. "peek_support" and "master" have entirely different histories.
peek_suppo
...
master
@ -8,7 +8,6 @@ void Channel::exportAPI(sol::state_view& lua) {
|
|||||||
sol::usertype<Channel> type("new", sol::no_constructor,
|
sol::usertype<Channel> type("new", sol::no_constructor,
|
||||||
"push", &Channel::push,
|
"push", &Channel::push,
|
||||||
"pop", &Channel::pop,
|
"pop", &Channel::pop,
|
||||||
"peek", &Channel::peek,
|
|
||||||
"size", &Channel::size
|
"size", &Channel::size
|
||||||
);
|
);
|
||||||
sol::stack::push(lua, type);
|
sol::stack::push(lua, type);
|
||||||
@ -85,33 +84,6 @@ StoredArray Channel::pop(const sol::optional<int>& duration,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
StoredArray Channel::peek(const sol::optional<int>& duration,
|
|
||||||
const sol::optional<std::string>& period) {
|
|
||||||
this_thread::cancellationPoint();
|
|
||||||
std::unique_lock<std::mutex> lock(ctx_->lock_);
|
|
||||||
{
|
|
||||||
this_thread::ScopedSetInterruptable interruptable(this);
|
|
||||||
|
|
||||||
Timer timer(duration ? fromLuaTime(duration.value(), period) :
|
|
||||||
std::chrono::milliseconds());
|
|
||||||
while (ctx_->channel_.empty()) {
|
|
||||||
if (duration) {
|
|
||||||
if (timer.isFinished() ||
|
|
||||||
ctx_->cv_.wait_for(lock, timer.left()) ==
|
|
||||||
std::cv_status::timeout) {
|
|
||||||
return StoredArray();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else { // No time limit
|
|
||||||
ctx_->cv_.wait(lock);
|
|
||||||
}
|
|
||||||
this_thread::cancellationPoint();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ctx_->channel_.front();
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t Channel::size() {
|
size_t Channel::size() {
|
||||||
std::lock_guard<std::mutex> lock(ctx_->lock_);
|
std::lock_guard<std::mutex> lock(ctx_->lock_);
|
||||||
return ctx_->channel_.size();
|
return ctx_->channel_.size();
|
||||||
|
|||||||
@ -25,9 +25,6 @@ public:
|
|||||||
StoredArray pop(const sol::optional<int>& duration,
|
StoredArray pop(const sol::optional<int>& duration,
|
||||||
const sol::optional<std::string>& period);
|
const sol::optional<std::string>& period);
|
||||||
|
|
||||||
StoredArray peek(const sol::optional<int>& duration,
|
|
||||||
const sol::optional<std::string>& period);
|
|
||||||
|
|
||||||
size_t size();
|
size_t size();
|
||||||
|
|
||||||
void interrupt() final;
|
void interrupt() final;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user