vrpRouting  0.3
interruption.h
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 
3 Copyright (c) 2015 pgRouting developers
5 
6 Copyright (c) 2020 Mohamed Bakli, Esteban Zimányi, Mahmoud Sakr
8 
9 ------
10 
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
15 
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20 
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 
25  ********************************************************************PGR-GNU*/
26 
27 #ifndef INCLUDE_CPP_COMMON_INTERRUPTION_H_
28 #define INCLUDE_CPP_COMMON_INTERRUPTION_H_
29 
30 #ifdef _MSC_VER
31 #define __PGR_PRETTY_FUNCTION__ __FUNCSIG__
32 #else
33 #define __PGR_PRETTY_FUNCTION__ __PRETTY_FUNCTION__
34 #endif
35 
36 extern "C" {
37 
38 #ifdef _MSC_VER
39 
40 #include <miscadmin.h>
41 #include <postgres.h>
42 
43 #else
44 /*
45  * Instead of including all the files
46  * copy/paste what is used
47  * IMPORTANT: this copy/paste might depend on the postgreSQL version
48  */
49 #include <signal.h>
50 
51 /*
52  * https://doxygen.postgresql.org/c_8h.html#a166c1d950e659804f0e3247aad99a81f
53  */
54 #define PGDLLIMPORT
55 
56 /*
57  * https://doxygen.postgresql.org/miscadmin_8h_source.html
58  */
59 extern PGDLLIMPORT volatile sig_atomic_t InterruptPending;
60 extern void ProcessInterrupts(void);
61 
62 #if __GNUC__ >= 3
63 #define unlikely(x) __builtin_expect((x) != 0, 0)
64 #else
65 #define unlikely(x) ((x) != 0)
66 #endif
67 
68 /* Test whether an interrupt is pending */
69 #ifndef WIN32
70 #define INTERRUPTS_PENDING_CONDITION() (unlikely(InterruptPending))
71 #else
72 extern void pgwin32_dispatch_queued_signals(void);
73 #define INTERRUPTS_PENDING_CONDITION() \
74  (unlikely(UNBLOCKED_SIGNAL_QUEUE()) ? pgwin32_dispatch_queued_signals() : 0, \
75  unlikely(InterruptPending))
76 #endif
77 
78 /* Service interrupt, if one is pending and it's safe to service it now */
79 #define CHECK_FOR_INTERRUPTS() \
80  do { \
81  if (INTERRUPTS_PENDING_CONDITION()) ProcessInterrupts(); \
82  } while (0)
83 #endif
84 }
85 
86 #endif // INCLUDE_CPP_COMMON_INTERRUPTION_H_
ProcessInterrupts
void ProcessInterrupts(void)
InterruptPending
volatile sig_atomic_t InterruptPending
PGDLLIMPORT
#define PGDLLIMPORT
Definition: interruption.h:54