summaryrefslogtreecommitdiffstats
path: root/ast/globals.h
blob: 770ec5c120cbf60650b5d8d2083365ce6052d1fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
#if !defined( GLOBALS_INCLUDED )   /* Include this file only once */
#define GLOBALS_INCLUDED 1

/* If thread-safety is required... */
#if defined( THREAD_SAFE ) && ( defined( astCLASS ) || defined( astFORTRAN77) )

/* Include files: */
/* ============== */

/* AST includes */
#include "axis.h"
#include "box.h"
#include "channel.h"
#include "chebymap.h"
#include "circle.h"
#include "cmpframe.h"
#include "cmpmap.h"
#include "cmpregion.h"
#include "dsbspecframe.h"
#include "dssmap.h"
#include "ellipse.h"
#include "error.h"
#include "fitschan.h"
#include "fitstable.h"
#include "fluxframe.h"
#include "frame.h"
#include "frameset.h"
#include "grismmap.h"
#include "interval.h"
#include "intramap.h"
#include "keymap.h"
#include "lutmap.h"
#include "mapping.h"
#include "mathmap.h"
#include "matrixmap.h"
#include "memory.h"
#include "moc.h"
#include "mocchan.h"
#include "normmap.h"
#include "nullregion.h"
#include "object.h"
#include "pcdmap.h"
#include "permmap.h"
#include "plot.h"
#include "plot3d.h"
#include "pointlist.h"
#include "pointset.h"
#include "polygon.h"
#include "polymap.h"
#include "prism.h"
#include "ratemap.h"
#include "region.h"
#include "selectormap.h"
#include "shiftmap.h"
#include "skyaxis.h"
#include "skyframe.h"
#include "slamap.h"
#include "specfluxframe.h"
#include "specframe.h"
#include "specmap.h"
#include "sphmap.h"
#include "stc.h"
#include "stccatalogentrylocation.h"
#include "stcobsdatalocation.h"
#include "stcresourceprofile.h"
#include "stcsearchlocation.h"
#include "stcschan.h"
#include "switchmap.h"
#include "table.h"
#include "timeframe.h"
#include "timemap.h"
#include "tranmap.h"
#include "unitmap.h"
#include "unitnormmap.h"
#include "wcsmap.h"
#include "winmap.h"
#include "xml.h"
#include "xmlchan.h"
#include "xphmap.h"
#include "zoommap.h"



/* System includes */
#include <pthread.h>

/* Macros */
/* ====== */

/* The name of the variable used to access thread-specific global data */
#define AST__GLOBALS ast_globals

/* Defines a macro that gives access to a specific global data item. */
#define astGLOBAL(class,name) (AST__GLOBALS->class.name)


/* Declares the pointer for the structure holding thread-specific values
   for AST global data. */
#define astDECLARE_GLOBALS AstGlobals *AST__GLOBALS;


/* A macro that should be invoked in each function that refers to a
   global data item. The "This" parameter should be a pointer to an
   Object, or NULL. It ensures the thread-specific data key has been
   created. It also allocates and initialises memory to hold the global
   data. */
#define astGET_GLOBALS(This) \
\
/* If the supplied Object pointer contains a pointer to the thread-specific \
   data structure, return it. */ \
   if( This && ((AstObject *)This)->globals ) { \
      AST__GLOBALS = ((AstObject *)This)->globals; \
\
/* Otherwise, ensure that the thread specific data key has been created. */ \
   } else if( pthread_once( &starlink_ast_globals_initialised, \
                            astGlobalsCreateKey_ ) ) { \
      AST__GLOBALS = NULL; \
      fprintf( stderr, "Starlink AST package initialisation failed." ); \
\
/* If the current thread does not yet have a structure to hold \
   thread-specific global data, create one now (initialising its \
   contents) and associate it with the thread speciifc data key. */ \
   } else if( ( AST__GLOBALS =  \
                pthread_getspecific( starlink_ast_globals_key ) ) == NULL ) { \
      AST__GLOBALS = astGlobalsInit_(); \
      if( pthread_setspecific( starlink_ast_globals_key, AST__GLOBALS ) ) { \
         fprintf( stderr, "Starlink AST failed to store Thread-Specific " \
                  "Data pointer." ); \
      } \
   }


/* A macro that expands to the value of a unique integer identifier for
   the calling thread. */
#define AST__THREAD_ID (AST__GLOBALS->thread_identifier) \


#define astMAKE_INITGLOBALS(class) \
\
void astInit##class##Globals_( Ast##class##Globals *globals ){ \
   GLOBAL_inits \
}

/* Type definitions */
/* ================ */

typedef struct AstGlobals {
   int thread_identifier;
   AstMemoryGlobals Memory;
   AstErrorGlobals  Error;
   AstObjectGlobals Object;
   AstAxisGlobals Axis;
   AstMappingGlobals Mapping;
   AstFrameGlobals Frame;
   AstChannelGlobals Channel;
   AstCmpMapGlobals CmpMap;
   AstKeyMapGlobals KeyMap;
   AstFitsChanGlobals FitsChan;
   AstFitsTableGlobals FitsTable;
   AstCmpFrameGlobals CmpFrame;
   AstDSBSpecFrameGlobals DSBSpecFrame;
   AstFrameSetGlobals FrameSet;
   AstLutMapGlobals LutMap;
   AstMathMapGlobals MathMap;
   AstPcdMapGlobals PcdMap;
   AstPointSetGlobals PointSet;
   AstSkyAxisGlobals SkyAxis;
   AstSkyFrameGlobals SkyFrame;
   AstSlaMapGlobals SlaMap;
   AstSpecFrameGlobals SpecFrame;
   AstSphMapGlobals SphMap;
   AstTimeFrameGlobals TimeFrame;
   AstWcsMapGlobals WcsMap;
   AstZoomMapGlobals ZoomMap;
   AstFluxFrameGlobals FluxFrame;
   AstSpecFluxFrameGlobals SpecFluxFrame;
   AstGrismMapGlobals GrismMap;
   AstIntraMapGlobals IntraMap;
   AstPlotGlobals Plot;
   AstPlot3DGlobals Plot3D;
   AstRegionGlobals Region;
   AstBoxGlobals Box;
   AstXmlGlobals Xml;
   AstXphMapGlobals XphMap;
   AstXmlChanGlobals XmlChan;
   AstCircleGlobals Circle;
   AstCmpRegionGlobals CmpRegion;
   AstDssMapGlobals DssMap;
   AstEllipseGlobals Ellipse;
   AstIntervalGlobals Interval;
   AstMatrixMapGlobals MatrixMap;
   AstMocGlobals Moc;
   AstMocChanGlobals MocChan;
   AstNormMapGlobals NormMap;
   AstNullRegionGlobals NullRegion;
   AstPermMapGlobals PermMap;
   AstPointListGlobals PointList;
   AstPolyMapGlobals PolyMap;
   AstChebyMapGlobals ChebyMap;
   AstPolygonGlobals Polygon;
   AstPrismGlobals Prism;
   AstRateMapGlobals RateMap;
   AstSelectorMapGlobals SelectorMap;
   AstShiftMapGlobals ShiftMap;
   AstSpecMapGlobals SpecMap;
   AstStcGlobals Stc;
   AstStcCatalogEntryLocationGlobals StcCatalogEntryLocation;
   AstStcObsDataLocationGlobals StcObsDataLocation;
   AstSwitchMapGlobals SwitchMap;
   AstTableGlobals Table;
   AstTimeMapGlobals TimeMap;
   AstTranMapGlobals TranMap;
   AstUnitMapGlobals UnitMap;
   AstUnitNormMapGlobals UnitNormMap;
   AstWinMapGlobals WinMap;
   AstStcResourceProfileGlobals	StcResourceProfile;
   AstStcSearchLocationGlobals StcSearchLocation;
   AstStcsChanGlobals StcsChan;
} AstGlobals;


/* Externally declared variables */
/* ============================= */


/* The pthreads key that is associated with the thread-specific data for
   each thread. Declared in global.c. */
extern pthread_key_t starlink_ast_globals_key;

/* The pthreads key that is associated with the thread-specific status
   value for each thread. Declared in global.c. */
extern pthread_key_t starlink_ast_status_key;

/* This is a flag indicating that the thread-specific data key has not yet
   been created. Declared in globals.c. */
extern pthread_once_t starlink_ast_globals_initialised;

/* Function Prototypes: */
/* ==================== */

void astGlobalsCreateKey_( void );
AstGlobals *astGlobalsInit_( void );


/* If thread-safety is not required, define some null macros. */
#else

#define astDECLARE_GLOBALS
#define astGET_GLOBALS(This)
#define astINIT_GLOBALS

#endif
#endif