PageRenderTime 78ms CodeModel.GetById 73ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/tools/Ruby/lib/ruby/1.8/i386-mingw32/rubysig.h

http://github.com/agross/netopenspace
C Header | 105 lines | 80 code | 12 blank | 13 comment | 17 complexity | 41f0a57076c4562e3b265db39b29aa3e MD5 | raw file
  1/**********************************************************************
  2
  3  rubysig.h -
  4
  5  $Author: shyouhei $
  6  $Date: 2009-01-05 11:16:18 +0900 (Mon, 05 Jan 2009) $
  7  created at: Wed Aug 16 01:15:38 JST 1995
  8
  9  Copyright (C) 1993-2003 Yukihiro Matsumoto
 10
 11**********************************************************************/
 12
 13#ifndef SIG_H
 14#define SIG_H
 15#include <errno.h>
 16
 17#ifdef _WIN32
 18typedef LONG rb_atomic_t;
 19
 20# define ATOMIC_TEST(var) InterlockedExchange(&(var), 0)
 21# define ATOMIC_SET(var, val) InterlockedExchange(&(var), (val))
 22# define ATOMIC_INC(var) InterlockedIncrement(&(var))
 23# define ATOMIC_DEC(var) InterlockedDecrement(&(var))
 24
 25/* Windows doesn't allow interrupt while system calls */
 26# define TRAP_BEG do {\
 27    int saved_errno = 0;\
 28    rb_atomic_t trap_immediate = ATOMIC_SET(rb_trap_immediate, 1)
 29# define TRAP_END\
 30    ATOMIC_SET(rb_trap_immediate, trap_immediate);\
 31    saved_errno = errno;\
 32    CHECK_INTS;\
 33    errno = saved_errno;\
 34} while (0)
 35# define RUBY_CRITICAL(statements) do {\
 36    rb_w32_enter_critical();\
 37    statements;\
 38    rb_w32_leave_critical();\
 39} while (0)
 40#else
 41typedef int rb_atomic_t;
 42
 43# define ATOMIC_TEST(var) ((var) ? ((var) = 0, 1) : 0)
 44# define ATOMIC_SET(var, val) ((var) = (val))
 45# define ATOMIC_INC(var) (++(var))
 46# define ATOMIC_DEC(var) (--(var))
 47
 48# define TRAP_BEG do {\
 49    int saved_errno = 0;\
 50    int trap_immediate = rb_trap_immediate;\
 51    rb_trap_immediate = 1
 52# define TRAP_END rb_trap_immediate = trap_immediate;\
 53    saved_errno = errno;\
 54    CHECK_INTS;\
 55    errno = saved_errno;\
 56} while (0)
 57
 58# define RUBY_CRITICAL(statements) do {\
 59    int trap_immediate = rb_trap_immediate;\
 60    rb_trap_immediate = 0;\
 61    statements;\
 62    rb_trap_immediate = trap_immediate;\
 63} while (0)
 64#endif
 65RUBY_EXTERN rb_atomic_t rb_trap_immediate;
 66
 67RUBY_EXTERN int rb_prohibit_interrupt;
 68#define DEFER_INTS (rb_prohibit_interrupt++)
 69#define ALLOW_INTS do {\
 70    rb_prohibit_interrupt--;\
 71    CHECK_INTS;\
 72} while (0)
 73#define ENABLE_INTS (rb_prohibit_interrupt--)
 74
 75VALUE rb_with_disable_interrupt _((VALUE(*)(ANYARGS),VALUE));
 76
 77RUBY_EXTERN rb_atomic_t rb_trap_pending;
 78void rb_trap_restore_mask _((void));
 79
 80RUBY_EXTERN int rb_thread_critical;
 81RUBY_EXTERN int rb_thread_pending;
 82void rb_thread_schedule _((void));
 83#if defined(HAVE_SETITIMER) || defined(_THREAD_SAFE)
 84# define CHECK_INTS do {\
 85    if (!(rb_prohibit_interrupt || rb_thread_critical)) {\
 86	if (rb_thread_pending) rb_thread_schedule();\
 87	if (rb_trap_pending) rb_trap_exec();\
 88    }\
 89} while (0)
 90#else
 91/* pseudo preemptive thread switching */
 92RUBY_EXTERN int rb_thread_tick;
 93#define THREAD_TICK 500
 94#define CHECK_INTS do {\
 95    if (!(rb_prohibit_interrupt || rb_thread_critical)) {\
 96	if (rb_thread_pending || rb_thread_tick-- <= 0) {\
 97	    rb_thread_tick = THREAD_TICK;\
 98	    rb_thread_schedule();\
 99	}\
100    }\
101    if (rb_trap_pending) rb_trap_exec();\
102} while (0)
103#endif
104
105#endif