@gjsify/sab-native 0.4.42 → 0.4.44
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.
- package/README.md +48 -0
- package/package.json +3 -3
package/README.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# @gjsify/sab-native
|
|
2
|
+
|
|
3
|
+
Optional native Vala bridge providing cross-process shared memory and atomics for `@gjsify/worker_threads` on GJS. Implements `SharedBuffer` via Linux `memfd_create` + `mmap(MAP_SHARED)` with typed accessors and SEQ_CST atomics backed by `__atomic_*` GCC builtins and `SYS_futex` for wait/notify. Also exposes `FdChannel` for passing file descriptors between processes via SCM_RIGHTS over a Unix-domain socket.
|
|
4
|
+
|
|
5
|
+
Part of the [gjsify](https://github.com/gjsify/gjsify) project — Node.js and Web APIs for GJS (GNOME JavaScript).
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
This package is loaded automatically by `@gjsify/worker_threads` when the prebuild is present. Install it explicitly to enable `SharedBuffer` cross-process transfers:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
gjsify install @gjsify/sab-native
|
|
13
|
+
|
|
14
|
+
# npm or yarn also work:
|
|
15
|
+
npm install @gjsify/sab-native
|
|
16
|
+
yarn add @gjsify/sab-native
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
// Loaded automatically by @gjsify/worker_threads.
|
|
23
|
+
// Direct use requires checking availability first:
|
|
24
|
+
import { hasNativeSab, SharedBuffer, atomics } from '@gjsify/sab-native';
|
|
25
|
+
|
|
26
|
+
if (hasNativeSab()) {
|
|
27
|
+
// Allocate 4 KB of shared memory
|
|
28
|
+
const buf = SharedBuffer.create(4096);
|
|
29
|
+
console.log('fd:', buf.fd, 'size:', buf.byteLength);
|
|
30
|
+
|
|
31
|
+
// Typed read/write
|
|
32
|
+
buf.setInt32LE(0, 42);
|
|
33
|
+
console.log(buf.getInt32LE(0)); // 42
|
|
34
|
+
|
|
35
|
+
// Atomic operations (SEQ_CST)
|
|
36
|
+
atomics.store32(buf, 0, 1);
|
|
37
|
+
const prev = atomics.add32(buf, 0, 10);
|
|
38
|
+
console.log('prev:', prev, 'now:', atomics.load32(buf, 0));
|
|
39
|
+
|
|
40
|
+
buf.close();
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Ships as a prebuilt `.so` + `.typelib` for `linux-{x86_64,aarch64,ppc64,s390x,riscv64}`.
|
|
45
|
+
|
|
46
|
+
## License
|
|
47
|
+
|
|
48
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/sab-native",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.44",
|
|
4
4
|
"description": "Optional Vala/GObject bridge providing cross-process shared memory + atomics for @gjsify/worker_threads. Wraps Linux memfd_create(2) + mmap(MAP_SHARED) to back JS-visible SharedBuffer regions whose fds can be passed to child workers via SCM_RIGHTS over a Unix-domain socket; exposes typed accessors (getInt32LE / setUint8 / etc.) plus atomics built on __atomic_* GCC builtins and SYS_futex for wait/notify. Workaround for the stock-GJS gap where SharedArrayBuffer is unavailable (Mozilla disables the SAB constructor without COOP/COEP opts) and SAB cannot share backing stores across Gio.Subprocess workers anyway.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/esm/index.js",
|
|
@@ -62,8 +62,8 @@
|
|
|
62
62
|
"@girs/gio-2.0": "2.88.0-4.0.4"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
|
-
"@gjsify/cli": "^0.4.
|
|
66
|
-
"@gjsify/unit": "^0.4.
|
|
65
|
+
"@gjsify/cli": "^0.4.44",
|
|
66
|
+
"@gjsify/unit": "^0.4.44",
|
|
67
67
|
"@ts-for-gir/cli": "^4.0.4",
|
|
68
68
|
"@types/node": "^25.9.1",
|
|
69
69
|
"typescript": "^6.0.3"
|