projects
/
folly.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix class member shadowing in folly::ProducerConsumerQueue
[folly.git]
/
folly
/
futures
/
ManualExecutor.cpp
diff --git
a/folly/futures/ManualExecutor.cpp
b/folly/futures/ManualExecutor.cpp
index c18476e58d92f30a04d4595e0aba04dc52513a32..7f69c41385060aadd1be619df472d570c5ab8b46 100644
(file)
--- a/
folly/futures/ManualExecutor.cpp
+++ b/
folly/futures/ManualExecutor.cpp
@@
-1,5
+1,5
@@
/*
/*
- * Copyright 201
4
Facebook, Inc.
+ * Copyright 201
7
Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@
-20,20
+20,12
@@
#include <string>
#include <tuple>
#include <string>
#include <tuple>
-#include <stdexcept>
-
namespace folly {
namespace folly {
-ManualExecutor::ManualExecutor() {
- if (sem_init(&sem_, 0, 0) == -1) {
- throw std::runtime_error(std::string("sem_init: ") + strerror(errno));
- }
-}
-
void ManualExecutor::add(Func callback) {
std::lock_guard<std::mutex> lock(lock_);
void ManualExecutor::add(Func callback) {
std::lock_guard<std::mutex> lock(lock_);
- funcs_.
push
(std::move(callback));
- sem_
post(&sem_
);
+ funcs_.
emplace
(std::move(callback));
+ sem_
.post(
);
}
size_t ManualExecutor::run() {
}
size_t ManualExecutor::run() {
@@
-48,7
+40,7
@@
size_t ManualExecutor::run() {
auto& sf = scheduledFuncs_.top();
if (sf.time > now_)
break;
auto& sf = scheduledFuncs_.top();
if (sf.time > now_)
break;
- funcs_.
push(sf.func
);
+ funcs_.
emplace(sf.moveOutFunc()
);
scheduledFuncs_.pop();
}
scheduledFuncs_.pop();
}
@@
-65,7
+57,7
@@
size_t ManualExecutor::run() {
// Balance the semaphore so it doesn't grow without bound
// if nobody is calling wait().
// This may fail (with EAGAIN), that's fine.
// Balance the semaphore so it doesn't grow without bound
// if nobody is calling wait().
// This may fail (with EAGAIN), that's fine.
- sem_
trywait(&sem_
);
+ sem_
.tryWait(
);
func = std::move(funcs_.front());
funcs_.pop();
func = std::move(funcs_.front());
funcs_.pop();
@@
-84,13
+76,7
@@
void ManualExecutor::wait() {
break;
}
break;
}
- auto ret = sem_wait(&sem_);
- if (ret == 0) {
- break;
- }
- if (errno != EINVAL) {
- throw std::runtime_error(std::string("sem_wait: ") + strerror(errno));
- }
+ sem_.wait();
}
}
}
}