| 525 | void delref() override { ThreadSafeReferenceCounted<ThreadSingleAssignmentVar<T>>::delref(); } |
| 526 | |
| 527 | void send(const T& value) { |
| 528 | if (TRACE_SAMPLE()) |
| 529 | TraceEvent(SevSample, "Promise_send").log(); |
| 530 | this->mutex.enter(); |
| 531 | if (!canBeSetUnsafe()) { |
| 532 | this->mutex.leave(); |
| 533 | ASSERT(false); // Promise fulfilled twice |
| 534 | } |
| 535 | this->value = value; //< Danger: polymorphic operation inside lock |
| 536 | this->status = Set; |
| 537 | if (!callback) { |
| 538 | this->mutex.leave(); |
| 539 | return; |
| 540 | } |
| 541 | |
| 542 | auto func = callback; |
| 543 | if (!callback->isMultiCallback()) |
| 544 | callback = nullptr; |
| 545 | |
| 546 | if (!func->canFire(0)) { |
| 547 | this->mutex.leave(); |
| 548 | } else { |
| 549 | this->mutex.leave(); |
| 550 | |
| 551 | // Thread safe because status is now Set and callback is nullptr, meaning than callback cannot change |
| 552 | int userParam = 0; |
| 553 | func->fire(Void(), userParam); |
| 554 | } |
| 555 | } |
| 556 | |
| 557 | void cleanupUnsafe() override { |
| 558 | value = T(); |
no test coverage detected