[njs] njs_vm_pending() is split in njs_vm_posted() and njs_vm_waiting().
Dmitry Volyntsev
xeioex at nginx.com
Fri Dec 28 09:46:26 UTC 2018
details: https://hg.nginx.org/njs/rev/bdd4c516a078
branches:
changeset: 702:bdd4c516a078
user: Dmitry Volyntsev <xeioex at nginx.com>
date: Fri Dec 28 12:43:22 2018 +0300
description:
njs_vm_pending() is split in njs_vm_posted() and njs_vm_waiting().
There are two types of events in njs:
Posted - are ready to be executed by njs_vm_run().
Waiting - await external async events.
diffstat:
njs/njs.c | 15 +++++++++++----
njs/njs.h | 14 +++++++++++++-
njs/njs_event.h | 4 +++-
3 files changed, 27 insertions(+), 6 deletions(-)
diffs (82 lines):
diff -r fa1c446b6823 -r bdd4c516a078 njs/njs.c
--- a/njs/njs.c Fri Dec 28 12:42:29 2018 +0300
+++ b/njs/njs.c Fri Dec 28 12:43:22 2018 +0300
@@ -196,7 +196,7 @@ njs_vm_destroy(njs_vm_t *vm)
njs_event_t *event;
nxt_lvlhsh_each_t lhe;
- if (njs_is_pending_events(vm)) {
+ if (njs_waiting_events(vm)) {
nxt_lvlhsh_each_init(&lhe, &njs_event_hash_proto);
for ( ;; ) {
@@ -558,9 +558,16 @@ njs_vm_del_event(njs_vm_t *vm, njs_vm_ev
nxt_int_t
-njs_vm_pending(njs_vm_t *vm)
+njs_vm_waiting(njs_vm_t *vm)
{
- return njs_is_pending_events(vm);
+ return njs_waiting_events(vm);
+}
+
+
+nxt_int_t
+njs_vm_posted(njs_vm_t *vm)
+{
+ return njs_posted_events(vm);
}
@@ -652,7 +659,7 @@ njs_vm_handle_events(njs_vm_t *vm)
}
}
- return njs_is_pending_events(vm) ? NJS_AGAIN : NJS_OK;
+ return njs_posted_events(vm) ? NJS_AGAIN : NJS_OK;
}
diff -r fa1c446b6823 -r bdd4c516a078 njs/njs.h
--- a/njs/njs.h Fri Dec 28 12:42:29 2018 +0300
+++ b/njs/njs.h Fri Dec 28 12:43:22 2018 +0300
@@ -167,11 +167,23 @@ NXT_EXPORT njs_vm_event_t njs_vm_add_eve
njs_function_t *function, nxt_uint_t once, njs_host_event_t host_ev,
njs_event_destructor destructor);
NXT_EXPORT void njs_vm_del_event(njs_vm_t *vm, njs_vm_event_t vm_event);
-NXT_EXPORT nxt_int_t njs_vm_pending(njs_vm_t *vm);
NXT_EXPORT nxt_int_t njs_vm_post_event(njs_vm_t *vm, njs_vm_event_t vm_event,
const njs_value_t *args, nxt_uint_t nargs);
/*
+ * Returns 1 if async events are present.
+ */
+NXT_EXPORT nxt_int_t njs_vm_waiting(njs_vm_t *vm);
+
+/*
+ * Returns 1 if posted events are ready to be executed.
+ */
+NXT_EXPORT nxt_int_t njs_vm_posted(njs_vm_t *vm);
+
+#define njs_vm_pending(vm) (njs_vm_waiting(vm) || njs_vm_posted(vm))
+
+
+/*
* Runs the specified function with provided arguments.
* NJS_OK successful run.
* NJS_ERROR some exception or internal error happens.
diff -r fa1c446b6823 -r bdd4c516a078 njs/njs_event.h
--- a/njs/njs_event.h Fri Dec 28 12:42:29 2018 +0300
+++ b/njs/njs_event.h Fri Dec 28 12:43:22 2018 +0300
@@ -12,7 +12,9 @@
#define NJS_EVENT_DELETE 2
-#define njs_is_pending_events(vm) (!nxt_lvlhsh_is_empty(&(vm)->events_hash))
+#define njs_waiting_events(vm) (!nxt_lvlhsh_is_empty(&(vm)->events_hash))
+
+#define njs_posted_events(vm) (!nxt_queue_is_empty(&(vm)->posted_events))
typedef struct {
More information about the nginx-devel
mailing list