Debian Codegraph @

modules/mono/mono_gc_handle.h

raw symbols SCIP
1 /**************************************************************************/
2 /* mono_gc_handle.h */
3 /**************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /**************************************************************************/
8 /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10 /* */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the */
13 /* "Software"), to deal in the Software without restriction, including */
14 /* without limitation the rights to use, copy, modify, merge, publish, */
15 /* distribute, sublicense, and/or sell copies of the Software, and to */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions: */
18 /* */
19 /* The above copyright notice and this permission notice shall be */
20 /* included in all copies or substantial portions of the Software. */
21 /* */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29 /**************************************************************************/
30
31 #pragma once
32
33 #include "core/object/ref_counted.h"
34
35 namespace gdmono {
36
37 enum class GCHandleType : char {
38 NIL,
39 STRONG_HANDLE,
40 WEAK_HANDLE
41 };
42 }
43
44 extern "C" {
45 struct GCHandleIntPtr {
46 void *value;
47
48 _FORCE_INLINE_ bool operator==(const GCHandleIntPtr &p_other) { return value == p_other.value; }
49 _FORCE_INLINE_ bool operator!=(const GCHandleIntPtr &p_other) { return value != p_other.value; }
50
51 GCHandleIntPtr() = delete;
52 };
53 }
54
55 static_assert(sizeof(GCHandleIntPtr) == sizeof(void *));
56
57 // Manual release of the GC handle must be done when using this struct
58 struct MonoGCHandleData {
59 GCHandleIntPtr handle = { nullptr };
60 gdmono::GCHandleType type = gdmono::GCHandleType::NIL;
61
62 _FORCE_INLINE_ bool is_released() const { return !handle.value; }
63 _FORCE_INLINE_ bool is_weak() const { return type == gdmono::GCHandleType::WEAK_HANDLE; }
64 _FORCE_INLINE_ GCHandleIntPtr get_intptr() const { return handle; }
65
66 void release();
67
68 static void free_gchandle(GCHandleIntPtr p_gchandle);
69
70 void operator=(const MonoGCHandleData &p_other) {
71 #ifdef DEBUG_ENABLED
72 CRASH_COND(!is_released());
73 #endif
74 handle = p_other.handle;
75 type = p_other.type;
76 }
77
78 MonoGCHandleData(const MonoGCHandleData &) = default;
79
80 MonoGCHandleData() {}
81
82 MonoGCHandleData(GCHandleIntPtr p_handle, gdmono::GCHandleType p_type) :
83 handle(p_handle),
84 type(p_type) {
85 }
86 };