rubysig.h


DEFINITIONS

This source file includes following functions.
  1. ATOMIC_TEST
  2. ATOMIC_SET
  3. ATOMIC_INC
  4. ATOMIC_DEC
  5. RUBY_CRITICAL
  6. ATOMIC_TEST
  7. ATOMIC_SET
  8. ATOMIC_INC
  9. ATOMIC_DEC
  10. RUBY_CRITICAL


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