Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
cut the backtrace displayed from sthread to the sthread_create to hide useless cruft
[simgrid.git] / src / xbt / xbt_misc.cpp
1 /* Various pieces of code which don't fit in any module                     */
2
3 /* Copyright (c) 2006-2023. The SimGrid Team. All rights reserved.          */
4
5 /* This program is free software; you can redistribute it and/or modify it
6  * under the terms of the license (GNU LGPL) which comes with this package. */
7
8 #define XBT_LOG_LOCALLY_DEFINE_XBT_CHANNEL /* MSVC don't want it to be declared extern in headers and local here */
9
10 #include "src/internal_config.h"
11 #include "src/sthread/sthread.h" // sthread_inside_simgrid
12 #include "src/xbt/coverage.h"
13 #include "xbt/log.h"
14 #include "xbt/misc.h"
15 #include "xbt/sysdep.h"
16
17 #include <cmath>
18 #if HAVE_UNISTD_H
19 #include <unistd.h>
20 #endif
21
22 XBT_LOG_NEW_CATEGORY(smpi, "All SMPI categories"); /* lives here even if that's a bit odd to solve linking issues: this
23                                                       is used in xbt_log_file_appender to detect whether SMPI is used
24                                                       (and thus whether we should unbench the writing to disk) */
25
26 const int xbt_pagesize = static_cast<int>(sysconf(_SC_PAGESIZE));
27 const int xbt_pagebits = static_cast<int>(log2(xbt_pagesize));
28
29 XBT_ATTRIB_NOINLINE void sthread_enable()
30 { // These symbols are used from ContextSwapped in any case, but they are only useful
31   asm("");
32 }
33 XBT_ATTRIB_NOINLINE void sthread_disable()
34 { //  when libsthread is LD_PRELOADED. In this case, sthread's implem gets used instead.
35   asm("");
36 }
37
38 /* these two functions belong to xbt/sysdep.h, which have no corresponding .c file */
39 /** @brief like xbt_free, but you can be sure that it is a function  */
40 void xbt_free_f(void* p) noexcept(noexcept(::free))
41 {
42   xbt_free(p);
43 }
44
45 /** @brief should be given a pointer to pointer, and frees the second one */
46 void xbt_free_ref(void* d) noexcept(noexcept(::free))
47 {
48   xbt_free(*(void**)d);
49 }
50
51 /** @brief Kill the program in silence */
52 void xbt_abort()
53 {
54   /* Call __gcov_flush on abort when compiling with coverage options. */
55   coverage_checkpoint();
56   abort();
57 }
58
59 #ifndef HAVE_SMPI
60 int SMPI_is_inited()
61 {
62   return false;
63 }
64 #endif