| 1 | /* |
| 2 | * This Source Code Form is subject to the terms of the Mozilla Public |
| 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 5 | * |
| 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2019 MonetDB B.V. |
| 7 | */ |
| 8 | |
| 9 | #ifndef _GDK_UTILS_H_ |
| 10 | #define _GDK_UTILS_H_ |
| 11 | |
| 12 | #include <setjmp.h> |
| 13 | |
| 14 | gdk_export const char *GDKgetenv(const char *name); |
| 15 | |
| 16 | gdk_export bool GDKgetenv_istext(const char *name, const char* text); |
| 17 | gdk_export bool GDKgetenv_isyes(const char *name); |
| 18 | gdk_export bool GDKgetenv_istrue(const char *name); |
| 19 | |
| 20 | gdk_export int GDKgetenv_int(const char *name, int def); |
| 21 | |
| 22 | gdk_export gdk_return GDKsetenv(const char *name, const char *value); |
| 23 | gdk_export gdk_return GDKcopyenv(BAT **key, BAT **val, bool writable); |
| 24 | |
| 25 | /* |
| 26 | * @+ Memory management |
| 27 | * Memory management in GDK mostly relies on the facilities offered by |
| 28 | * the underlying OS. The below routines monitor the available memory |
| 29 | * resources which consist of physical swap space and logical vm |
| 30 | * space. There are three kinds of memory, that affect these two |
| 31 | * resources in different ways: |
| 32 | * |
| 33 | * - memory mapping |
| 34 | * which ask for a logical region of virtual memory space. In |
| 35 | * principle, no physical memory is needed to keep the system afloat |
| 36 | * here, as the memory mapped file is swapped onto a disk object |
| 37 | * that already exists. |
| 38 | * |
| 39 | * Actually, there are two kings of memory mapping used in GDK, |
| 40 | * namely read-only direct mapped and writable copy-on write. For |
| 41 | * the dirty pages, the latter actually also consumes physical |
| 42 | * memory resources, but that is ignored here for simplicity. |
| 43 | * |
| 44 | * - anonymous virtual memory |
| 45 | * This is virtual memory that is mapped on the swap file. Hence, |
| 46 | * this consumes both logical VM space resources and physical memory |
| 47 | * space. |
| 48 | * |
| 49 | * - malloced memory |
| 50 | * comes from the heap and directly consumes physical memory |
| 51 | * resources. |
| 52 | * |
| 53 | * The malloc routine checks the memory consumption every 1000 calls, |
| 54 | * or for calls larger that 50000 bytes. Consequently, at least every |
| 55 | * 50MB increase, alloc memory is checked. The VM calls always check |
| 56 | * the memory consumption. |
| 57 | */ |
| 58 | /* default setting to administer everything */ |
| 59 | #define GDK_MEM_NULLALLOWED |
| 60 | |
| 61 | #if SIZEOF_VOID_P==8 |
| 62 | #define GDK_VM_MAXSIZE LL_CONSTANT(4398046511104) /* :-) a 64-bit OS: 4TB */ |
| 63 | #else |
| 64 | #define GDK_VM_MAXSIZE LL_CONSTANT(1610612736) /* :-| a 32-bit OS: 1.5GB */ |
| 65 | #endif |
| 66 | /* virtual memory defines */ |
| 67 | gdk_export size_t _MT_npages; |
| 68 | gdk_export size_t _MT_pagesize; |
| 69 | |
| 70 | #define MT_pagesize() _MT_pagesize |
| 71 | #define MT_npages() _MT_npages |
| 72 | |
| 73 | gdk_export void MT_init(void); /* init the package. */ |
| 74 | struct opt; |
| 75 | gdk_export gdk_return GDKinit(struct opt *set, int setlen); |
| 76 | |
| 77 | /* used for testing only */ |
| 78 | gdk_export void GDKsetmallocsuccesscount(lng count); |
| 79 | |
| 80 | /* |
| 81 | * Upon closing the session, all persistent BATs should be saved and |
| 82 | * the transient BATs should be removed. The buffer pool manager |
| 83 | * takes care of this. |
| 84 | */ |
| 85 | #ifndef HAVE_EMBEDDED |
| 86 | gdk_export _Noreturn void GDKexit(int status); |
| 87 | #else |
| 88 | gdk_export void GDKexit(int status); |
| 89 | #endif |
| 90 | gdk_export bool GDKexiting(void); |
| 91 | |
| 92 | gdk_export void GDKprepareExit(void); |
| 93 | gdk_export void GDKreset(int status); |
| 94 | gdk_export const char *GDKversion(void); |
| 95 | |
| 96 | // these are used in embedded mode to jump out of GDKfatal |
| 97 | gdk_export jmp_buf GDKfataljump; |
| 98 | gdk_export str GDKfatalmsg; |
| 99 | gdk_export bit GDKfataljumpenable; |
| 100 | |
| 101 | /* Timers |
| 102 | * The following relative timers are available for inspection. |
| 103 | * Note that they may consume recognizable overhead. |
| 104 | * |
| 105 | */ |
| 106 | gdk_export lng GDKusec(void); |
| 107 | gdk_export int GDKms(void); |
| 108 | |
| 109 | |
| 110 | #endif /* _GDK_UTILS_H_ */ |
| 111 | |