comparison src/os_unix.c @ 14:946da5994c01

updated for version 7.0006
author vimboss
date Mon, 05 Jul 2004 15:58:32 +0000
parents bdeee1504ac1
children cc049b00ee70
comparison
equal deleted inserted replaced
13:24d5189d3956 14:946da5994c01
28 #ifndef __APPLE__ 28 #ifndef __APPLE__
29 # define select select_declared_wrong 29 # define select select_declared_wrong
30 #endif 30 #endif
31 31
32 #include "vim.h" 32 #include "vim.h"
33
34 #ifdef FEAT_MZSCHEME
35 # include "if_mzsch.h"
36 #endif
33 37
34 #ifdef HAVE_FCNTL_H 38 #ifdef HAVE_FCNTL_H
35 # include <fcntl.h> 39 # include <fcntl.h>
36 #endif 40 #endif
37 41
258 {SIGTERM, "TERM", TRUE}, 262 {SIGTERM, "TERM", TRUE},
259 #endif 263 #endif
260 #ifdef SIGVTALRM 264 #ifdef SIGVTALRM
261 {SIGVTALRM, "VTALRM", TRUE}, 265 {SIGVTALRM, "VTALRM", TRUE},
262 #endif 266 #endif
263 #ifdef SIGPROF 267 #if defined(SIGPROF) && !defined(FEAT_MZSCHEME)
268 /* MzScheme uses SIGPROF for its own needs */
264 {SIGPROF, "PROF", TRUE}, 269 {SIGPROF, "PROF", TRUE},
265 #endif 270 #endif
266 #ifdef SIGXCPU 271 #ifdef SIGXCPU
267 {SIGXCPU, "XCPU", TRUE}, 272 {SIGXCPU, "XCPU", TRUE},
268 #endif 273 #endif
518 mch_delay(msec, ignoreinput) 523 mch_delay(msec, ignoreinput)
519 long msec; 524 long msec;
520 int ignoreinput; 525 int ignoreinput;
521 { 526 {
522 int old_tmode; 527 int old_tmode;
528 #ifdef FEAT_MZSCHEME
529 long total = msec; /* remember original value */
530 #endif
523 531
524 if (ignoreinput) 532 if (ignoreinput)
525 { 533 {
526 /* Go to cooked mode without echo, to allow SIGINT interrupting us 534 /* Go to cooked mode without echo, to allow SIGINT interrupting us
527 * here */ 535 * here */
532 /* 540 /*
533 * Everybody sleeps in a different way... 541 * Everybody sleeps in a different way...
534 * Prefer nanosleep(), some versions of usleep() can only sleep up to 542 * Prefer nanosleep(), some versions of usleep() can only sleep up to
535 * one second. 543 * one second.
536 */ 544 */
545 #ifdef FEAT_MZSCHEME
546 do
547 {
548 /* if total is large enough, wait by portions in p_mzq */
549 if (total > p_mzq)
550 msec = p_mzq;
551 else
552 msec = total;
553 total -= msec;
554 #endif
537 #ifdef HAVE_NANOSLEEP 555 #ifdef HAVE_NANOSLEEP
538 { 556 {
539 struct timespec ts; 557 struct timespec ts;
540 558
541 ts.tv_sec = msec / 1000; 559 ts.tv_sec = msec / 1000;
570 } 588 }
571 # endif /* __EMX__ */ 589 # endif /* __EMX__ */
572 # endif /* HAVE_SELECT */ 590 # endif /* HAVE_SELECT */
573 # endif /* HAVE_NANOSLEEP */ 591 # endif /* HAVE_NANOSLEEP */
574 #endif /* HAVE_USLEEP */ 592 #endif /* HAVE_USLEEP */
593 #ifdef FEAT_MZSCHEME
594 }
595 while (total > 0);
596 #endif
575 597
576 settmode(old_tmode); 598 settmode(old_tmode);
577 } 599 }
578 else 600 else
579 WaitForChar(msec); 601 WaitForChar(msec);
4064 int fd; 4086 int fd;
4065 long msec; 4087 long msec;
4066 int *check_for_gpm; 4088 int *check_for_gpm;
4067 { 4089 {
4068 int ret; 4090 int ret;
4069 #if defined(FEAT_XCLIPBOARD) || defined(USE_XSMP) 4091 #if defined(FEAT_XCLIPBOARD) || defined(USE_XSMP) || defined(FEAT_MZSCHEME)
4070 static int busy = FALSE; 4092 static int busy = FALSE;
4071 4093
4072 /* May retry getting characters after an event was handled. */ 4094 /* May retry getting characters after an event was handled. */
4073 # define MAY_LOOP 4095 # define MAY_LOOP
4074 4096
4079 struct timeval start_tv; 4101 struct timeval start_tv;
4080 4102
4081 if (msec > 0 && ( 4103 if (msec > 0 && (
4082 # ifdef FEAT_XCLIPBOARD 4104 # ifdef FEAT_XCLIPBOARD
4083 xterm_Shell != (Widget)0 4105 xterm_Shell != (Widget)0
4084 # ifdef USE_XSMP 4106 # if defined(USE_XSMP) || defined(FEAT_MZSCHEME)
4085 || 4107 ||
4086 # endif 4108 # endif
4087 # endif 4109 # endif
4088 # ifdef USE_XSMP 4110 # ifdef USE_XSMP
4089 xsmp_icefd != -1 4111 xsmp_icefd != -1
4112 # ifdef FEAT_MZSCHEME
4113 ||
4114 # endif
4115 # endif
4116 # ifdef FEAT_MZSCHEME
4117 (mzthreads_allowed() && p_mzq > 0)
4090 # endif 4118 # endif
4091 )) 4119 ))
4092 gettimeofday(&start_tv, NULL); 4120 gettimeofday(&start_tv, NULL);
4093 # endif 4121 # endif
4094 4122
4102 while (1) 4130 while (1)
4103 #endif 4131 #endif
4104 { 4132 {
4105 #ifdef MAY_LOOP 4133 #ifdef MAY_LOOP
4106 int finished = TRUE; /* default is to 'loop' just once */ 4134 int finished = TRUE; /* default is to 'loop' just once */
4135 # ifdef FEAT_MZSCHEME
4136 int mzquantum_used = FALSE;
4137 # endif
4107 #endif 4138 #endif
4108 #ifndef HAVE_SELECT 4139 #ifndef HAVE_SELECT
4109 struct pollfd fds[5]; 4140 struct pollfd fds[5];
4110 int nfd; 4141 int nfd;
4111 # ifdef FEAT_XCLIPBOARD 4142 # ifdef FEAT_XCLIPBOARD
4115 int gpm_idx = -1; 4146 int gpm_idx = -1;
4116 # endif 4147 # endif
4117 # ifdef USE_XSMP 4148 # ifdef USE_XSMP
4118 int xsmp_idx = -1; 4149 int xsmp_idx = -1;
4119 # endif 4150 # endif
4120 4151 int towait = (int)msec;
4152
4153 # ifdef FEAT_MZSCHEME
4154 mzvim_check_threads();
4155 if (mzthreads_allowed() && p_mzq > 0 && (msec < 0 || msec > p_mzq))
4156 {
4157 towait = (int)p_mzq; /* don't wait longer than 'mzquantum' */
4158 mzquantum_used = TRUE;
4159 }
4160 # endif
4121 fds[0].fd = fd; 4161 fds[0].fd = fd;
4122 fds[0].events = POLLIN; 4162 fds[0].events = POLLIN;
4123 nfd = 1; 4163 nfd = 1;
4124 4164
4125 # ifdef FEAT_SNIFF 4165 # ifdef FEAT_SNIFF
4157 fds[nfd].events = POLLIN; 4197 fds[nfd].events = POLLIN;
4158 nfd++; 4198 nfd++;
4159 } 4199 }
4160 # endif 4200 # endif
4161 4201
4162 ret = poll(fds, nfd, (int)msec); 4202 ret = poll(fds, nfd, towait);
4203 # ifdef FEAT_MZSCHEME
4204 if (ret == 0 && mzquantum_used)
4205 /* MzThreads scheduling is required and timeout occured */
4206 finished = FALSE;
4207 # endif
4163 4208
4164 # ifdef FEAT_SNIFF 4209 # ifdef FEAT_SNIFF
4165 if (ret < 0) 4210 if (ret < 0)
4166 sniff_disconnect(1); 4211 sniff_disconnect(1);
4167 else if (want_sniff_request) 4212 else if (want_sniff_request)
4201 if (p_verbose > 0) 4246 if (p_verbose > 0)
4202 MSG(_("XSMP lost ICE connection")); 4247 MSG(_("XSMP lost ICE connection"));
4203 xsmp_close(); 4248 xsmp_close();
4204 } 4249 }
4205 if (--ret == 0) 4250 if (--ret == 0)
4206 /* Try again */ 4251 finished = FALSE; /* Try again */
4207 finished = FALSE;
4208 } 4252 }
4209 # endif 4253 # endif
4210 4254
4211 4255
4212 #else /* HAVE_SELECT */ 4256 #else /* HAVE_SELECT */
4213 4257
4214 struct timeval tv; 4258 struct timeval tv;
4259 struct timeval *tvp;
4215 fd_set rfds, efds; 4260 fd_set rfds, efds;
4216 int maxfd; 4261 int maxfd;
4217 4262 long towait = msec;
4263
4264 # ifdef FEAT_MZSCHEME
4265 mzvim_check_threads();
4266 if (mzthreads_allowed() && p_mzq > 0 && (msec < 0 || msec > p_mzq))
4267 {
4268 towait = p_mzq; /* don't wait longer than 'mzquantum' */
4269 mzquantum_used = TRUE;
4270 }
4271 # endif
4218 # ifdef __EMX__ 4272 # ifdef __EMX__
4219 /* don't check for incoming chars if not in raw mode, because select() 4273 /* don't check for incoming chars if not in raw mode, because select()
4220 * always returns TRUE then (in some version of emx.dll) */ 4274 * always returns TRUE then (in some version of emx.dll) */
4221 if (curr_tmode != TMODE_RAW) 4275 if (curr_tmode != TMODE_RAW)
4222 return 0; 4276 return 0;
4223 # endif 4277 # endif
4224 4278
4225 if (msec >= 0) 4279 if (towait >= 0)
4226 { 4280 {
4227 tv.tv_sec = msec / 1000; 4281 tv.tv_sec = towait / 1000;
4228 tv.tv_usec = (msec % 1000) * (1000000/1000); 4282 tv.tv_usec = (towait % 1000) * (1000000/1000);
4229 } 4283 tvp = &tv;
4284 }
4285 else
4286 tvp = NULL;
4230 4287
4231 /* 4288 /*
4232 * Select on ready for reading and exceptional condition (end of file). 4289 * Select on ready for reading and exceptional condition (end of file).
4233 */ 4290 */
4234 FD_ZERO(&rfds); /* calls bzero() on a sun */ 4291 FD_ZERO(&rfds); /* calls bzero() on a sun */
4279 # ifdef OLD_VMS 4336 # ifdef OLD_VMS
4280 /* Old VMS as v6.2 and older have broken select(). It waits more than 4337 /* Old VMS as v6.2 and older have broken select(). It waits more than
4281 * required. Should not be used */ 4338 * required. Should not be used */
4282 ret = 0; 4339 ret = 0;
4283 # else 4340 # else
4284 ret = select(maxfd + 1, &rfds, NULL, &efds, (msec >= 0) ? &tv : NULL); 4341 ret = select(maxfd + 1, &rfds, NULL, &efds, tvp);
4342 # endif
4343 # ifdef FEAT_MZSCHEME
4344 if (ret == 0 && mzquantum_used)
4345 /* loop if MzThreads must be scheduled and timeout occured */
4346 finished = FALSE;
4285 # endif 4347 # endif
4286 4348
4287 # ifdef FEAT_SNIFF 4349 # ifdef FEAT_SNIFF
4288 if (ret < 0 ) 4350 if (ret < 0 )
4289 sniff_disconnect(1); 4351 sniff_disconnect(1);