OLD | NEW |
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 #if !defined(DART_IO_DISABLED) | 5 #if !defined(DART_IO_DISABLED) |
6 | 6 |
7 #include "platform/globals.h" | 7 #include "platform/globals.h" |
8 #if defined(TARGET_OS_FUCHSIA) | 8 #if defined(TARGET_OS_FUCHSIA) |
9 | 9 |
10 #include "bin/eventhandler.h" | 10 #include "bin/eventhandler.h" |
11 #include "bin/eventhandler_fuchsia.h" | 11 #include "bin/eventhandler_fuchsia.h" |
12 | 12 |
13 #include <magenta/syscalls.h> | 13 #include <magenta/syscalls.h> |
14 #include <runtime/status.h> | 14 #include <runtime/status.h> |
15 | 15 |
16 #include "bin/thread.h" | 16 #include "bin/thread.h" |
17 #include "bin/utils.h" | 17 #include "bin/utils.h" |
18 | 18 |
19 namespace dart { | 19 namespace dart { |
20 namespace bin { | 20 namespace bin { |
21 | 21 |
22 EventHandlerImplementation::EventHandlerImplementation() { | 22 EventHandlerImplementation::EventHandlerImplementation() { |
23 mx_status_t status = mx_message_pipe_create(interrupt_handles_, 0); | 23 mx_status_t status = mx_msgpipe_create(interrupt_handles_, 0); |
24 if (status != NO_ERROR) { | 24 if (status != NO_ERROR) { |
25 FATAL1("mx_message_pipe_create failed: %s\n", mx_strstatus(status)); | 25 FATAL1("mx_msgpipe_create failed: %s\n", mx_strstatus(status)); |
26 } | 26 } |
27 } | 27 } |
28 | 28 |
29 | 29 |
30 EventHandlerImplementation::~EventHandlerImplementation() { | 30 EventHandlerImplementation::~EventHandlerImplementation() { |
31 mx_status_t status = mx_handle_close(interrupt_handles_[0]); | 31 mx_status_t status = mx_handle_close(interrupt_handles_[0]); |
32 if (status != NO_ERROR) { | 32 if (status != NO_ERROR) { |
33 FATAL1("mx_handle_close failed: %s\n", mx_strstatus(status)); | 33 FATAL1("mx_handle_close failed: %s\n", mx_strstatus(status)); |
34 } | 34 } |
35 status = mx_handle_close(interrupt_handles_[1]); | 35 status = mx_handle_close(interrupt_handles_[1]); |
36 if (status != NO_ERROR) { | 36 if (status != NO_ERROR) { |
37 FATAL1("mx_handle_close failed: %s\n", mx_strstatus(status)); | 37 FATAL1("mx_handle_close failed: %s\n", mx_strstatus(status)); |
38 } | 38 } |
39 } | 39 } |
40 | 40 |
41 | 41 |
42 void EventHandlerImplementation::WakeupHandler(intptr_t id, | 42 void EventHandlerImplementation::WakeupHandler(intptr_t id, |
43 Dart_Port dart_port, | 43 Dart_Port dart_port, |
44 int64_t data) { | 44 int64_t data) { |
45 InterruptMessage msg; | 45 InterruptMessage msg; |
46 msg.id = id; | 46 msg.id = id; |
47 msg.dart_port = dart_port; | 47 msg.dart_port = dart_port; |
48 msg.data = data; | 48 msg.data = data; |
49 | 49 |
50 mx_status_t status = | 50 mx_status_t status = |
51 mx_message_write(interrupt_handles_[1], &msg, sizeof(msg), NULL, 0, 0); | 51 mx_msgpipe_write(interrupt_handles_[1], &msg, sizeof(msg), NULL, 0, 0); |
52 if (status != NO_ERROR) { | 52 if (status != NO_ERROR) { |
53 FATAL1("mx_message_write failed: %s\n", mx_strstatus(status)); | 53 FATAL1("mx_msgpipe_write failed: %s\n", mx_strstatus(status)); |
54 } | 54 } |
55 } | 55 } |
56 | 56 |
57 | 57 |
58 void EventHandlerImplementation::HandleInterruptFd() { | 58 void EventHandlerImplementation::HandleInterruptFd() { |
59 InterruptMessage msg; | 59 InterruptMessage msg; |
60 uint32_t bytes = kInterruptMessageSize; | 60 uint32_t bytes = kInterruptMessageSize; |
61 mx_status_t status; | 61 mx_status_t status; |
62 while (true) { | 62 while (true) { |
63 status = mx_message_read( | 63 status = mx_msgpipe_read( |
64 interrupt_handles_[0], &msg, &bytes, NULL, NULL, 0); | 64 interrupt_handles_[0], &msg, &bytes, NULL, NULL, 0); |
65 if (status != NO_ERROR) { | 65 if (status != NO_ERROR) { |
66 break; | 66 break; |
67 } | 67 } |
68 ASSERT(bytes == kInterruptMessageSize); | 68 ASSERT(bytes == kInterruptMessageSize); |
69 if (msg.id == kTimerId) { | 69 if (msg.id == kTimerId) { |
70 timeout_queue_.UpdateTimeout(msg.dart_port, msg.data); | 70 timeout_queue_.UpdateTimeout(msg.dart_port, msg.data); |
71 } else if (msg.id == kShutdownId) { | 71 } else if (msg.id == kShutdownId) { |
72 shutdown_ = true; | 72 shutdown_ = true; |
73 } else { | 73 } else { |
74 UNIMPLEMENTED(); | 74 UNIMPLEMENTED(); |
75 } | 75 } |
76 } | 76 } |
77 // status == ERR_BAD_STATE when we try to read and there are no messages | 77 // status == ERR_BAD_STATE when we try to read and there are no messages |
78 // available, so it is an error if we get here and status != ERR_BAD_STATE. | 78 // available, so it is an error if we get here and status != ERR_BAD_STATE. |
79 if (status != ERR_BAD_STATE) { | 79 if (status != ERR_BAD_STATE) { |
80 FATAL1("mx_message_read failed: %s\n", mx_strstatus(status)); | 80 FATAL1("mx_msgpipe_read failed: %s\n", mx_strstatus(status)); |
81 } | 81 } |
82 } | 82 } |
83 | 83 |
84 | 84 |
85 void EventHandlerImplementation::HandleEvents() { | 85 void EventHandlerImplementation::HandleEvents() { |
86 // TODO(zra): Handle events from other handles. At the moment we are only | 86 // TODO(zra): Handle events from other handles. At the moment we are only |
87 // interrupted when there is a message on interrupt_handles_[0]. | 87 // interrupted when there is a message on interrupt_handles_[0]. |
88 HandleInterruptFd(); | 88 HandleInterruptFd(); |
89 } | 89 } |
90 | 90 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 int64_t data) { | 163 int64_t data) { |
164 WakeupHandler(id, dart_port, data); | 164 WakeupHandler(id, dart_port, data); |
165 } | 165 } |
166 | 166 |
167 } // namespace bin | 167 } // namespace bin |
168 } // namespace dart | 168 } // namespace dart |
169 | 169 |
170 #endif // defined(TARGET_OS_FUCHSIA) | 170 #endif // defined(TARGET_OS_FUCHSIA) |
171 | 171 |
172 #endif // !defined(DART_IO_DISABLED) | 172 #endif // !defined(DART_IO_DISABLED) |
OLD | NEW |