~ubuntu-branches/debian/squeeze/erlang/squeeze

« back to all changes in this revision

Viewing changes to erts/emulator/sys/unix/erl_unix_sys.h

  • Committer: Bazaar Package Importer
  • Author(s): Erlang Packagers, Sergei Golovan
  • Date: 2006-12-03 17:07:44 UTC
  • mfrom: (2.1.11 feisty)
  • Revision ID: james.westby@ubuntu.com-20061203170744-rghjwupacqlzs6kv
Tags: 1:11.b.2-4
[ Sergei Golovan ]
Fixed erlang-base and erlang-base-hipe prerm scripts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
#ifndef _ERL_UNIX_SYS_H
24
24
#define _ERL_UNIX_SYS_H
25
25
 
26
 
#if defined(__linux__) && defined(__GNUC__)
27
 
#   define _GNU_SOURCE 1 /* we want to turn some features */
28
 
#endif
29
 
 
30
26
#include <stdio.h>
31
27
#include <math.h>
32
28
#include <limits.h>
122
118
#   endif
123
119
#endif
124
120
 
125
 
/*
126
 
 * Make sure that ENOTSUP is defined.
127
 
 */
128
 
 
129
 
#ifndef ENOTSUP
130
 
#define ENOTSUP         -1738659
 
121
#ifdef ERTS_WANT_BREAK_HANDLING
 
122
extern volatile int erts_break_requested;
 
123
void erts_do_break_handling(void);
131
124
#endif
132
125
 
 
126
#define HAVE_ERTS_CHECK_IO_DEBUG
 
127
int erts_check_io_debug(void);
 
128
 
133
129
/*
134
130
** For the erl_timer_sup module.
135
131
*/
142
138
 
143
139
extern int erts_ticks_per_sec;
144
140
 
 
141
extern volatile int erts_got_sigusr1;
 
142
 
145
143
#define SYS_CLK_TCK (erts_ticks_per_sec)
146
144
 
147
145
#define sys_times(Arg) times(Arg)
159
157
 
160
158
#endif /* HAVE_GETHRTIME */
161
159
 
162
 
#ifdef HAVE_GETHRVTIME
163
 
#  define sys_gethrvtime() gethrvtime()
 
160
#if (defined(HAVE_GETHRVTIME) || defined(HAVE_CLOCK_GETTIME))
 
161
typedef long long SysCpuTime;
 
162
typedef struct timespec SysTimespec;
 
163
 
 
164
#if defined(HAVE_GETHRVTIME)
 
165
#define sys_gethrvtime() gethrvtime()
 
166
#define sys_get_proc_cputime(t,tp) (t) = sys_gethrvtime(), \
 
167
                                   (tp).tv_sec = (time_t)((t)/1000000000LL), \
 
168
                                   (tp).tv_nsec = (long)((t)%1000000000LL)
164
169
int sys_start_hrvtime(void);
165
170
int sys_stop_hrvtime(void);
166
 
#endif /* HAVE_GETHRVTIME */
 
171
 
 
172
#elif defined(HAVE_CLOCK_GETTIME)
 
173
#define sys_clock_gettime(cid,tp) clock_gettime((cid),&(tp))
 
174
#define sys_get_proc_cputime(t,tp) sys_clock_gettime(CLOCK_PROCESS_CPUTIME_ID,(tp))
 
175
 
 
176
#endif
 
177
#endif
167
178
 
168
179
/* No use in having other resolutions than 1 Ms. */
169
180
#define SYS_CLOCK_RESOLUTION 1
184
195
 * Handling of floating point exceptions.
185
196
 */
186
197
 
187
 
extern volatile int erl_fp_exception;
188
 
 
189
198
#ifdef USE_ISINF_ISNAN          /* simulate finite() */
190
199
#  define finite(f) (!isinf(f) && !isnan(f))
191
200
#  define HAVE_FINITE
192
201
#endif
193
202
 
194
203
#ifdef NO_FPE_SIGNALS
195
 
#  define ERTS_FP_CHECK_INIT() do {} while (0)
196
 
#  define ERTS_FP_ERROR(f, Action) if (!finite(f)) { Action; } else {}
197
 
#  define ERTS_SAVE_FP_EXCEPTION()
198
 
#  define ERTS_RESTORE_FP_EXCEPTION()
199
 
#else
200
 
#  define ERTS_FP_CHECK_INIT() do {erl_fp_exception = 0;} while (0)
201
 
#  if defined(__i386__) && defined(__GNUC__)
202
 
extern void erts_restore_x87(void);
203
 
static __inline__ int erts_check_x87(double f)
 
204
#define erts_get_current_fp_exception() NULL
 
205
#ifdef ERTS_SMP
 
206
#define erts_thread_init_fp_exception() do{}while(0)
 
207
#endif
 
208
#  define __ERTS_FP_CHECK_INIT(fpexnp) do {} while (0)
 
209
#  define __ERTS_FP_ERROR(fpexnp, f, Action) if (!finite(f)) { Action; } else {}
 
210
#  define __ERTS_FP_ERROR_THOROUGH(fpexnp, f, Action) __ERTS_FP_ERROR(fpexnp, f, Action)
 
211
#  define __ERTS_SAVE_FP_EXCEPTION(fpexnp)
 
212
#  define __ERTS_RESTORE_FP_EXCEPTION(fpexnp)
 
213
 
 
214
#else /* !NO_FPE_SIGNALS */
 
215
 
 
216
extern volatile int *erts_get_current_fp_exception(void);
 
217
#ifdef ERTS_SMP
 
218
extern void erts_thread_init_fp_exception(void);
 
219
#endif
 
220
#  if (defined(__i386__) || defined(__x86_64__)) && defined(__GNUC__)
 
221
#    define erts_fwait(fpexnp,f) \
 
222
        __asm__ __volatile__("fwait" : "=m"(*(fpexnp)) : "m"(f))
 
223
#  elif (defined(__powerpc__) || defined(__ppc__)) && defined(__GNUC__)
 
224
#    define erts_fwait(fpexnp,f) \
 
225
        __asm__ __volatile__("" : "=m"(*(fpexnp)) : "fm"(f))
 
226
#  elif defined(__sparc__) && defined(__linux__) && defined(__GNUC__)
 
227
#    define erts_fwait(fpexnp,f) \
 
228
        __asm__ __volatile__("" : "=m"(*(fpexnp)) : "em"(f))
 
229
#  else
 
230
#    define erts_fwait(fpexnp,f) \
 
231
        __asm__ __volatile__("" : "=m"(*(fpexnp)) : "g"(f))
 
232
#  endif
 
233
#  if (defined(__i386__) || defined(__x86_64__)) && defined(__GNUC__)
 
234
     extern void erts_restore_fpu(void);
 
235
#  else
 
236
#    define erts_restore_fpu() /*empty*/
 
237
#  endif
 
238
#  if (!defined(__GNUC__) || \
 
239
       (__GNUC__ < 2) || \
 
240
       (__GNUC__ == 2 && __GNUC_MINOR < 96)) && \
 
241
      !defined(__builtin_expect)
 
242
#    define __builtin_expect(x, expected_value) (x)
 
243
#  endif
 
244
static __inline__ int erts_check_fpe(volatile int *fp_exception, double f)
204
245
{
205
 
    __asm__ __volatile__("fwait" : "=m"(erl_fp_exception) : "m"(f));
206
 
    if( !erl_fp_exception )
 
246
    erts_fwait(fp_exception, f);
 
247
    if (__builtin_expect(!*fp_exception, 1))
207
248
       return 0;
208
 
    erts_restore_x87();
 
249
    erts_restore_fpu();
209
250
    return 1;
210
251
}
211
 
#  define ERTS_FP_ERROR(f, Action) do { if( erts_check_x87((f)) ) { Action; } } while (0)
212
 
#  else
213
 
static __inline__ int erts_check_fpe(double f)
 
252
#  undef erts_fwait
 
253
#  undef erts_restore_fpu
 
254
#  define __ERTS_FP_CHECK_INIT(fpexnp) do { *(fpexnp) = 0; } while (0)
 
255
#  define __ERTS_FP_ERROR(fpexnp, f, Action) do { if (erts_check_fpe((fpexnp),(f))) { Action; } } while (0)
 
256
#  define __ERTS_SAVE_FP_EXCEPTION(fpexnp) int old_erl_fp_exception = *(fpexnp)
 
257
#  define __ERTS_RESTORE_FP_EXCEPTION(fpexnp) \
 
258
              do { *(fpexnp) = old_erl_fp_exception; } while (0)
 
259
   /* This is for library calls where we don't trust the external
 
260
      code to always throw floating-point exceptions on errors. */
 
261
static __inline__ int erts_check_fpe_thorough(volatile int *fp_exception, double f)
214
262
{
215
 
    __asm__ __volatile__("" : "=m"(erl_fp_exception) : "g"(f));
216
 
    return erl_fp_exception;
 
263
    return erts_check_fpe(fp_exception, f) || !finite(f);
217
264
}
218
 
#  define ERTS_FP_ERROR(f, Action) do { if( erts_check_fpe((f)) ) { Action; } } while (0)
219
 
#  endif
220
 
#  define ERTS_SAVE_FP_EXCEPTION() int old_erl_fp_exception = erl_fp_exception
221
 
#  define ERTS_RESTORE_FP_EXCEPTION() \
222
 
              do {erl_fp_exception = old_erl_fp_exception;} while (0)
223
 
#endif
 
265
#  define __ERTS_FP_ERROR_THOROUGH(fpexnp, f, Action) \
 
266
  do { if (erts_check_fpe_thorough((fpexnp),(f))) { Action; } } while (0)
 
267
 
 
268
#endif /* !NO_FPE_SIGNALS */
 
269
 
 
270
#define ERTS_FP_CHECK_INIT(p)           __ERTS_FP_CHECK_INIT(&(p)->fp_exception)
 
271
#define ERTS_FP_ERROR(p, f, A)          __ERTS_FP_ERROR(&(p)->fp_exception, f, A)
 
272
#define ERTS_FP_ERROR_THOROUGH(p, f, A) __ERTS_FP_ERROR_THOROUGH(&(p)->fp_exception, f, A)
224
273
 
225
274
 
226
275
#ifdef NEED_CHILD_SETUP_DEFINES
241
290
extern int exit_async(void);
242
291
#endif
243
292
 
 
293
#define ERTS_EXIT_AFTER_DUMP _exit
 
294
 
 
295
#ifdef ERTS_TIMER_THREAD
 
296
struct erts_iwait; /* opaque for clients */
 
297
extern struct erts_iwait *erts_iwait_init(void);
 
298
extern void erts_iwait_wait(struct erts_iwait *iwait, struct timeval *delay);
 
299
extern void erts_iwait_interrupt(struct erts_iwait *iwait);
 
300
#endif /* ERTS_TIMER_THREAD */
 
301
 
244
302
#endif /* #ifndef _ERL_UNIX_SYS_H */