@auto_js/utility 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/memory/memory.cc +21 -0
  2. package/package.json +1 -1
package/memory/memory.cc CHANGED
@@ -2,6 +2,7 @@ export module util:memory;
2
2
  export import :memory.autorelease_pool;
3
3
  export import :memory.comparator;
4
4
  export import :memory.noinit_allocator;
5
+ import :platform.lockable;
5
6
  import std;
6
7
 
7
8
  namespace util {
@@ -57,4 +58,24 @@ auto safe_pointer_upcast(std::unique_ptr<Type, Deleter> unique) {
57
58
  return std::unique_ptr<To, cast_deleter>{std::move(unique)};
58
59
  }
59
60
 
61
+ // `std::atomic<std::shared_ptr<T>>` replacement when not available (macOS)
62
+ #if __cpp_lib_atomic_shared_ptr
63
+
64
+ export template <class Type>
65
+ using atomic_shared_ptr = std::atomic<std::shared_ptr<Type>>;
66
+
67
+ #else
68
+
69
+ export template <class Type>
70
+ class atomic_shared_ptr {
71
+ public:
72
+ auto load(auto /*order*/) const -> std::shared_ptr<Type> { return pointer_.read(); }
73
+ auto store(auto value, auto /*order*/) -> void { *pointer_.write() = std::move(value); }
74
+
75
+ private:
76
+ util::lockable<std::shared_ptr<Type>> pointer_;
77
+ };
78
+
79
+ #endif
80
+
60
81
  } // namespace util
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@auto_js/utility",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "author": "https://github.com/laverdet/",
5
5
  "homepage": "https://github.com/laverdet/isolated-vm/tree/experimental/packages/utility",
6
6
  "license": "ISC",