00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef _TIMER_XSB_H_
00026 #define _TIMER_XSB_H_
00027
00028 #ifndef CONFIG_INCLUDED
00029 #error "File xsb_config.h must be included before this file"
00030 #endif
00031
00032 #ifndef CELL_DEFS_INCLUDED
00033 #error "File cell_xsb.h must be included before this file"
00034 #endif
00035
00036 #ifndef SYSTEM_FLAGS
00037 #include "flags_xsb.h"
00038 #endif
00039
00040 #include "timer_defs_xsb.h"
00041 #include "context.h"
00042 #include "setjmp_xsb.h"
00043 #include "thread_xsb.h"
00044
00045 #ifndef MULTI_THREAD
00046 #ifdef WIN_NT
00047 #include <windows.h>
00048 #endif
00049 #endif
00050
00051 #define NORMAL_TERMINATION -1
00052 #define TIMED_OUT 1
00053 #define STILL_WAITING 0
00054 #if !defined(WIN_NT) && !defined(MULTI_THREAD)
00055 extern sigjmp_buf xsb_timer_env;
00056 #endif
00057
00058
00059
00060 struct xsb_timeout_info {
00061 int exitFlag;
00062 #ifdef MULTI_THREAD
00063 pthread_t_p timedThread;
00064 pthread_cond_t condition;
00065 pthread_mutex_t mutex;
00066 CTXTdecl;
00067 #else
00068 #ifdef WIN_NT
00069 long parent_thread;
00070 #else
00071
00072 #endif
00073 #endif
00074 };
00075
00076 typedef struct xsb_timeout_info xsbTimeoutInfo;
00077
00078 struct xsb_timeout {
00079 xsbTimeoutInfo timeout_info;
00080 };
00081
00082
00083 typedef struct xsb_timeout xsbTimeout;
00084
00085
00086
00087 int make_timed_call(CTXTdeclc xsbTimeout*, void (*) (xsbTimeout*));
00088
00089
00090
00091
00092
00093 #ifdef MULTI_THREAD
00094
00095 #define SETALARM ;
00096 #define OP_TIMED_OUT(timeout) (op_timed_out(CTXTc timeout))
00097
00098 #define TURNOFFALARM
00099 #define CHECK_TIMER_SET ((int)pflags[SYS_TIMER] > 0)
00100 #define NOTIFY_PARENT_THREAD(timeout) \
00101 if (CHECK_TIMER_SET) { \
00102
00103 \
00104 pthread_mutex_lock(&timeout->timeout_info.mutex); \
00105 timeout->timeout_info.exitFlag = NORMAL_TERMINATION; \
00106 pthread_cond_signal(&timeout->timeout_info.condition); \
00107 pthread_mutex_unlock(&timeout->timeout_info.mutex); \
00108 }
00109
00110 #else
00111
00112 #ifdef WIN_NT
00113
00114 VOID CALLBACK xsb_timer_handler(HWND wind, UINT msg, UINT eventid, DWORD time);
00115 unsigned long _beginthread(void(_cdecl *start_address) (void *),
00116 unsigned stack_size,
00117 void *arglist);
00118 int message_pump();
00119 UINT xsb_timer_id;
00120
00121 #define TURNOFFALARM KillTimer(NULL, xsb_timer_id);
00122 #define CHECK_TIMER_SET ((int)pflags[SYS_TIMER] > 0)
00123 #define NOTIFY_PARENT_THREAD(timeout) \
00124 if (CHECK_TIMER_SET) {\
00125
00126 \
00127 PostThreadMessage((DWORD)(timeout->timeout_info.parent_thread), \
00128 WM_COMMAND,NORMAL_TERMINATION,0);\
00129 }
00130 #define OP_TIMED_OUT(timeout) (message_pump())
00131
00132 #else
00133
00134 void xsb_timer_handler(int signo);
00135
00136 #define SETALARM (signal(SIGALRM, xsb_timer_handler))
00137 #define TURNOFFALARM alarm(0);
00138 #define CHECK_TIMER_SET ((int)pflags[SYS_TIMER] > 0)
00139 #define NOTIFY_PARENT_THREAD(timeout) ;
00140 #define SET_TIMER alarm((int)pflags[SYS_TIMER])
00141 #define OP_TIMED_OUT (sigsetjmp(xsb_timer_env,1) != 0)
00142
00143 #endif
00144
00145 #endif
00146
00147 #endif