]>
git.proxmox.com Git - ceph.git/blob - ceph/src/civetweb/src/third_party/duktape-1.3.0/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
));
27 DUK_INTERNAL
void duk_heap_insert_into_heap_allocated(duk_heap
*heap
, duk_heaphdr
*hdr
) {
28 DUK_ASSERT(DUK_HEAPHDR_GET_TYPE(hdr
) != DUK_HTYPE_STRING
);
30 #ifdef DUK_USE_DOUBLE_LINKED_HEAP
31 if (heap
->heap_allocated
) {
32 DUK_ASSERT(DUK_HEAPHDR_GET_PREV(heap
, heap
->heap_allocated
) == NULL
);
33 DUK_HEAPHDR_SET_PREV(heap
, heap
->heap_allocated
, hdr
);
35 DUK_HEAPHDR_SET_PREV(heap
, hdr
, NULL
);
37 DUK_HEAPHDR_SET_NEXT(heap
, hdr
, heap
->heap_allocated
);
38 heap
->heap_allocated
= hdr
;
41 #ifdef DUK_USE_INTERRUPT_COUNTER
42 DUK_INTERNAL
void duk_heap_switch_thread(duk_heap
*heap
, duk_hthread
*new_thr
) {
43 duk_hthread
*curr_thr
;
45 DUK_ASSERT(heap
!= NULL
);
47 if (new_thr
!= NULL
) {
48 curr_thr
= heap
->curr_thread
;
49 if (curr_thr
== NULL
) {
50 /* For initial entry use default value; zero forces an
51 * interrupt before executing the first insturction.
53 DUK_DD(DUK_DDPRINT("switch thread, initial entry, init default interrupt counter"));
54 new_thr
->interrupt_counter
= 0;
55 new_thr
->interrupt_init
= 0;
57 /* Copy interrupt counter/init value state to new thread (if any).
58 * It's OK for new_thr to be the same as curr_thr.
60 #if defined(DUK_USE_DEBUG)
61 if (new_thr
!= curr_thr
) {
62 DUK_DD(DUK_DDPRINT("switch thread, not initial entry, copy interrupt counter"));
65 new_thr
->interrupt_counter
= curr_thr
->interrupt_counter
;
66 new_thr
->interrupt_init
= curr_thr
->interrupt_init
;
69 DUK_DD(DUK_DDPRINT("switch thread, new thread is NULL, no interrupt counter changes"));
72 heap
->curr_thread
= new_thr
; /* may be NULL */
74 #endif /* DUK_USE_INTERRUPT_COUNTER */