]>
git.proxmox.com Git - ceph.git/blob - ceph/src/civetweb/src/third_party/duktape-1.5.2/src-separate/duk_heap_misc.c
2 * Support functions for duk_heap.
5 #include "duk_internal.h"
7 #if defined(DUK_USE_DOUBLE_LINKED_HEAP) && defined(DUK_USE_REFERENCE_COUNTING)
8 /* arbitrary remove only works with double linked heap, and is only required by
9 * reference counting so far.
11 DUK_INTERNAL
void duk_heap_remove_any_from_heap_allocated(duk_heap
*heap
, duk_heaphdr
*hdr
) {
12 DUK_ASSERT(DUK_HEAPHDR_GET_TYPE(hdr
) != DUK_HTYPE_STRING
);
14 if (DUK_HEAPHDR_GET_PREV(heap
, hdr
)) {
15 DUK_HEAPHDR_SET_NEXT(heap
, DUK_HEAPHDR_GET_PREV(heap
, hdr
), DUK_HEAPHDR_GET_NEXT(heap
, hdr
));
17 heap
->heap_allocated
= DUK_HEAPHDR_GET_NEXT(heap
, hdr
);
19 if (DUK_HEAPHDR_GET_NEXT(heap
, hdr
)) {
20 DUK_HEAPHDR_SET_PREV(heap
, DUK_HEAPHDR_GET_NEXT(heap
, hdr
), DUK_HEAPHDR_GET_PREV(heap
, hdr
));
25 /* The prev/next pointers of the removed duk_heaphdr are left as garbage.
26 * It's up to the caller to ensure they're written before inserting the
32 DUK_INTERNAL
void duk_heap_insert_into_heap_allocated(duk_heap
*heap
, duk_heaphdr
*hdr
) {
33 DUK_ASSERT(DUK_HEAPHDR_GET_TYPE(hdr
) != DUK_HTYPE_STRING
);
35 #ifdef DUK_USE_DOUBLE_LINKED_HEAP
36 if (heap
->heap_allocated
) {
37 DUK_ASSERT(DUK_HEAPHDR_GET_PREV(heap
, heap
->heap_allocated
) == NULL
);
38 DUK_HEAPHDR_SET_PREV(heap
, heap
->heap_allocated
, hdr
);
40 DUK_HEAPHDR_SET_PREV(heap
, hdr
, NULL
);
42 DUK_HEAPHDR_SET_NEXT(heap
, hdr
, heap
->heap_allocated
);
43 heap
->heap_allocated
= hdr
;
46 #ifdef DUK_USE_INTERRUPT_COUNTER
47 DUK_INTERNAL
void duk_heap_switch_thread(duk_heap
*heap
, duk_hthread
*new_thr
) {
48 duk_hthread
*curr_thr
;
50 DUK_ASSERT(heap
!= NULL
);
52 if (new_thr
!= NULL
) {
53 curr_thr
= heap
->curr_thread
;
54 if (curr_thr
== NULL
) {
55 /* For initial entry use default value; zero forces an
56 * interrupt before executing the first insturction.
58 DUK_DD(DUK_DDPRINT("switch thread, initial entry, init default interrupt counter"));
59 new_thr
->interrupt_counter
= 0;
60 new_thr
->interrupt_init
= 0;
62 /* Copy interrupt counter/init value state to new thread (if any).
63 * It's OK for new_thr to be the same as curr_thr.
65 #if defined(DUK_USE_DEBUG)
66 if (new_thr
!= curr_thr
) {
67 DUK_DD(DUK_DDPRINT("switch thread, not initial entry, copy interrupt counter"));
70 new_thr
->interrupt_counter
= curr_thr
->interrupt_counter
;
71 new_thr
->interrupt_init
= curr_thr
->interrupt_init
;
74 DUK_DD(DUK_DDPRINT("switch thread, new thread is NULL, no interrupt counter changes"));
77 heap
->curr_thread
= new_thr
; /* may be NULL */
79 #endif /* DUK_USE_INTERRUPT_COUNTER */