Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1465)

Side by Side Diff: runtime/bin/eventhandler_fuchsia.h

Issue 2910853002: [Fuchsia] EventHandler: epoll -> ports v2 (Closed)
Patch Set: Call async wait directly from the Dart thread Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | runtime/bin/eventhandler_fuchsia.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #ifndef RUNTIME_BIN_EVENTHANDLER_FUCHSIA_H_ 5 #ifndef RUNTIME_BIN_EVENTHANDLER_FUCHSIA_H_
6 #define RUNTIME_BIN_EVENTHANDLER_FUCHSIA_H_ 6 #define RUNTIME_BIN_EVENTHANDLER_FUCHSIA_H_
7 7
8 #if !defined(RUNTIME_BIN_EVENTHANDLER_H_) 8 #if !defined(RUNTIME_BIN_EVENTHANDLER_H_)
9 #error Do not include eventhandler_fuchsia.h directly; use eventhandler.h. 9 #error Do not include eventhandler_fuchsia.h directly; use eventhandler.h.
10 #endif 10 #endif
11 11
12 #include <errno.h> 12 #include <errno.h>
13 #include <magenta/status.h>
14 #include <magenta/syscalls.h>
15 #include <magenta/syscalls/object.h>
16 #include <magenta/syscalls/port.h>
17 #include <mxio/private.h>
13 #include <sys/epoll.h> 18 #include <sys/epoll.h>
14 #include <sys/socket.h> 19 #include <sys/socket.h>
15 #include <unistd.h> 20 #include <unistd.h>
16 21
22 #include "bin/reference_counting.h"
23 #include "bin/thread.h"
17 #include "platform/signal_blocker.h" 24 #include "platform/signal_blocker.h"
18 25
19 namespace dart { 26 namespace dart {
20 namespace bin { 27 namespace bin {
21 28
29 class DescriptorInfo;
30
31 class IOHandle : public ReferenceCounted<IOHandle> {
32 public:
33 explicit IOHandle(intptr_t fd)
34 : ReferenceCounted(),
35 mutex_(new Mutex()),
36 write_events_enabled_(true),
37 read_events_enabled_(true),
38 fd_(fd),
39 handle_(MX_HANDLE_INVALID),
40 wait_key_(0),
41 mxio_(__mxio_fd_to_io(fd)) {}
42
43 intptr_t fd() const { return fd_; }
44
45 // Called from SocketBase::{Read(), Write()} and ServerSocket::Accept() on
46 // the Dart thread.
47 intptr_t Read(void* buffer, intptr_t num_bytes);
48 intptr_t Write(const void* buffer, intptr_t num_bytes);
49 intptr_t Accept(struct sockaddr* addr, socklen_t* addrlen);
50
51 // Called from the EventHandler thread.
52 void Close();
53 uint32_t MaskToEpollEvents(intptr_t mask);
54 // If port is MX_HANDLE_INVALID, AsyncWait uses the port from the previous
55 // call with a valid port handle.
56 bool AsyncWait(mx_handle_t port, uint32_t events, uint64_t key);
57 void CancelWait(mx_handle_t port, uint64_t key);
58 uint32_t WaitEnd(mx_signals_t observed);
59 intptr_t ToggleEvents(intptr_t event_mask);
60
61 static intptr_t EpollEventsToMask(intptr_t events);
62
63 private:
64 ~IOHandle() {
65 if (mxio_ != NULL) {
66 __mxio_release(mxio_);
67 }
68 delete mutex_;
69 }
70
71 mx_status_t ReadySignalsLocked(mx_signals_t* ready_signals);
abarth 2017/06/20 22:07:34 I didn't find any callers of this function.
zra 2017/06/20 22:22:27 Left over from previous approach. Removed.
72 bool AsyncWaitLocked(mx_handle_t port, uint32_t events, uint64_t key);
73
74 // Mutex that protects the state here.
75 Mutex* mutex_;
76 bool write_events_enabled_;
77 bool read_events_enabled_;
78 // TODO(zra): Add flag to enable/disable peer closed signal?
79 intptr_t fd_;
80 mx_handle_t handle_;
81 mx_handle_t port_;
82 uint64_t wait_key_;
83 mxio_t* mxio_;
84
85 friend class ReferenceCounted<IOHandle>;
86 DISALLOW_COPY_AND_ASSIGN(IOHandle);
87 };
88
22 class DescriptorInfo : public DescriptorInfoBase { 89 class DescriptorInfo : public DescriptorInfoBase {
23 public: 90 public:
24 explicit DescriptorInfo(intptr_t fd) : DescriptorInfoBase(fd) {} 91 explicit DescriptorInfo(intptr_t fd) : DescriptorInfoBase(fd) {
92 IOHandle* handle = reinterpret_cast<IOHandle*>(fd);
93 handle->Retain();
94 }
25 95
26 virtual ~DescriptorInfo() {} 96 virtual ~DescriptorInfo() {
27 97 IOHandle* handle = reinterpret_cast<IOHandle*>(fd_);
28 intptr_t GetPollEvents(); 98 handle->Release();
99 }
29 100
30 virtual void Close() { 101 virtual void Close() {
31 // Should be VOID_TEMP_FAILURE_RETRY 102 IOHandle* handle = reinterpret_cast<IOHandle*>(fd_);
32 VOID_NO_RETRY_EXPECTED(close(fd_)); 103 handle->Close();
33 fd_ = -1;
34 } 104 }
35 105
106 IOHandle* io_handle() const { return reinterpret_cast<IOHandle*>(fd_); }
107
36 private: 108 private:
37 DISALLOW_COPY_AND_ASSIGN(DescriptorInfo); 109 DISALLOW_COPY_AND_ASSIGN(DescriptorInfo);
38 }; 110 };
39 111
40 class DescriptorInfoSingle : public DescriptorInfoSingleMixin<DescriptorInfo> { 112 class DescriptorInfoSingle : public DescriptorInfoSingleMixin<DescriptorInfo> {
41 public: 113 public:
42 explicit DescriptorInfoSingle(intptr_t fd) 114 explicit DescriptorInfoSingle(intptr_t fd)
43 : DescriptorInfoSingleMixin(fd, false) {} 115 : DescriptorInfoSingleMixin(fd, false) {}
44 virtual ~DescriptorInfoSingle() {} 116 virtual ~DescriptorInfoSingle() {}
45 117
(...skipping 10 matching lines...) Expand all
56 128
57 private: 129 private:
58 DISALLOW_COPY_AND_ASSIGN(DescriptorInfoMultiple); 130 DISALLOW_COPY_AND_ASSIGN(DescriptorInfoMultiple);
59 }; 131 };
60 132
61 class EventHandlerImplementation { 133 class EventHandlerImplementation {
62 public: 134 public:
63 EventHandlerImplementation(); 135 EventHandlerImplementation();
64 ~EventHandlerImplementation(); 136 ~EventHandlerImplementation();
65 137
66 void UpdateEpollInstance(intptr_t old_mask, DescriptorInfo* di); 138 void UpdatePort(intptr_t old_mask, DescriptorInfo* di);
67 139
68 // Gets the socket data structure for a given file 140 // Gets the socket data structure for a given file
69 // descriptor. Creates a new one if one is not found. 141 // descriptor. Creates a new one if one is not found.
70 DescriptorInfo* GetDescriptorInfo(intptr_t fd, bool is_listening); 142 DescriptorInfo* GetDescriptorInfo(intptr_t fd, bool is_listening);
71 void SendData(intptr_t id, Dart_Port dart_port, int64_t data); 143 void SendData(intptr_t id, Dart_Port dart_port, int64_t data);
72 void Start(EventHandler* handler); 144 void Start(EventHandler* handler);
73 void Shutdown(); 145 void Shutdown();
74 146
75 private: 147 private:
148 static const uint64_t kInterruptPacketKey = 1;
149
76 static void Poll(uword args); 150 static void Poll(uword args);
77 static void* GetHashmapKeyFromFd(intptr_t fd); 151 static void* GetHashmapKeyFromFd(intptr_t fd);
78 static uint32_t GetHashmapHashFromFd(intptr_t fd); 152 static uint32_t GetHashmapHashFromFd(intptr_t fd);
153 static void AddToPort(mx_handle_t port_handle, DescriptorInfo* di);
154 static void RemoveFromPort(mx_handle_t port_handle, DescriptorInfo* di);
79 155
80 int64_t GetTimeout() const; 156 int64_t GetTimeout() const;
81 void HandleEvents(struct epoll_event* events, int size); 157 void HandlePacket(mx_port_packet_t* pkt);
82 void HandleTimeout(); 158 void HandleTimeout();
83 void WakeupHandler(intptr_t id, Dart_Port dart_port, int64_t data); 159 void WakeupHandler(intptr_t id, Dart_Port dart_port, int64_t data);
84 intptr_t GetPollEvents(intptr_t events, DescriptorInfo* di); 160 intptr_t GetPollEvents(intptr_t events);
85 void HandleInterruptFd(); 161 void HandleInterrupt(InterruptMessage* msg);
86 162
87 HashMap socket_map_; 163 HashMap socket_map_;
88 TimeoutQueue timeout_queue_; 164 TimeoutQueue timeout_queue_;
89 bool shutdown_; 165 bool shutdown_;
90 int interrupt_fds_[2]; 166 mx_handle_t port_handle_;
91 int epoll_fd_;
92 167
93 DISALLOW_COPY_AND_ASSIGN(EventHandlerImplementation); 168 DISALLOW_COPY_AND_ASSIGN(EventHandlerImplementation);
94 }; 169 };
95 170
96 } // namespace bin 171 } // namespace bin
97 } // namespace dart 172 } // namespace dart
98 173
99 #endif // RUNTIME_BIN_EVENTHANDLER_FUCHSIA_H_ 174 #endif // RUNTIME_BIN_EVENTHANDLER_FUCHSIA_H_
OLDNEW
« no previous file with comments | « no previous file | runtime/bin/eventhandler_fuchsia.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698