Skip to content

Commit

Permalink
let PointerValue::invalidate() be noexcept
Browse files Browse the repository at this point in the history
Summary:
X-link: facebook/react-native#47354

`PointerValue::invalidate()` is called from `Pointer` destructor, which is implicitly `noexcept`, and from `Pointer` move-assignment operator, which is now `noexcept`.

Reviewed By: neildhar

Differential Revision: D65271399

fbshipit-source-id: 26fd9707e4389da78537d0d607adaef0c68690ca
  • Loading branch information
yfeldblum authored and facebook-github-bot committed Nov 7, 2024
1 parent a0d150d commit 45cdffd
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions API/hermes/hermes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@ class HermesRuntimeImpl final : public HermesRuntime,
return value_;
}

void invalidate() override {
void invalidate() noexcept override {
#ifdef ASSERT_ON_DANGLING_VM_REFS
assert(
((1u << 31) & refCount_) == 0 &&
Expand All @@ -936,7 +936,7 @@ class HermesRuntimeImpl final : public HermesRuntime,
dec();
}

void inc() {
void inc() noexcept {
// It is always safe to use relaxed operations for incrementing the
// reference count, because the only operation that may occur concurrently
// with it is decrementing the reference count, and we do not need to
Expand All @@ -947,7 +947,7 @@ class HermesRuntimeImpl final : public HermesRuntime,
(void)oldCount;
}

void dec() {
void dec() noexcept {
// It is safe to use relaxed operations here because decrementing the
// reference count is the only access that may be performed without proper
// synchronisation. As a result, the only ordering we need to enforce when
Expand Down
6 changes: 3 additions & 3 deletions API/hermes_abi/HermesABIRuntimeWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,19 +189,19 @@ class HermesABIRuntimeWrapper : public Runtime {
return managedPointer_;
}

void invalidate() override {
void invalidate() noexcept override {
dec();
}

void inc() {
void inc() noexcept {
// See comments in hermes_abi.cpp for why we use relaxed operations here.
auto oldCount = refCount_.fetch_add(1, std::memory_order_relaxed);
assert(oldCount && "Cannot resurrect a pointer");
assert(oldCount + 1 != 0 && "Ref count overflow");
(void)oldCount;
}

void dec() {
void dec() noexcept {
// See comments in hermes_abi.cpp for why we use relaxed operations here.
auto oldCount = refCount_.fetch_sub(1, std::memory_order_relaxed);
assert(oldCount > 0 && "Ref count underflow");
Expand Down
6 changes: 3 additions & 3 deletions API/hermes_sandbox/HermesSandboxRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1048,11 +1048,11 @@ class HermesSandboxRuntimeImpl : public facebook::hermes::HermesSandboxRuntime,
return managedPointer_;
}

void invalidate() override {
void invalidate() noexcept override {
dec();
}

void inc() {
void inc() noexcept {
// See comments in hermes_vtable.cpp for why we use relaxed operations
// here.
auto oldCount = refCount_.fetch_add(1, std::memory_order_relaxed);
Expand All @@ -1061,7 +1061,7 @@ class HermesSandboxRuntimeImpl : public facebook::hermes::HermesSandboxRuntime,
(void)oldCount;
}

void dec() {
void dec() noexcept {
// See comments in hermes_vtable.cpp for why we use relaxed operations
// here, and why TSAN requires different ordering.

Expand Down
2 changes: 1 addition & 1 deletion API/jsi/jsi/jsi.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ class JSI_EXPORT Runtime {
// rvalue arguments/methods would also reduce the number of clones.

struct PointerValue {
virtual void invalidate() = 0;
virtual void invalidate() noexcept = 0;

protected:
virtual ~PointerValue() = default;
Expand Down

0 comments on commit 45cdffd

Please sign in to comment.