]> git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/opentelemetry-cpp/third_party/prometheus-cpp/3rdparty/civetweb/src/third_party/duktape-1.8.0/src-separate/duk_heap_misc.c
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / jaegertracing / opentelemetry-cpp / third_party / prometheus-cpp / 3rdparty / civetweb / src / third_party / duktape-1.8.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 /* 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
27 * object back.
28 */
29 }
30 #endif
31
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);
34
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);
39 }
40 DUK_HEAPHDR_SET_PREV(heap, hdr, NULL);
41 #endif
42 DUK_HEAPHDR_SET_NEXT(heap, hdr, heap->heap_allocated);
43 heap->heap_allocated = hdr;
44 }
45
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;
49
50 DUK_ASSERT(heap != NULL);
51
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.
57 */
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;
61 } else {
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.
64 */
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"));
68 }
69 #endif
70 new_thr->interrupt_counter = curr_thr->interrupt_counter;
71 new_thr->interrupt_init = curr_thr->interrupt_init;
72 }
73 } else {
74 DUK_DD(DUK_DDPRINT("switch thread, new thread is NULL, no interrupt counter changes"));
75 }
76
77 heap->curr_thread = new_thr; /* may be NULL */
78 }
79 #endif /* DUK_USE_INTERRUPT_COUNTER */