Simplify reader_wait and fix some includes.

GitOrigin-RevId: 32a91a6aa25934b2eeeddd99470a24871f38d219
This commit is contained in:
levlam 2018-09-13 21:22:25 +03:00
parent 3745cec3cb
commit 56f5f4e263
6 changed files with 6 additions and 28 deletions

View File

@ -13,7 +13,6 @@
#include "td/utils/crypto.h" #include "td/utils/crypto.h"
#include "td/utils/logging.h" #include "td/utils/logging.h"
#include "td/utils/MpscPollableQueue.h" #include "td/utils/MpscPollableQueue.h"
#include "td/utils/port/Poll.h"
#include "td/utils/port/PollFlags.h" #include "td/utils/port/PollFlags.h"
#include "td/utils/port/thread.h" #include "td/utils/port/thread.h"

View File

@ -13,11 +13,6 @@
#include "td/utils/SpinLock.h" #include "td/utils/SpinLock.h"
#if !TD_WINDOWS
#include <poll.h>
#include <sched.h>
#endif
#include <utility> #include <utility>
namespace td { namespace td {
@ -79,21 +74,14 @@ class MpscPollableQueue {
} }
} }
// Just example of usage // Just an example of usage
#if !TD_WINDOWS
int reader_wait() { int reader_wait() {
int res; int res;
while ((res = reader_wait_nonblock()) == 0) { while ((res = reader_wait_nonblock()) == 0) {
// TODO: reader_flush? reader_get_event_fd().wait(1000);
pollfd fd;
fd.fd = reader_get_event_fd().get_poll_info().native_fd().fd();
fd.events = POLLIN;
poll(&fd, 1, -1);
} }
return res; return res;
} }
#endif
private: private:
SpinLock lock_; SpinLock lock_;

View File

@ -17,9 +17,9 @@ char disable_linker_warning_about_empty_file_event_fd_bsd_cpp TD_UNUSED;
#include "td/utils/Slice.h" #include "td/utils/Slice.h"
#include <fcntl.h> #include <fcntl.h>
#include <poll.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/types.h> #include <sys/types.h>
#include <poll.h>
namespace td { namespace td {
namespace detail { namespace detail {

View File

@ -17,8 +17,8 @@ char disable_linker_warning_about_empty_file_event_fd_linux_cpp TD_UNUSED;
#include "td/utils/Slice.h" #include "td/utils/Slice.h"
#include <sys/eventfd.h> #include <sys/eventfd.h>
#include <unistd.h>
#include <poll.h> #include <poll.h>
#include <unistd.h>
namespace td { namespace td {
namespace detail { namespace detail {

View File

@ -11,11 +11,6 @@
#if !TD_THREAD_UNSUPPORTED && !TD_EVENTFD_UNSUPPORTED #if !TD_THREAD_UNSUPPORTED && !TD_EVENTFD_UNSUPPORTED
#if !TD_WINDOWS
#include <poll.h>
#include <sched.h>
#endif
#include <atomic> #include <atomic>
#include <type_traits> #include <type_traits>
#include <utility> #include <utility>
@ -393,18 +388,14 @@ class PollQueue : public QueueT {
return res; return res;
} }
// Just example of usage // Just an example of usage
#if !TD_WINDOWS
int reader_wait() { int reader_wait() {
int res; int res;
while ((res = reader_wait_nonblock()) == 0) { while ((res = reader_wait_nonblock()) == 0) {
// TODO: reader_flush?
reader_get_event_fd().wait(1000); reader_get_event_fd().wait(1000);
} }
return res; return res;
} }
#endif
private: private:
EventFd event_fd_; EventFd event_fd_;

View File

@ -35,7 +35,7 @@ TEST(Port, files) {
const int ITER_COUNT = 1000; const int ITER_COUNT = 1000;
for (int i = 0; i < ITER_COUNT; i++) { for (int i = 0; i < ITER_COUNT; i++) {
walk_path(main_dir, walk_path(main_dir,
[&](CSlice name, bool is_directory) mutable { [&](CSlice name, bool is_directory) {
if (!is_directory) { if (!is_directory) {
ASSERT_TRUE(name == fd_path || name == fd2_path); ASSERT_TRUE(name == fd_path || name == fd2_path);
} }