]> git.proxmox.com Git - ceph.git/blob - ceph/src/civetweb/src/third_party/duktape-1.3.0/src-separate/duk_heap_misc.c
bump version to 12.2.12-pve1
[ceph.git] / ceph / src / civetweb / src / third_party / duktape-1.3.0 / src-separate / duk_heap_misc.c
1 /*
2 * Support functions for duk_heap.
3 */
4
5 #include "duk_internal.h"
6
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.
10 */
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);
13
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));
16 } else {
17 heap->heap_allocated = DUK_HEAPHDR_GET_NEXT(heap, hdr);
18 }
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));
21 } else {
22 ;
23 }
24 }
25 #endif
26
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);
29
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);
34 }
35 DUK_HEAPHDR_SET_PREV(heap, hdr, NULL);
36 #endif
37 DUK_HEAPHDR_SET_NEXT(heap, hdr, heap->heap_allocated);
38 heap->heap_allocated = hdr;
39 }
40
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;
44
45 DUK_ASSERT(heap != NULL);
46
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.
52 */
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;
56 } else {
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.
59 */
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"));
63 }
64 #endif
65 new_thr->interrupt_counter = curr_thr->interrupt_counter;
66 new_thr->interrupt_init = curr_thr->interrupt_init;
67 }
68 } else {
69 DUK_DD(DUK_DDPRINT("switch thread, new thread is NULL, no interrupt counter changes"));
70 }
71
72 heap->curr_thread = new_thr; /* may be NULL */
73 }
74 #endif /* DUK_USE_INTERRUPT_COUNTER */