emnapi 1.2.0 → 1.3.1

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 (44) hide show
  1. package/CMakeLists.txt +13 -3
  2. package/README.md +7 -18
  3. package/common.gypi +1 -0
  4. package/dist/library_napi.js +130 -41
  5. package/emnapi.gyp +4 -0
  6. package/include/node/emnapi.h +2 -2
  7. package/include/node/js_native_api.h +30 -25
  8. package/include/node/js_native_api_types.h +13 -9
  9. package/include/node/node_api.h +25 -13
  10. package/include/node/uv/threadpool.h +1 -1
  11. package/include/node/uv/unix.h +4 -0
  12. package/include/node/uv.h +49 -6
  13. package/index.js +1 -0
  14. package/lib/wasm32/libemnapi.a +0 -0
  15. package/lib/wasm32-emscripten/libemnapi-mt.a +0 -0
  16. package/lib/wasm32-emscripten/libemnapi.a +0 -0
  17. package/lib/wasm32-wasi/libemnapi.a +0 -0
  18. package/lib/wasm32-wasi-threads/libemnapi-basic-mt.a +0 -0
  19. package/lib/wasm32-wasi-threads/libemnapi-basic.a +0 -0
  20. package/lib/wasm32-wasi-threads/libemnapi-mt.a +0 -0
  21. package/lib/wasm32-wasi-threads/libemnapi.a +0 -0
  22. package/lib/wasm32-wasip1/libemnapi.a +0 -0
  23. package/lib/wasm32-wasip1-threads/libemnapi-basic-mt.a +0 -0
  24. package/lib/wasm32-wasip1-threads/libemnapi-basic.a +0 -0
  25. package/lib/wasm32-wasip1-threads/libemnapi-mt.a +0 -0
  26. package/lib/wasm32-wasip1-threads/libemnapi.a +0 -0
  27. package/lib/wasm64-emscripten/libemnapi-mt.a +0 -0
  28. package/lib/wasm64-emscripten/libemnapi.a +0 -0
  29. package/package.json +1 -1
  30. package/src/async_cleanup_hook.c +1 -1
  31. package/src/async_work.c +2 -2
  32. package/src/emnapi_internal.h +2 -2
  33. package/src/js_native_api.c +2 -1
  34. package/src/node_api.c +5 -5
  35. package/src/threadsafe_function.c +20 -21
  36. package/src/uv/queue.h +68 -86
  37. package/src/uv/threadpool.c +58 -40
  38. package/src/uv/unix/async.c +67 -64
  39. package/src/uv/unix/core.c +36 -1
  40. package/src/uv/unix/internal.h +54 -0
  41. package/src/uv/unix/loop.c +40 -4
  42. package/src/uv/unix/posix-hrtime.c +40 -0
  43. package/src/uv/uv-common.c +123 -7
  44. package/src/uv/uv-common.h +137 -9
@@ -27,35 +27,140 @@
27
27
  #define container_of(ptr, type, member) \
28
28
  ((type *) ((char *) (ptr) - offsetof(type, member)))
29
29
 
30
- #define UV_REQ_INIT(req, typ) \
31
- do { \
32
- (req)->type = (typ); \
33
- } \
34
- while (0)
30
+ /* Handle flags. Some flags are specific to Windows or UNIX. */
31
+ enum {
32
+ /* Used by all handles. */
33
+ UV_HANDLE_CLOSING = 0x00000001,
34
+ UV_HANDLE_CLOSED = 0x00000002,
35
+ UV_HANDLE_ACTIVE = 0x00000004,
36
+ UV_HANDLE_REF = 0x00000008,
37
+ UV_HANDLE_INTERNAL = 0x00000010,
38
+ UV_HANDLE_ENDGAME_QUEUED = 0x00000020
39
+ };
35
40
 
36
41
  #define uv__has_active_reqs(loop) \
37
42
  ((loop)->active_reqs.count > 0)
38
43
 
39
- #define uv__req_register(loop, req) \
44
+ #define uv__req_register(loop) \
40
45
  do { \
41
46
  (loop)->active_reqs.count++; \
42
47
  } \
43
48
  while (0)
44
49
 
45
- #define uv__req_unregister(loop, req) \
50
+ #define uv__req_unregister(loop) \
46
51
  do { \
47
52
  assert(uv__has_active_reqs(loop)); \
48
53
  (loop)->active_reqs.count--; \
49
54
  } \
50
55
  while (0)
51
56
 
57
+ #define uv__has_active_handles(loop) \
58
+ ((loop)->active_handles > 0)
59
+
60
+ #define uv__active_handle_add(h) \
61
+ do { \
62
+ (h)->loop->active_handles++; \
63
+ } \
64
+ while (0)
65
+
66
+ #define uv__active_handle_rm(h) \
67
+ do { \
68
+ (h)->loop->active_handles--; \
69
+ } \
70
+ while (0)
71
+
72
+ #define uv__is_active(h) \
73
+ (((h)->flags & UV_HANDLE_ACTIVE) != 0)
74
+
75
+ #define uv__is_closing(h) \
76
+ (((h)->flags & (UV_HANDLE_CLOSING | UV_HANDLE_CLOSED)) != 0)
77
+ #define uv__handle_start(h) \
78
+ do { \
79
+ if (((h)->flags & UV_HANDLE_ACTIVE) != 0) break; \
80
+ (h)->flags |= UV_HANDLE_ACTIVE; \
81
+ if (((h)->flags & UV_HANDLE_REF) != 0) uv__active_handle_add(h); \
82
+ } \
83
+ while (0)
84
+
85
+ #define uv__handle_stop(h) \
86
+ do { \
87
+ if (((h)->flags & UV_HANDLE_ACTIVE) == 0) break; \
88
+ (h)->flags &= ~UV_HANDLE_ACTIVE; \
89
+ if (((h)->flags & UV_HANDLE_REF) != 0) uv__active_handle_rm(h); \
90
+ } \
91
+ while (0)
92
+
93
+ #define uv__handle_ref(h) \
94
+ do { \
95
+ if (((h)->flags & UV_HANDLE_REF) != 0) break; \
96
+ (h)->flags |= UV_HANDLE_REF; \
97
+ if (((h)->flags & UV_HANDLE_CLOSING) != 0) break; \
98
+ if (((h)->flags & UV_HANDLE_ACTIVE) != 0) uv__active_handle_add(h); \
99
+ } \
100
+ while (0)
101
+
102
+ #define uv__handle_unref(h) \
103
+ do { \
104
+ if (((h)->flags & UV_HANDLE_REF) == 0) break; \
105
+ (h)->flags &= ~UV_HANDLE_REF; \
106
+ if (((h)->flags & UV_HANDLE_CLOSING) != 0) break; \
107
+ if (((h)->flags & UV_HANDLE_ACTIVE) != 0) uv__active_handle_rm(h); \
108
+ } \
109
+ while (0)
110
+
111
+ #define uv__has_ref(h) \
112
+ (((h)->flags & UV_HANDLE_REF) != 0)
113
+
114
+ #if defined(_WIN32)
115
+ # define uv__handle_platform_init(h) ((h)->u.fd = -1)
116
+ #else
117
+ # define uv__handle_platform_init(h) ((h)->next_closing = NULL)
118
+ #endif
119
+
120
+ #define uv__handle_init(loop_, h, type_) \
121
+ do { \
122
+ (h)->loop = (loop_); \
123
+ (h)->type = (type_); \
124
+ (h)->flags = UV_HANDLE_REF; /* Ref the loop when active. */ \
125
+ uv__queue_insert_tail(&(loop_)->handle_queue, &(h)->handle_queue); \
126
+ uv__handle_platform_init(h); \
127
+ } \
128
+ while (0)
129
+
130
+ #define UV_REQ_INIT(req, typ) \
131
+ do { \
132
+ (req)->type = (typ); \
133
+ } \
134
+ while (0)
135
+
52
136
  #define uv__req_init(loop, req, typ) \
53
137
  do { \
54
138
  UV_REQ_INIT(req, typ); \
55
- uv__req_register(loop, req); \
139
+ uv__req_register(loop); \
56
140
  } \
57
141
  while (0)
58
142
 
143
+ #define uv__get_internal_fields(loop) \
144
+ ((uv__loop_internal_fields_t*) loop->internal_fields)
145
+
146
+ #define uv__get_loop_metrics(loop) \
147
+ (&uv__get_internal_fields(loop)->loop_metrics)
148
+
149
+ #define uv__metrics_inc_loop_count(loop) \
150
+ do { \
151
+ uv__get_loop_metrics(loop)->metrics.loop_count++; \
152
+ } while (0)
153
+
154
+ #define uv__metrics_inc_events(loop, e) \
155
+ do { \
156
+ uv__get_loop_metrics(loop)->metrics.events += (e); \
157
+ } while (0)
158
+
159
+ #define uv__metrics_inc_events_waiting(loop, e) \
160
+ do { \
161
+ uv__get_loop_metrics(loop)->metrics.events_waiting += (e); \
162
+ } while (0)
163
+
59
164
  #define uv__exchange_int_relaxed(p, v) \
60
165
  atomic_exchange_explicit((_Atomic int*)(p), v, memory_order_relaxed)
61
166
 
@@ -68,7 +173,30 @@ enum uv__work_kind {
68
173
  void uv__threadpool_cleanup(void);
69
174
  void uv__work_done(uv_async_t* handle);
70
175
  void uv__loop_close(uv_loop_t* loop);
71
- void uv__async_close(uv_async_t* handle);
176
+
177
+ void *uv__calloc(size_t count, size_t size);
178
+ char *uv__strdup(const char* s);
179
+ char *uv__strndup(const char* s, size_t n);
180
+ void* uv__malloc(size_t size);
181
+ void uv__free(void* ptr);
182
+ void* uv__realloc(void* ptr, size_t size);
183
+ void* uv__reallocf(void* ptr, size_t size);
184
+
185
+ typedef struct uv__loop_metrics_s uv__loop_metrics_t;
186
+ typedef struct uv__loop_internal_fields_s uv__loop_internal_fields_t;
187
+
188
+ struct uv__loop_metrics_s {
189
+ uv_metrics_t metrics;
190
+ uint64_t provider_entry_time;
191
+ uint64_t provider_idle_time;
192
+ uv_mutex_t lock;
193
+ };
194
+
195
+ struct uv__loop_internal_fields_s {
196
+ unsigned int flags;
197
+ uv__loop_metrics_t loop_metrics;
198
+ int current_timeout;
199
+ };
72
200
 
73
201
  #endif
74
202