Skip to content

Commit d6ffabc

Browse files
Gabriel SchulhofBethGriggs
Gabriel Schulhof
authored andcommitted
n-api: mark thread-safe function as stable
Fixes: #24249 PR-URL: #25556 Backport-PR-URL: #25648 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
1 parent 44609d1 commit d6ffabc

File tree

6 files changed

+29
-29
lines changed

6 files changed

+29
-29
lines changed

doc/api/n-api.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,15 @@ This is an opaque pointer that is used to represent a JavaScript value.
171171

172172
### napi_threadsafe_function
173173

174-
> Stability: 1 - Experimental
174+
> Stability: 2 - Stable
175175

176176
This is an opaque pointer that represents a JavaScript function which can be
177177
called asynchronously from multiple threads via
178178
`napi_call_threadsafe_function()`.
179179

180180
### napi_threadsafe_function_release_mode
181181

182-
> Stability: 1 - Experimental
182+
> Stability: 2 - Stable
183183

184184
A value to be given to `napi_release_threadsafe_function()` to indicate whether
185185
the thread-safe function is to be closed immediately (`napi_tsfn_abort`) or
@@ -194,7 +194,7 @@ typedef enum {
194194

195195
### napi_threadsafe_function_call_mode
196196

197-
> Stability: 1 - Experimental
197+
> Stability: 2 - Stable
198198

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

286286
#### napi_threadsafe_function_call_js
287287

288-
> Stability: 1 - Experimental
288+
> Stability: 2 - Stable
289289

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

41854185
### napi_create_threadsafe_function
41864186

4187-
> Stability: 1 - Experimental
4187+
> Stability: 2 - Stable
41884188

41894189
<!-- YAML
41904190
added: REPLACEME
@@ -4227,7 +4227,7 @@ parameters and with `undefined` as its `this` value.
42274227

42284228
### napi_get_threadsafe_function_context
42294229

4230-
> Stability: 1 - Experimental
4230+
> Stability: 2 - Stable
42314231

42324232
<!-- YAML
42334233
added: REPLACEME
@@ -4245,7 +4245,7 @@ This API may be called from any thread which makes use of `func`.
42454245

42464246
### napi_call_threadsafe_function
42474247

4248-
> Stability: 1 - Experimental
4248+
> Stability: 2 - Stable
42494249

42504250
<!-- YAML
42514251
added: REPLACEME
@@ -4273,7 +4273,7 @@ This API may be called from any thread which makes use of `func`.
42734273

42744274
### napi_acquire_threadsafe_function
42754275

4276-
> Stability: 1 - Experimental
4276+
> Stability: 2 - Stable
42774277

42784278
<!-- YAML
42794279
added: REPLACEME
@@ -4295,7 +4295,7 @@ This API may be called from any thread which will start making use of `func`.
42954295

42964296
### napi_release_threadsafe_function
42974297

4298-
> Stability: 1 - Experimental
4298+
> Stability: 2 - Stable
42994299

43004300
<!-- YAML
43014301
added: REPLACEME
@@ -4323,7 +4323,7 @@ This API may be called from any thread which will stop making use of `func`.
43234323

43244324
### napi_ref_threadsafe_function
43254325

4326-
> Stability: 1 - Experimental
4326+
> Stability: 2 - Stable
43274327

43284328
<!-- YAML
43294329
added: REPLACEME
@@ -4344,7 +4344,7 @@ This API may only be called from the main thread.
43444344

43454345
### napi_unref_threadsafe_function
43464346

4347-
> Stability: 1 - Experimental
4347+
> Stability: 2 - Stable
43484348

43494349
<!-- YAML
43504350
added: REPLACEME

src/node_api.h

+7-6
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
@@ -614,7 +615,7 @@ NAPI_EXTERN napi_status napi_remove_env_cleanup_hook(napi_env env,
614615

615616
#endif // NAPI_VERSION >= 3
616617

617-
#ifdef NAPI_EXPERIMENTAL
618+
#if NAPI_VERSION >= 4
618619

619620
// Calling into JS from other threads
620621
NAPI_EXTERN napi_status
@@ -652,7 +653,7 @@ napi_unref_threadsafe_function(napi_env env, napi_threadsafe_function func);
652653
NAPI_EXTERN napi_status
653654
napi_ref_threadsafe_function(napi_env env, napi_threadsafe_function func);
654655

655-
#endif // NAPI_EXPERIMENTAL
656+
#endif // NAPI_VERSION >= 4
656657

657658
EXTERN_C_END
658659

src/node_api_types.h

+8-8
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,
@@ -76,13 +76,13 @@ typedef enum {
7676
napi_escape_called_twice,
7777
napi_handle_scope_mismatch,
7878
napi_callback_scope_mismatch,
79-
#ifdef NAPI_EXPERIMENTAL
79+
#if NAPI_VERSION >= 4
8080
napi_queue_full,
8181
napi_closing,
82-
#endif // NAPI_EXPERIMENTAL
82+
#endif // NAPI_VERSION >= 4
8383
} napi_status;
8484

85-
#ifdef NAPI_EXPERIMENTAL
85+
#if NAPI_VERSION >= 4
8686
typedef enum {
8787
napi_tsfn_release,
8888
napi_tsfn_abort
@@ -92,7 +92,7 @@ typedef enum {
9292
napi_tsfn_nonblocking,
9393
napi_tsfn_blocking
9494
} napi_threadsafe_function_call_mode;
95-
#endif // NAPI_EXPERIMENTAL
95+
#endif // NAPI_VERSION >= 4
9696

9797
typedef napi_value (*napi_callback)(napi_env env,
9898
napi_callback_info info);
@@ -105,12 +105,12 @@ typedef void (*napi_async_complete_callback)(napi_env env,
105105
napi_status status,
106106
void* data);
107107

108-
#ifdef NAPI_EXPERIMENTAL
108+
#if NAPI_VERSION >= 4
109109
typedef void (*napi_threadsafe_function_call_js)(napi_env env,
110110
napi_value js_callback,
111111
void* context,
112112
void* data);
113-
#endif // NAPI_EXPERIMENTAL
113+
#endif // NAPI_VERSION >= 4
114114

115115
typedef struct {
116116
// One of utf8name or name should be NULL.

src/node_version.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,6 @@
108108
#define NODE_MODULE_VERSION 57
109109

110110
// the NAPI_VERSION provided by this version of the runtime
111-
#define NAPI_VERSION 3
111+
#define NAPI_VERSION 4
112112

113113
#endif // SRC_NODE_VERSION_H_

test/addons-napi/test_general/test.js

+2-2
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

-1
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)