401 {
403 GetHashmapKeyFromPort(
port), GetHashmapHashFromPort(
port),
true);
404 PortEntry* pentry;
405 if (entry->value == nullptr) {
406 pentry = new PortEntry();
407 pentry->dart_port =
port;
408 pentry->token_count = kTokenCount;
409 pentry->is_reading = IsReadingMask(mask);
410 entry->value = reinterpret_cast<void*>(pentry);
411
412 if (pentry->IsReady()) {
413 active_readers_.
Add(pentry);
414 }
415 } else {
416 pentry = reinterpret_cast<PortEntry*>(entry->value);
417 bool was_ready = pentry->IsReady();
418 pentry->is_reading = IsReadingMask(mask);
419 bool is_ready = pentry->IsReady();
420
421 if (was_ready && !is_ready) {
422 active_readers_.
Remove(pentry);
423 } else if (!was_ready && is_ready) {
424 active_readers_.
Add(pentry);
425 }
426 }
427
428#ifdef DEBUG
429
430 int ready_count = 0;
431
432 if (active_readers_.
HasHead()) {
433 PortEntry*
root =
reinterpret_cast<PortEntry*
>(active_readers_.
head());
434 PortEntry* current =
root;
435 do {
436 ASSERT(current->IsReady());
437 ready_count++;
439 current = active_readers_.
head();
440 }
while (current !=
root);
441 }
442
444 entry = tokens_map_.
Next(entry)) {
445 PortEntry* pentry = reinterpret_cast<PortEntry*>(entry->value);
446 if (pentry->IsReady()) {
447 ready_count--;
448 }
449 }
450
452#endif
453 }