[njs] Remove njs_timer.c forgotten in the previous commit.

Dmitry Volyntsev xeioex at nginx.com
Tue Nov 28 04:41:49 UTC 2023


details:   https://hg.nginx.org/njs/rev/d82a667c50af
branches:  
changeset: 2239:d82a667c50af
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Mon Nov 27 18:43:04 2023 -0800
description:
Remove njs_timer.c forgotten in the previous commit.

diffstat:

 src/njs_timer.c |  133 --------------------------------------------------------
 src/njs_timer.h |   19 --------
 2 files changed, 0 insertions(+), 152 deletions(-)

diffs (160 lines):

diff -r dffdf7c50dfc -r d82a667c50af src/njs_timer.c
--- a/src/njs_timer.c	Tue Nov 21 09:00:52 2023 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,133 +0,0 @@
-
-/*
- * Copyright (C) Dmitry Volyntsev
- * Copyright (C) NGINX, Inc.
- */
-
-
-#include <njs_main.h>
-
-
-static njs_int_t
-njs_set_timer(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
-    njs_index_t unused, njs_bool_t immediate, njs_value_t *retval)
-{
-    njs_uint_t     n;
-    uint64_t       delay;
-    njs_event_t   *event;
-    njs_vm_ops_t  *ops;
-
-    if (njs_slow_path(nargs < 2)) {
-        njs_type_error(vm, "too few arguments");
-        return NJS_ERROR;
-    }
-
-    if (njs_slow_path(!njs_is_function(&args[1]))) {
-        njs_type_error(vm, "first arg must be a function");
-        return NJS_ERROR;
-    }
-
-    ops = vm->options.ops;
-    if (njs_slow_path(ops == NULL)) {
-        njs_internal_error(vm, "not supported by host environment");
-        return NJS_ERROR;
-    }
-
-    delay = 0;
-
-    if (!immediate && nargs >= 3 && njs_is_number(&args[2])) {
-        delay = njs_number(&args[2]);
-    }
-
-    event = njs_mp_alloc(vm->mem_pool, sizeof(njs_event_t));
-    if (njs_slow_path(event == NULL)) {
-        goto memory_error;
-    }
-
-    n = immediate ? 2 : 3;
-
-    event->destructor = ops->clear_timer;
-    event->function = njs_function(&args[1]);
-    event->nargs = (nargs >= n) ? nargs - n : 0;
-    event->once = 1;
-    event->posted = 0;
-
-    if (event->nargs != 0) {
-        event->args = njs_mp_alloc(vm->mem_pool,
-                                   sizeof(njs_value_t) * event->nargs);
-        if (njs_slow_path(event->args == NULL)) {
-            goto memory_error;
-        }
-
-        memcpy(event->args, &args[n], sizeof(njs_value_t) * event->nargs);
-    }
-
-    event->host_event = ops->set_timer(vm->external, delay, event);
-    if (njs_slow_path(event->host_event == NULL)) {
-        njs_internal_error(vm, "set_timer() failed");
-        return NJS_ERROR;
-    }
-
-    if (njs_add_event(vm, event) == NJS_OK) {
-        njs_set_number(retval, vm->event_id - 1);
-    }
-
-    return NJS_OK;
-
-memory_error:
-
-    njs_memory_error(vm);
-
-    return NJS_ERROR;
-}
-
-
-njs_int_t
-njs_set_timeout(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
-    njs_index_t unused, njs_value_t *retval)
-{
-    return njs_set_timer(vm, args, nargs, unused, 0, retval);
-}
-
-
-njs_int_t
-njs_set_immediate(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
-    njs_index_t unused, njs_value_t *retval)
-{
-    return njs_set_timer(vm, args, nargs, unused, 1, retval);
-}
-
-
-njs_int_t
-njs_clear_timeout(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
-    njs_index_t unused, njs_value_t *retval)
-{
-    u_char              buf[16], *p;
-    njs_int_t           ret;
-    njs_event_t         *event;
-    njs_lvlhsh_query_t  lhq;
-
-    if (njs_fast_path(nargs < 2) || !njs_is_number(&args[1])) {
-        njs_set_undefined(retval);
-        return NJS_OK;
-    }
-
-    p = njs_sprintf(buf, buf + njs_length(buf), "%uD",
-                    (unsigned) njs_number(&args[1]));
-
-    lhq.key.start = buf;
-    lhq.key.length = p - buf;
-    lhq.key_hash = njs_djb_hash(lhq.key.start, lhq.key.length);
-    lhq.proto = &njs_event_hash_proto;
-    lhq.pool = vm->mem_pool;
-
-    ret = njs_lvlhsh_find(&vm->events_hash, &lhq);
-    if (ret == NJS_OK) {
-        event = lhq.value;
-        njs_del_event(vm, event, NJS_EVENT_RELEASE | NJS_EVENT_DELETE);
-    }
-
-    njs_set_undefined(retval);
-
-    return NJS_OK;
-}
diff -r dffdf7c50dfc -r d82a667c50af src/njs_timer.h
--- a/src/njs_timer.h	Tue Nov 21 09:00:52 2023 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,19 +0,0 @@
-
-/*
- * Copyright (C) Dmitry Volyntsev
- * Copyright (C) NGINX, Inc.
- */
-
-#ifndef _NJS_TIMER_H_INCLUDED_
-#define _NJS_TIMER_H_INCLUDED_
-
-
-njs_int_t njs_set_timeout(njs_vm_t *vm, njs_value_t *args,
-    njs_uint_t nargs, njs_index_t unused, njs_value_t *retval);
-njs_int_t njs_set_immediate(njs_vm_t *vm, njs_value_t *args,
-    njs_uint_t nargs, njs_index_t unused, njs_value_t *retval);
-njs_int_t njs_clear_timeout(njs_vm_t *vm, njs_value_t *args,
-    njs_uint_t nargs, njs_index_t unused, njs_value_t *retval);
-
-
-#endif /* _NJS_TIMER_H_INCLUDED_ */


More information about the nginx-devel mailing list