mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
[quickjs] reference count in heartbeat.c
This commit is contained in:
parent
6629f34466
commit
d5787d46b4
@ -81,16 +81,23 @@ add_heartbeat(struct ecmascript_interpreter *interpreter)
|
|||||||
|
|
||||||
assert(interpreter);
|
assert(interpreter);
|
||||||
|
|
||||||
|
if (interpreter->heartbeat) {
|
||||||
|
interpreter->heartbeat->ref_count++;
|
||||||
|
return interpreter->heartbeat;
|
||||||
|
}
|
||||||
|
|
||||||
if (!interpreter->vs || !interpreter->vs->doc_view)
|
if (!interpreter->vs || !interpreter->vs->doc_view)
|
||||||
ses = NULL;
|
ses = NULL;
|
||||||
else
|
else
|
||||||
ses = interpreter->vs->doc_view->session;
|
ses = interpreter->vs->doc_view->session;
|
||||||
|
|
||||||
hb = (struct heartbeat *)mem_alloc(sizeof(struct heartbeat));
|
hb = (struct heartbeat *)mem_alloc(sizeof(struct heartbeat));
|
||||||
|
|
||||||
if (!hb) return NULL;
|
if (!hb) return NULL;
|
||||||
|
|
||||||
hb->ttl = get_opt_int("ecmascript.max_exec_time", ses);
|
hb->ttl = get_opt_int("ecmascript.max_exec_time", ses);
|
||||||
hb->interpreter = interpreter;
|
hb->interpreter = interpreter;
|
||||||
|
hb->ref_count = 1;
|
||||||
add_to_list(heartbeats, hb);
|
add_to_list(heartbeats, hb);
|
||||||
|
|
||||||
#ifndef CONFIG_OS_DOS
|
#ifndef CONFIG_OS_DOS
|
||||||
@ -115,6 +122,10 @@ done_heartbeat(struct heartbeat *hb)
|
|||||||
if (!hb) return; /* add_heartbeat returned NULL */
|
if (!hb) return; /* add_heartbeat returned NULL */
|
||||||
assert(hb->interpreter);
|
assert(hb->interpreter);
|
||||||
|
|
||||||
|
if (--hb->ref_count > 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef CONFIG_OS_DOS
|
#ifndef CONFIG_OS_DOS
|
||||||
/* Stop the heartbeat timer if this heartbeat is the only one. */
|
/* Stop the heartbeat timer if this heartbeat is the only one. */
|
||||||
if (list_is_singleton(*hb)) {
|
if (list_is_singleton(*hb)) {
|
||||||
|
@ -15,6 +15,7 @@ struct heartbeat {
|
|||||||
* second. When it reaches 0, script execution is
|
* second. When it reaches 0, script execution is
|
||||||
* terminated. */
|
* terminated. */
|
||||||
|
|
||||||
|
int ref_count;
|
||||||
struct ecmascript_interpreter *interpreter;
|
struct ecmascript_interpreter *interpreter;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user