Skip to content

Commit cff27fe

Browse files
author
Gabriel Schulhof
committed
n-api: mark thread-safe function as stable
Fixes: #24249 PR-URL: #25556 Backport-PR-URL: #25633 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
1 parent 7840f71 commit cff27fe

File tree

6 files changed

+30
-26
lines changed

6 files changed

+30
-26
lines changed

doc/api/n-api.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -223,15 +223,15 @@ This is an opaque pointer that is used to represent a JavaScript value.
223223

224224
### napi_threadsafe_function
225225

226-
> Stability: 1 - Experimental
226+
> Stability: 2 - Stable
227227

228228
This is an opaque pointer that represents a JavaScript function which can be
229229
called asynchronously from multiple threads via
230230
`napi_call_threadsafe_function()`.
231231

232232
### napi_threadsafe_function_release_mode
233233

234-
> Stability: 1 - Experimental
234+
> Stability: 2 - Stable
235235

236236
A value to be given to `napi_release_threadsafe_function()` to indicate whether
237237
the thread-safe function is to be closed immediately (`napi_tsfn_abort`) or
@@ -246,7 +246,7 @@ typedef enum {
246246

247247
### napi_threadsafe_function_call_mode
248248

249-
> Stability: 1 - Experimental
249+
> Stability: 2 - Stable
250250

251251
A value to be given to `napi_call_threadsafe_function()` to indicate whether
252252
the call should block whenever the queue associated with the thread-safe
@@ -341,7 +341,7 @@ typedef void (*napi_async_complete_callback)(napi_env env,
341341

342342
#### napi_threadsafe_function_call_js
343343

344-
> Stability: 1 - Experimental
344+
> Stability: 2 - Stable
345345

346346
Function pointer used with asynchronous thread-safe function calls. The callback
347347
will be called on the main thread. Its purpose is to use a data item arriving
@@ -4455,7 +4455,7 @@ prevent the event loop from exiting. The APIs `napi_ref_threadsafe_function` and
44554455

44564456
### napi_create_threadsafe_function
44574457

4458-
> Stability: 1 - Experimental
4458+
> Stability: 2 - Stable
44594459

44604460
<!-- YAML
44614461
added: v10.6.0
@@ -4498,7 +4498,7 @@ parameters and with `undefined` as its `this` value.
44984498

44994499
### napi_get_threadsafe_function_context
45004500

4501-
> Stability: 1 - Experimental
4501+
> Stability: 2 - Stable
45024502

45034503
<!-- YAML
45044504
added: v10.6.0
@@ -4516,7 +4516,7 @@ This API may be called from any thread which makes use of `func`.
45164516

45174517
### napi_call_threadsafe_function
45184518

4519-
> Stability: 1 - Experimental
4519+
> Stability: 2 - Stable
45204520

45214521
<!-- YAML
45224522
added: v10.6.0
@@ -4544,7 +4544,7 @@ This API may be called from any thread which makes use of `func`.
45444544

45454545
### napi_acquire_threadsafe_function
45464546

4547-
> Stability: 1 - Experimental
4547+
> Stability: 2 - Stable
45484548

45494549
<!-- YAML
45504550
added: v10.6.0
@@ -4566,7 +4566,7 @@ This API may be called from any thread which will start making use of `func`.
45664566

45674567
### napi_release_threadsafe_function
45684568

4569-
> Stability: 1 - Experimental
4569+
> Stability: 2 - Stable
45704570

45714571
<!-- YAML
45724572
added: v10.6.0
@@ -4594,7 +4594,7 @@ This API may be called from any thread which will stop making use of `func`.
45944594

45954595
### napi_ref_threadsafe_function
45964596

4597-
> Stability: 1 - Experimental
4597+
> Stability: 2 - Stable
45984598

45994599
<!-- YAML
46004600
added: v10.6.0
@@ -4615,7 +4615,7 @@ This API may only be called from the main thread.
46154615

46164616
### napi_unref_threadsafe_function
46174617

4618-
> Stability: 1 - Experimental
4618+
> Stability: 2 - Stable
46194619

46204620
<!-- YAML
46214621
added: v10.6.0

src/node_api.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,21 @@
33

44
#include <stddef.h>
55
#include <stdbool.h>
6-
#include "node_api_types.h"
7-
8-
struct uv_loop_s; // Forward declaration.
96

107
#ifndef NAPI_VERSION
118
#ifdef NAPI_EXPERIMENTAL
129
// Use INT_MAX, this should only be consumed by the pre-processor anyway.
1310
#define NAPI_VERSION 2147483647
1411
#else
1512
// The baseline version for N-API
16-
#define NAPI_VERSION 3
13+
#define NAPI_VERSION 4
1714
#endif
1815
#endif
1916

17+
#include "node_api_types.h"
18+
19+
struct uv_loop_s; // Forward declaration.
20+
2021
#ifdef _WIN32
2122
#ifdef BUILDING_NODE_EXTENSION
2223
#ifdef EXTERNAL_NAPI
@@ -633,7 +634,7 @@ NAPI_EXTERN napi_status napi_remove_env_cleanup_hook(napi_env env,
633634

634635
#endif // NAPI_VERSION >= 3
635636

636-
#ifdef NAPI_EXPERIMENTAL
637+
#if NAPI_VERSION >= 4
637638

638639
// Calling into JS from other threads
639640
NAPI_EXTERN napi_status
@@ -671,6 +672,10 @@ napi_unref_threadsafe_function(napi_env env, napi_threadsafe_function func);
671672
NAPI_EXTERN napi_status
672673
napi_ref_threadsafe_function(napi_env env, napi_threadsafe_function func);
673674

675+
#endif // NAPI_VERSION >= 4
676+
677+
#ifdef NAPI_EXPERIMENTAL
678+
674679
NAPI_EXTERN napi_status napi_create_bigint_int64(napi_env env,
675680
int64_t value,
676681
napi_value* result);

src/node_api_types.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ typedef struct napi_callback_info__* napi_callback_info;
2020
typedef struct napi_async_context__* napi_async_context;
2121
typedef struct napi_async_work__* napi_async_work;
2222
typedef struct napi_deferred__* napi_deferred;
23-
#ifdef NAPI_EXPERIMENTAL
23+
#if NAPI_VERSION >= 4
2424
typedef struct napi_threadsafe_function__* napi_threadsafe_function;
25-
#endif // NAPI_EXPERIMENTAL
25+
#endif // NAPI_VERSION >= 4
2626

2727
typedef enum {
2828
napi_default = 0,
@@ -84,7 +84,7 @@ typedef enum {
8484
napi_bigint_expected,
8585
} napi_status;
8686

87-
#ifdef NAPI_EXPERIMENTAL
87+
#if NAPI_VERSION >= 4
8888
typedef enum {
8989
napi_tsfn_release,
9090
napi_tsfn_abort
@@ -94,7 +94,7 @@ typedef enum {
9494
napi_tsfn_nonblocking,
9595
napi_tsfn_blocking
9696
} napi_threadsafe_function_call_mode;
97-
#endif // NAPI_EXPERIMENTAL
97+
#endif // NAPI_VERSION >= 4
9898

9999
typedef napi_value (*napi_callback)(napi_env env,
100100
napi_callback_info info);
@@ -107,12 +107,12 @@ typedef void (*napi_async_complete_callback)(napi_env env,
107107
napi_status status,
108108
void* data);
109109

110-
#ifdef NAPI_EXPERIMENTAL
110+
#if NAPI_VERSION >= 4
111111
typedef void (*napi_threadsafe_function_call_js)(napi_env env,
112112
napi_value js_callback,
113113
void* context,
114114
void* data);
115-
#endif // NAPI_EXPERIMENTAL
115+
#endif // NAPI_VERSION >= 4
116116

117117
typedef struct {
118118
// One of utf8name or name should be NULL.

src/node_version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,6 @@
114114
#define NODE_MODULE_VERSION 64
115115

116116
// the NAPI_VERSION provided by this version of the runtime
117-
#define NAPI_VERSION 3
117+
#define NAPI_VERSION 4
118118

119119
#endif // SRC_NODE_VERSION_H_

test/addons-napi/test_general/test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ assert.notStrictEqual(test_general.testGetPrototype(baseObject),
3333
test_general.testGetPrototype(extendedObject));
3434

3535
// test version management functions
36-
// expected version is currently 3
37-
assert.strictEqual(test_general.testGetVersion(), 3);
36+
// expected version is currently 4
37+
assert.strictEqual(test_general.testGetVersion(), 4);
3838

3939
const [ major, minor, patch, release ] = test_general.testGetNodeVersion();
4040
assert.strictEqual(process.version.split('-')[0],

test/addons-napi/test_threadsafe_function/binding.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
// which, in turn, may affect the ABI stability of the project despite its use
55
// of N-API.
66
#include <uv.h>
7-
#define NAPI_EXPERIMENTAL
87
#include <node_api.h>
98
#include "../common.h"
109

0 commit comments

Comments
 (0)