islet-project / islet

An on-device confidential computing platform
Apache License 2.0
93 stars 17 forks source link

stat: Fix to use atomic operations #314

Closed bitboom closed 5 months ago

bitboom commented 5 months ago

This PR aims to eliminate unsafe code associated with Mutable Static Variables (MSVs).

The strategy for accessing MSVs is outlined below.

  1. Immutable Variables: Directly declare static variables for immutable data, requiring no synchronization.
  2. Primitive Types: Use core::sync::atomic for primitive types, enabling atomic operations that ensure thread safety.
  3. Dynamic Initialized Types: Implement lazy_static for types requiring runtime initialization, ensuring thread-safe setup.
  4. Synchronization Mechanisms: Choose between SpinLock and Mutex based on your system requirements
bitboom commented 5 months ago

Replaced with https://github.com/islet-project/islet/pull/314