Skip to content

Commit 48a5241

Browse files
Gabriel SchulhofBethGriggs
Gabriel Schulhof
authored andcommitted
n-api: mark thread-safe function as stable
Fixes: #24249 PR-URL: #25556 Backport-PR-URL: #25633 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
1 parent f612a71 commit 48a5241

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
@@ -4458,7 +4458,7 @@ prevent the event loop from exiting. The APIs `napi_ref_threadsafe_function` and
44584458

44594459
### napi_create_threadsafe_function
44604460

4461-
> Stability: 1 - Experimental
4461+
> Stability: 2 - Stable
44624462

44634463
<!-- YAML
44644464
added: v10.6.0
@@ -4501,7 +4501,7 @@ parameters and with `undefined` as its `this` value.
45014501

45024502
### napi_get_threadsafe_function_context
45034503

4504-
> Stability: 1 - Experimental
4504+
> Stability: 2 - Stable
45054505

45064506
<!-- YAML
45074507
added: v10.6.0
@@ -4519,7 +4519,7 @@ This API may be called from any thread which makes use of `func`.
45194519

45204520
### napi_call_threadsafe_function
45214521

4522-
> Stability: 1 - Experimental
4522+
> Stability: 2 - Stable
45234523

45244524
<!-- YAML
45254525
added: v10.6.0
@@ -4547,7 +4547,7 @@ This API may be called from any thread which makes use of `func`.
45474547

45484548
### napi_acquire_threadsafe_function
45494549

4550-
> Stability: 1 - Experimental
4550+
> Stability: 2 - Stable
45514551

45524552
<!-- YAML
45534553
added: v10.6.0
@@ -4569,7 +4569,7 @@ This API may be called from any thread which will start making use of `func`.
45694569

45704570
### napi_release_threadsafe_function
45714571

4572-
> Stability: 1 - Experimental
4572+
> Stability: 2 - Stable
45734573

45744574
<!-- YAML
45754575
added: v10.6.0
@@ -4597,7 +4597,7 @@ This API may be called from any thread which will stop making use of `func`.
45974597

45984598
### napi_ref_threadsafe_function
45994599

4600-
> Stability: 1 - Experimental
4600+
> Stability: 2 - Stable
46014601

46024602
<!-- YAML
46034603
added: v10.6.0
@@ -4618,7 +4618,7 @@ This API may only be called from the main thread.
46184618

46194619
### napi_unref_threadsafe_function
46204620

4621-
> Stability: 1 - Experimental
4621+
> Stability: 2 - Stable
46224622

46234623
<!-- YAML
46244624
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)