A little paranoia as I stare at this code and some analyzer nonsense.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4807 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
parent
21e6cf10b6
commit
2c79e03094
20
src/task.c
20
src/task.c
@ -1857,7 +1857,10 @@ void tf_task_destroy(tf_task_t* task)
|
||||
while (task->timeouts)
|
||||
{
|
||||
timeout_t* timeout = task->timeouts;
|
||||
JS_FreeValue(task->_context, timeout->_callback);
|
||||
if (task->_context)
|
||||
{
|
||||
JS_FreeValue(task->_context, timeout->_callback);
|
||||
}
|
||||
timeout->_callback = JS_UNDEFINED;
|
||||
_timeout_unlink(task, timeout);
|
||||
uv_close((uv_handle_t*)&timeout->_timer, _timeout_closed);
|
||||
@ -2051,6 +2054,7 @@ const char* tf_task_get_name(tf_task_t* task)
|
||||
|
||||
static void _timeout_link(tf_task_t* task, timeout_t* timeout)
|
||||
{
|
||||
assert(timeout);
|
||||
assert(!timeout->previous);
|
||||
assert(!timeout->next);
|
||||
timeout->previous = timeout;
|
||||
@ -2067,6 +2071,7 @@ static void _timeout_link(tf_task_t* task, timeout_t* timeout)
|
||||
|
||||
static void _timeout_unlink(tf_task_t* task, timeout_t* timeout)
|
||||
{
|
||||
assert(timeout);
|
||||
assert(timeout->previous);
|
||||
assert(timeout->next);
|
||||
if (timeout->next == timeout && timeout->previous == timeout && task->timeouts == timeout)
|
||||
@ -2082,18 +2087,21 @@ static void _timeout_unlink(tf_task_t* task, timeout_t* timeout)
|
||||
task->timeouts = timeout->next;
|
||||
}
|
||||
}
|
||||
timeout->previous = NULL;
|
||||
timeout->next = NULL;
|
||||
}
|
||||
|
||||
static void _timeout_closed(uv_handle_t* handle)
|
||||
{
|
||||
timeout_t* timeout = handle->data;
|
||||
handle->data = NULL;
|
||||
tf_free(timeout);
|
||||
}
|
||||
|
||||
static void _util_timeoutCallback(uv_timer_t* handle)
|
||||
static void _tf_task_timeout_callback(uv_timer_t* handle)
|
||||
{
|
||||
timeout_t* timeout = handle->data;
|
||||
tf_trace_begin(tf_task_get_trace(timeout->_task), "_util_timeoutCallback");
|
||||
tf_trace_begin(tf_task_get_trace(timeout->_task), "_tf_task_timeout_callback");
|
||||
JSContext* context = tf_task_get_context(timeout->_task);
|
||||
JSValue result = JS_Call(
|
||||
context,
|
||||
@ -2124,9 +2132,9 @@ static JSValue _tf_task_setTimeout(JSContext* context, JSValueConst this_val, in
|
||||
|
||||
uv_timer_init(tf_task_get_loop(task), &timeout->_timer);
|
||||
|
||||
int64_t duration;
|
||||
JS_ToInt64(context, &duration, argv[1]);
|
||||
if (uv_timer_start(&timeout->_timer, _util_timeoutCallback, duration, 0) != 0)
|
||||
int64_t duration_ms = 0;
|
||||
JS_ToInt64(context, &duration_ms, argv[1]);
|
||||
if (uv_timer_start(&timeout->_timer, _tf_task_timeout_callback, duration_ms, 0) != 0)
|
||||
{
|
||||
JS_FreeValue(context, timeout->_callback);
|
||||
_timeout_unlink(task, timeout);
|
||||
|
Loading…
Reference in New Issue
Block a user