Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
duktape-1.5.2/src-separate/duk_hthread_misc.c
Go to the documentation of this file.
1/*
2 * Thread support.
3 */
4
5#include "duk_internal.h"
6
8 DUK_ASSERT(thr != NULL);
9
10 /* Order of unwinding is important */
11
13
14 duk_hthread_callstack_unwind(thr, 0); /* side effects, possibly errors */
15
16 thr->valstack_bottom = thr->valstack;
17 duk_set_top((duk_context *) thr, 0); /* unwinds valstack, updating refcounts */
18
20
21 /* Here we could remove references to built-ins, but it may not be
22 * worth the effort because built-ins are quite likely to be shared
23 * with another (unterminated) thread, and terminated threads are also
24 * usually garbage collected quite quickly. Also, doing DECREFs
25 * could trigger finalization, which would run on the current thread
26 * and have access to only some of the built-ins. Garbage collection
27 * deals with this correctly already.
28 */
29
30 /* XXX: Shrink the stacks to minimize memory usage? May not
31 * be worth the effort because terminated threads are usually
32 * garbage collected quite soon.
33 */
34}
35
37 DUK_ASSERT(thr != NULL);
38
39 if (thr->callstack_top > 0) {
40 return thr->callstack + thr->callstack_top - 1;
41 } else {
42 return NULL;
43 }
44}
45
46#if defined(DUK_USE_DEBUGGER_SUPPORT)
47DUK_INTERNAL duk_uint_fast32_t duk_hthread_get_act_curr_pc(duk_hthread *thr, duk_activation *act) {
48 duk_instr_t *bcode;
49
50 DUK_ASSERT(thr != NULL);
51 DUK_ASSERT(act != NULL);
52 DUK_UNREF(thr);
53
54 /* XXX: store 'bcode' pointer to activation for faster lookup? */
55 if (act->func && DUK_HOBJECT_IS_COMPILEDFUNCTION(act->func)) {
57 return (duk_uint_fast32_t) (act->curr_pc - bcode);
58 }
59 return 0;
60}
61#endif /* DUK_USE_DEBUGGER_SUPPORT */
62
64 duk_instr_t *bcode;
66
67 DUK_ASSERT(thr != NULL);
68 DUK_ASSERT(act != NULL);
69 DUK_UNREF(thr);
70
71 if (act->func && DUK_HOBJECT_IS_COMPILEDFUNCTION(act->func)) {
73 ret = (duk_uint_fast32_t) (act->curr_pc - bcode);
74 if (ret > 0) {
75 ret--;
76 }
77 return ret;
78 }
79 return 0;
80}
81
82/* Write bytecode executor's curr_pc back to topmost activation (if any). */
84 duk_activation *act;
85
86 DUK_ASSERT(thr != NULL);
87
88 if (thr->ptr_curr_pc != NULL) {
89 /* ptr_curr_pc != NULL only when bytecode executor is active. */
90 DUK_ASSERT(thr->callstack_top > 0);
91 act = thr->callstack + thr->callstack_top - 1;
92 act->curr_pc = *thr->ptr_curr_pc;
93 }
94}
95
97 duk_activation *act;
98
99 DUK_ASSERT(thr != NULL);
100
101 if (thr->ptr_curr_pc != NULL) {
102 /* ptr_curr_pc != NULL only when bytecode executor is active. */
103 DUK_ASSERT(thr->callstack_top > 0);
104 act = thr->callstack + thr->callstack_top - 1;
105 act->curr_pc = *thr->ptr_curr_pc;
106 thr->ptr_curr_pc = NULL;
107 }
108}
duk_uint32_t duk_uint_fast32_t
#define DUK_HCOMPILEDFUNCTION_GET_CODE_BASE(heap, h)
DUK_INTERNAL_DECL void duk_hthread_catchstack_unwind(duk_hthread *thr, duk_size_t new_top)
#define DUK_HOBJECT_IS_COMPILEDFUNCTION(h)
DUK_INTERNAL_DECL void duk_hthread_callstack_unwind(duk_hthread *thr, duk_size_t new_top)
DUK_EXTERNAL void duk_set_top(duk_context *ctx, duk_idx_t index)
duk_uint32_t duk_instr_t
#define DUK_HTHREAD_STATE_TERMINATED
DUK_INTERNAL void duk_hthread_terminate(duk_hthread *thr)
DUK_INTERNAL void duk_hthread_sync_and_null_currpc(duk_hthread *thr)
DUK_INTERNAL void duk_hthread_sync_currpc(duk_hthread *thr)
DUK_INTERNAL duk_uint_fast32_t duk_hthread_get_act_prev_pc(duk_hthread *thr, duk_activation *act)
DUK_INTERNAL duk_activation * duk_hthread_get_current_activation(duk_hthread *thr)
#define NULL
Definition gmacros.h:924