Kotlinify SingleThreadAsserter (#43768)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/43768

Changelog: [Internal]

As part of the Sustainability Week (see [post](https://fb.workplace.com/groups/251759413609061/permalink/742797531171911/)).

Reviewed By: cortinico

Differential Revision: D55636773

fbshipit-source-id: 2f3d1c73a5d3c7d229b854ab73dcf2902a639c3a
This commit is contained in:
Fabrizio Cucci
2024-04-02 16:17:39 -07:00
committed by Facebook GitHub Bot
parent fa808b0840
commit 7d60f403f9
3 changed files with 25 additions and 28 deletions
@@ -1746,9 +1746,9 @@ public abstract interface class com/facebook/react/common/ShakeDetector$ShakeLis
public abstract fun onShake ()V
}
public class com/facebook/react/common/SingleThreadAsserter {
public final class com/facebook/react/common/SingleThreadAsserter {
public fun <init> ()V
public fun assertNow ()V
public final fun assertNow ()V
}
public final class com/facebook/react/common/StandardCharsets {
@@ -1,26 +0,0 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.react.common;
import androidx.annotation.Nullable;
import com.facebook.infer.annotation.Assertions;
import com.facebook.infer.annotation.Nullsafe;
/** Simple class for asserting that operations only run on a single thread. */
@Nullsafe(Nullsafe.Mode.LOCAL)
public class SingleThreadAsserter {
private @Nullable Thread mThread = null;
public void assertNow() {
Thread current = Thread.currentThread();
if (mThread == null) {
mThread = current;
}
Assertions.assertCondition(mThread == current);
}
}
@@ -0,0 +1,23 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.react.common
import com.facebook.infer.annotation.Assertions
/** Simple class for asserting that operations only run on a single thread. */
public class SingleThreadAsserter {
private var thread: Thread? = null
public fun assertNow() {
val currentThread = Thread.currentThread()
if (thread == null) {
thread = currentThread
}
Assertions.assertCondition(thread == currentThread)
}
}