Index: runtime/bin/eventhandler.h |
diff --git a/runtime/bin/eventhandler.h b/runtime/bin/eventhandler.h |
index ab5b590b65112c7cb28643df413ff7be28d3aae1..02cf0792e9b7f2b25a1688ff62fa0a39d063a41e 100644 |
--- a/runtime/bin/eventhandler.h |
+++ b/runtime/bin/eventhandler.h |
@@ -132,6 +132,8 @@ class CircularLinkedList { |
public: |
CircularLinkedList() : head_(NULL) {} |
+ typedef void (*ClearFun) (void* value); |
+ |
// Returns true if the list was empty. |
bool Add(T t) { |
Entry* e = new Entry(t); |
@@ -195,8 +197,12 @@ class CircularLinkedList { |
} |
} |
- void RemoveAll() { |
+ void RemoveAll(ClearFun clear = NULL) { |
while (HasHead()) { |
+ if (clear != NULL) { |
+ T h = head(); |
+ clear(reinterpret_cast<void*>(h)); |
+ } |
RemoveHead(); |
siva
2016/08/09 21:41:43
Wouldn't it be more atomic to pass the clear funct
zra
2016/08/09 22:19:27
Done. The DescriptorInfos and therefore the Circul
|
} |
} |
@@ -413,7 +419,9 @@ class DescriptorInfoMultipleMixin : public DI { |
: DI(fd), tokens_map_(&SamePortValue, kTokenCount), |
disable_tokens_(disable_tokens) {} |
- virtual ~DescriptorInfoMultipleMixin() {} |
+ virtual ~DescriptorInfoMultipleMixin() { |
+ RemoveAllPorts(); |
+ } |
virtual bool IsListeningSocket() const { return true; } |
@@ -497,14 +505,16 @@ class DescriptorInfoMultipleMixin : public DI { |
} |
virtual void RemoveAllPorts() { |
- active_readers_.RemoveAll(); |
for (HashMap::Entry *entry = tokens_map_.Start(); |
entry != NULL; |
entry = tokens_map_.Next(entry)) { |
PortEntry* pentry = reinterpret_cast<PortEntry*>(entry->value); |
+ entry->value = NULL; |
+ active_readers_.Remove(pentry); |
delete pentry; |
} |
tokens_map_.Clear(); |
+ active_readers_.RemoveAll(DeletePortEntry); |
} |
virtual Dart_Port NextNotifyDartPort(intptr_t events_ready) { |
@@ -585,6 +595,11 @@ class DescriptorInfoMultipleMixin : public DI { |
} |
private: |
+ static void DeletePortEntry(void* data) { |
+ PortEntry* entry = reinterpret_cast<PortEntry*>(data); |
+ delete entry; |
+ } |
+ |
// The [Dart_Port]s which are not paused (i.e. are interested in read events, |
// i.e. `mask == (1 << kInEvent)`) and we have enough tokens to communicate |
// with them. |