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

Unified Diff: dart/runtime/bin/eventhandler_linux.h

Issue 905733002: Extract common Mask/Dart_Port settings of linux event handler implementation to eventhandler.h (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed comments. Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « dart/runtime/bin/eventhandler_android.cc ('k') | dart/runtime/bin/eventhandler_linux.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dart/runtime/bin/eventhandler_linux.h
diff --git a/dart/runtime/bin/eventhandler_linux.h b/dart/runtime/bin/eventhandler_linux.h
index 0c5bd264f1a3d833d7570cbc695ae0c1a0c4ae46..3bf70fb5f2c1bb6acb58af09cefec04bdbd417a7 100644
--- a/dart/runtime/bin/eventhandler_linux.h
+++ b/dart/runtime/bin/eventhandler_linux.h
@@ -21,183 +21,36 @@
namespace dart {
namespace bin {
-class ListeningSocketData;
-class SocketData {
+class DescriptorInfo : public DescriptorInfoBase {
public:
- explicit SocketData(intptr_t fd)
- : fd_(fd), port_(0), mask_(0), tokens_(16) {
- ASSERT(fd_ != -1);
- }
+ explicit DescriptorInfo(intptr_t fd) : DescriptorInfoBase(fd) { }
- virtual ~SocketData() {
- }
+ virtual ~DescriptorInfo() { }
intptr_t GetPollEvents();
- void Close() {
- port_ = 0;
- mask_ = 0;
+ virtual void Close() {
VOID_TEMP_FAILURE_RETRY(close(fd_));
fd_ = -1;
}
-
- void SetMask(intptr_t mask) {
- ASSERT(fd_ != -1);
- mask_ = mask;
- }
-
- intptr_t fd() { return fd_; }
- virtual Dart_Port port() { return port_; }
-
- virtual bool IsListeningSocket() const { return false; }
-
- virtual bool AddPort(Dart_Port port) {
- ASSERT(port_ == 0);
- port_ = port;
- return true;
- }
-
- virtual bool RemovePort(Dart_Port port) {
- ASSERT(port_ == 0 || port_ == port);
- return true;
- }
-
- // Returns true if the last token was taken.
- virtual bool TakeToken() {
- ASSERT(tokens_ > 0);
- tokens_--;
- return tokens_ == 0;
- }
-
- // Returns true if the tokens was 0 before adding.
- virtual bool ReturnToken(Dart_Port port, int count) {
- ASSERT(port_ == port);
- ASSERT(tokens_ >= 0);
- bool was_empty = tokens_ == 0;
- tokens_ += count;
- return was_empty;
- }
-
- bool HasTokens() const { return tokens_ > 0; }
-
- protected:
- intptr_t fd_;
- Dart_Port port_;
- intptr_t mask_;
- int tokens_;
};
-class ListeningSocketData : public SocketData {
- private:
- static const int kTokenCount = 4;
-
- static bool SamePortValue(void* key1, void* key2) {
- return reinterpret_cast<Dart_Port>(key1) ==
- reinterpret_cast<Dart_Port>(key2);
- }
-
- static uint32_t GetHashmapHashFromPort(Dart_Port port) {
- return static_cast<uint32_t>(port & 0xFFFFFFFF);
- }
-
- static void* GetHashmapKeyFromPort(Dart_Port port) {
- return reinterpret_cast<void*>(port);
- }
-
+class DescriptorInfoSingle
+ : public DescriptorInfoSingleMixin<DescriptorInfo> {
public:
- explicit ListeningSocketData(intptr_t fd)
- : SocketData(fd),
- tokens_map_(&SamePortValue, 4) {}
-
- bool IsListeningSocket() const { return true; }
-
- bool AddPort(Dart_Port port) {
- HashMap::Entry* entry = tokens_map_.Lookup(
- GetHashmapKeyFromPort(port), GetHashmapHashFromPort(port), true);
- entry->value = reinterpret_cast<void*>(kTokenCount);
- return live_ports_.Add(port);
- }
+ explicit DescriptorInfoSingle(intptr_t fd)
+ : DescriptorInfoSingleMixin(fd) {}
+ virtual ~DescriptorInfoSingle() {}
+};
- virtual bool RemovePort(Dart_Port port) {
- HashMap::Entry* entry = tokens_map_.Lookup(
- GetHashmapKeyFromPort(port), GetHashmapHashFromPort(port), false);
- if (entry != NULL) {
- intptr_t tokens = reinterpret_cast<intptr_t>(entry->value);
- if (tokens == 0) {
- while (idle_ports_.head() != port) {
- idle_ports_.Rotate();
- }
- idle_ports_.RemoveHead();
- } else {
- while (live_ports_.head() != port) {
- live_ports_.Rotate();
- }
- live_ports_.RemoveHead();
- }
- tokens_map_.Remove(
- GetHashmapKeyFromPort(port), GetHashmapHashFromPort(port));
- } else {
- // NOTE: This is a listening socket which has been immediately closed.
- //
- // If a listening socket is not listened on, the event handler does not
- // know about it beforehand. So the first time the event handler knows
- // about it, is when it is supposed to be closed. We therefore do nothing
- // here.
- //
- // But whether to close it, depends on whether other isolates have it open
- // as well or not.
- }
- return !live_ports_.HasHead();
- }
- bool TakeToken() {
- ASSERT(live_ports_.HasHead());
- Dart_Port port = live_ports_.head();
- HashMap::Entry* entry = tokens_map_.Lookup(
- GetHashmapKeyFromPort(port), GetHashmapHashFromPort(port), false);
- ASSERT(entry != NULL);
- intptr_t tokens = reinterpret_cast<intptr_t>(entry->value);
- tokens--;
- entry->value = reinterpret_cast<void*>(tokens);
- if (tokens == 0) {
- live_ports_.RemoveHead();
- idle_ports_.Add(port);
- if (!live_ports_.HasHead()) {
- return true;
- }
- } else {
- live_ports_.Rotate();
- }
- return false;
- }
-
- Dart_Port port() { return live_ports_.head(); }
-
- bool ReturnToken(Dart_Port port, int count) {
- HashMap::Entry* entry = tokens_map_.Lookup(
- GetHashmapKeyFromPort(port), GetHashmapHashFromPort(port), false);
- ASSERT(entry != NULL);
- intptr_t tokens = reinterpret_cast<intptr_t>(entry->value);
- tokens += count;
- entry->value = reinterpret_cast<void*>(tokens);
- if (tokens == count) {
- // Return to live_ports_.
- while (idle_ports_.head() != port) {
- idle_ports_.Rotate();
- }
- idle_ports_.RemoveHead();
- bool was_empty = !live_ports_.HasHead();
- live_ports_.Add(port);
- return was_empty;
- }
- return false;
- }
-
- private:
- CircularLinkedList<Dart_Port> live_ports_;
- CircularLinkedList<Dart_Port> idle_ports_;
- HashMap tokens_map_;
+class DescriptorInfoMultiple
+ : public DescriptorInfoMultipleMixin<DescriptorInfo> {
+ public:
+ explicit DescriptorInfoMultiple(intptr_t fd)
+ : DescriptorInfoMultipleMixin(fd) {}
+ virtual ~DescriptorInfoMultiple() {}
};
@@ -206,9 +59,11 @@ class EventHandlerImplementation {
EventHandlerImplementation();
~EventHandlerImplementation();
+ void UpdateEpollInstance(intptr_t old_mask, DescriptorInfo *di);
+
// Gets the socket data structure for a given file
// descriptor. Creates a new one if one is not found.
- SocketData* GetSocketData(intptr_t fd, bool is_listening);
+ DescriptorInfo* GetDescriptorInfo(intptr_t fd, bool is_listening);
void SendData(intptr_t id, Dart_Port dart_port, int64_t data);
void Start(EventHandler* handler);
void Shutdown();
@@ -219,7 +74,7 @@ class EventHandlerImplementation {
void WakeupHandler(intptr_t id, Dart_Port dart_port, int64_t data);
void HandleInterruptFd();
void SetPort(intptr_t fd, Dart_Port dart_port, intptr_t mask);
- intptr_t GetPollEvents(intptr_t events, SocketData* sd);
+ intptr_t GetPollEvents(intptr_t events, DescriptorInfo* di);
static void* GetHashmapKeyFromFd(intptr_t fd);
static uint32_t GetHashmapHashFromFd(intptr_t fd);
« no previous file with comments | « dart/runtime/bin/eventhandler_android.cc ('k') | dart/runtime/bin/eventhandler_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698