4 * System-dependent functions for GNU Shogi.
6 * ----------------------------------------------------------------------
7 * Copyright (c) 1993, 1994, 1995 Matthias Mutz
8 * Copyright (c) 1999 Michael Vanier and the Free Software Foundation
10 * GNU SHOGI is based on GNU CHESS
12 * Copyright (c) 1988, 1989, 1990 John Stanback
13 * Copyright (c) 1992 Free Software Foundation
15 * This file is part of GNU SHOGI.
17 * GNU Shogi is free software; you can redistribute it and/or modify it
18 * under the terms of the GNU General Public License as published by the
19 * Free Software Foundation; either version 1, or (at your option) any
22 * GNU Shogi is distributed in the hope that it will be useful, but WITHOUT
23 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
24 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
27 * You should have received a copy of the GNU General Public License along
28 * with GNU Shogi; see the file COPYING. If not, write to the Free
29 * Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
30 * ----------------------------------------------------------------------
41 /* Definition of FIONREAD */
42 #include <sys/filio.h>
46 /* Forward declarations. */
48 void ElapsedTime_NOFIONREAD(ElapsedTime_mode iop);
49 void ElapsedTime_FIONREAD(ElapsedTime_mode iop);
53 * Determine the time that has passed since the search was started. If the
54 * elapsed time exceeds the target(ResponseTime + ExtraTime) then set timeout
55 * to true which will terminate the search.
56 * iop = COMPUTE_MODE calculate et, bump ETnodes
57 * iop = COMPUTE_AND_INIT_MODE calculate et, set timeout if time exceeded,
62 * ElapsedTime() is actually a wrapper function around the different
63 * versions of ElapsedTime_XXX(). This allows us to compile all the
64 * different ways of measuring time in one executable.
68 ElapsedTime(ElapsedTime_mode iop)
73 ElapsedTime_NOFIONREAD(iop);
77 ElapsedTime_FIONREAD(iop);
84 #ifdef HAVE_GETTIMEOFDAY
86 ElapsedTime_FIONREAD(ElapsedTime_mode iop)
95 if ((i = ioctl((int) 0, FIONREAD, &nchar)))
99 "You probably have a non-ANSI <ioctl.h>; "
100 "see README. %d %d %x\n",
110 flag.bothsides = false;
113 gettimeofday(&tv, NULL);
114 current_time = tv.tv_sec*100 + (tv.tv_usec/10000);
116 # ifdef INTERRUPT_TEST
117 if (iop == INIT_INTERRUPT_MODE)
119 itime0 = current_time;
121 else if (iop == COMPUTE_INTERRUPT_MODE)
123 it = current_time - itime0;
128 et = current_time - time0;
129 ETnodes = NodeCnt + znodes;
133 # ifdef INTERRUPT_TEST
134 printf("elapsed time %ld not positive\n", et);
139 if (iop == COMPUTE_AND_INIT_MODE)
141 if ((et > ResponseTime + ExtraTime) && (Sdepth > MINDEPTH))
144 time0 = current_time;
149 # ifdef QUIETBACKGROUND
151 # endif /* QUIETBACKGROUND */
159 ElapsedTime_NOFIONREAD(ElapsedTime_mode iop)
164 gettimeofday(&tv, NULL);
165 current_time = tv.tv_sec*100 + (tv.tv_usec/10000);
167 # ifdef INTERRUPT_TEST
168 if (iop == INIT_INTERRUPT_MODE)
170 itime0 = current_time;
172 else if (iop == COMPUTE_INTERRUPT_MODE)
174 it = current_time - itime0;
179 et = current_time - time0;
180 ETnodes = NodeCnt + znodes;
184 # ifdef INTERRUPT_TEST
185 printf("elapsed time %ld not positive\n", et);
190 if (iop == COMPUTE_AND_INIT_MODE)
192 if ((et > ResponseTime + ExtraTime) && (Sdepth > MINDEPTH))
195 time0 = current_time;
200 # ifdef QUIETBACKGROUND
202 # endif /* QUIETBACKGROUND */
209 #else /* !HAVE_GETTIMEOFDAY */
213 * Determine the time that has passed since the search was started. If the
214 * elapsed time exceeds the target (ResponseTime + ExtraTime) then set
215 * timeout to true which will terminate the search.
217 * iop = 0 calculate et, bump ETnodes
218 * iop = 1 calculate et, set timeout if time exceeded, calculate et
223 ElapsedTime_FIONREAD(ElapsedTime_mode iop)
232 if ((i = ioctl((int) 0, FIONREAD, &nchar)))
236 "You probably have a non-ANSI <ioctl.h>; "
237 "see README. %d %d %x\n",
246 flag.bothsides = false;
249 et = ((current_time = time((long *) 0)) - time0) * 100;
251 #ifdef INTERRUPT_TEST
252 if (iop == INIT_INTERRUPT_MODE)
254 itime0 = current_time;
256 else if (iop == COMPUTE_INTERRUPT_MODE)
258 it = current_time - itime0;
263 ETnodes = NodeCnt + znodes;
267 #ifdef INTERRUPT_TEST
268 printf("elapsed time %ld not positive\n", et);
273 if (iop == COMPUTE_AND_INIT_MODE)
275 if ((et > (ResponseTime + ExtraTime)) && (Sdepth > MINDEPTH))
278 time0 = current_time;
283 #ifdef QUIETBACKGROUND
285 #endif /* QUIETBACKGROUND */
294 ElapsedTime_NOFIONREAD(ElapsedTime_mode iop)
298 et = ((current_time = time((long *) 0)) - time0) * 100;
300 #ifdef INTERRUPT_TEST
301 if (iop == INIT_INTERRUPT_MODE)
303 itime0 = current_time;
305 else if (iop == COMPUTE_INTERRUPT_MODE)
307 it = current_time - itime0;
312 ETnodes = NodeCnt + znodes;
316 #ifdef INTERRUPT_TEST
317 printf("elapsed time %ld not positive\n", et);
322 if (iop == COMPUTE_AND_INIT_MODE)
324 if ((et > (ResponseTime + ExtraTime)) && (Sdepth > MINDEPTH))
327 time0 = current_time;
332 #ifdef QUIETBACKGROUND
334 #endif /* QUIETBACKGROUND */
341 #endif /* HAVE_GETTIMEOFDAY */