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 3 of the License,
20 * or (at your option) any later version.
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, see
29 * <http://www.gnu.org/licenses/>.
30 * ----------------------------------------------------------------------
41 /* Definition of FIONREAD */
42 #include <sys/filio.h>
46 /* Definition of errno(). */
50 /* Forward declarations. */
52 void ElapsedTime_NOFIONREAD(ElapsedTime_mode iop);
53 void ElapsedTime_FIONREAD(ElapsedTime_mode iop);
57 * Determine the time that has passed since the search was started. If the
58 * elapsed time exceeds the target(ResponseTime + ExtraTime) then set timeout
59 * to true which will terminate the search.
60 * iop = COMPUTE_MODE calculate et, bump ETnodes
61 * iop = COMPUTE_AND_INIT_MODE calculate et, set timeout if time exceeded,
66 * ElapsedTime() is actually a wrapper function around the different
67 * versions of ElapsedTime_XXX(). This allows us to compile all the
68 * different ways of measuring time in one executable.
72 ElapsedTime(ElapsedTime_mode iop)
77 ElapsedTime_NOFIONREAD(iop);
81 ElapsedTime_FIONREAD(iop);
88 #ifdef HAVE_GETTIMEOFDAY
90 ElapsedTime_FIONREAD(ElapsedTime_mode iop)
98 if ((i = ioctl((int) 0, FIONREAD, &nchar)))
102 "You probably have a non-ANSI <ioctl.h>; "
103 "see README. %d %d %x\n",
113 flag.bothsides = false;
116 gettimeofday(&tv, NULL);
117 current_time = tv.tv_sec*100 + (tv.tv_usec/10000);
119 # ifdef INTERRUPT_TEST
120 if (iop == INIT_INTERRUPT_MODE)
122 itime0 = current_time;
124 else if (iop == COMPUTE_INTERRUPT_MODE)
126 it = current_time - itime0;
131 et = current_time - time0;
132 ETnodes = NodeCnt + znodes;
136 # ifdef INTERRUPT_TEST
137 printf("elapsed time %ld not positive\n", et);
142 if (iop == COMPUTE_AND_INIT_MODE)
144 if ((et > ResponseTime + ExtraTime) && (Sdepth > MINDEPTH))
147 time0 = current_time;
152 # ifdef QUIETBACKGROUND
154 # endif /* QUIETBACKGROUND */
162 ElapsedTime_NOFIONREAD(ElapsedTime_mode iop)
167 gettimeofday(&tv, NULL);
168 current_time = tv.tv_sec*100 + (tv.tv_usec/10000);
170 # ifdef INTERRUPT_TEST
171 if (iop == INIT_INTERRUPT_MODE)
173 itime0 = current_time;
175 else if (iop == COMPUTE_INTERRUPT_MODE)
177 it = current_time - itime0;
182 et = current_time - time0;
183 ETnodes = NodeCnt + znodes;
187 # ifdef INTERRUPT_TEST
188 printf("elapsed time %ld not positive\n", et);
193 if (iop == COMPUTE_AND_INIT_MODE)
195 if ((et > ResponseTime + ExtraTime) && (Sdepth > MINDEPTH))
198 time0 = current_time;
203 # ifdef QUIETBACKGROUND
205 # endif /* QUIETBACKGROUND */
212 #else /* !HAVE_GETTIMEOFDAY */
216 * Determine the time that has passed since the search was started. If the
217 * elapsed time exceeds the target (ResponseTime + ExtraTime) then set
218 * timeout to true which will terminate the search.
220 * iop = 0 calculate et, bump ETnodes
221 * iop = 1 calculate et, set timeout if time exceeded, calculate et
226 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 */