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 /* 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)
99 if ((i = ioctl((int) 0, FIONREAD, &nchar)))
103 "You probably have a non-ANSI <ioctl.h>; "
104 "see README. %d %d %x\n",
114 flag.bothsides = false;
117 gettimeofday(&tv, NULL);
118 current_time = tv.tv_sec*100 + (tv.tv_usec/10000);
120 # ifdef INTERRUPT_TEST
121 if (iop == INIT_INTERRUPT_MODE)
123 itime0 = current_time;
125 else if (iop == COMPUTE_INTERRUPT_MODE)
127 it = current_time - itime0;
132 et = current_time - time0;
133 ETnodes = NodeCnt + znodes;
137 # ifdef INTERRUPT_TEST
138 printf("elapsed time %ld not positive\n", et);
143 if (iop == COMPUTE_AND_INIT_MODE)
145 if ((et > ResponseTime + ExtraTime) && (Sdepth > MINDEPTH))
148 time0 = current_time;
153 # ifdef QUIETBACKGROUND
155 # endif /* QUIETBACKGROUND */
163 ElapsedTime_NOFIONREAD(ElapsedTime_mode iop)
168 gettimeofday(&tv, NULL);
169 current_time = tv.tv_sec*100 + (tv.tv_usec/10000);
171 # ifdef INTERRUPT_TEST
172 if (iop == INIT_INTERRUPT_MODE)
174 itime0 = current_time;
176 else if (iop == COMPUTE_INTERRUPT_MODE)
178 it = current_time - itime0;
183 et = current_time - time0;
184 ETnodes = NodeCnt + znodes;
188 # ifdef INTERRUPT_TEST
189 printf("elapsed time %ld not positive\n", et);
194 if (iop == COMPUTE_AND_INIT_MODE)
196 if ((et > ResponseTime + ExtraTime) && (Sdepth > MINDEPTH))
199 time0 = current_time;
204 # ifdef QUIETBACKGROUND
206 # endif /* QUIETBACKGROUND */
213 #else /* !HAVE_GETTIMEOFDAY */
217 * Determine the time that has passed since the search was started. If the
218 * elapsed time exceeds the target (ResponseTime + ExtraTime) then set
219 * timeout to true which will terminate the search.
221 * iop = 0 calculate et, bump ETnodes
222 * iop = 1 calculate et, set timeout if time exceeded, calculate et
227 ElapsedTime_FIONREAD(ElapsedTime_mode iop)
236 if ((i = ioctl((int) 0, FIONREAD, &nchar)))
240 "You probably have a non-ANSI <ioctl.h>; "
241 "see README. %d %d %x\n",
250 flag.bothsides = false;
253 et = ((current_time = time((long *) 0)) - time0) * 100;
255 #ifdef INTERRUPT_TEST
256 if (iop == INIT_INTERRUPT_MODE)
258 itime0 = current_time;
260 else if (iop == COMPUTE_INTERRUPT_MODE)
262 it = current_time - itime0;
267 ETnodes = NodeCnt + znodes;
271 #ifdef INTERRUPT_TEST
272 printf("elapsed time %ld not positive\n", et);
277 if (iop == COMPUTE_AND_INIT_MODE)
279 if ((et > (ResponseTime + ExtraTime)) && (Sdepth > MINDEPTH))
282 time0 = current_time;
287 #ifdef QUIETBACKGROUND
289 #endif /* QUIETBACKGROUND */
298 ElapsedTime_NOFIONREAD(ElapsedTime_mode iop)
302 et = ((current_time = time((long *) 0)) - time0) * 100;
304 #ifdef INTERRUPT_TEST
305 if (iop == INIT_INTERRUPT_MODE)
307 itime0 = current_time;
309 else if (iop == COMPUTE_INTERRUPT_MODE)
311 it = current_time - itime0;
316 ETnodes = NodeCnt + znodes;
320 #ifdef INTERRUPT_TEST
321 printf("elapsed time %ld not positive\n", et);
326 if (iop == COMPUTE_AND_INIT_MODE)
328 if ((et > (ResponseTime + ExtraTime)) && (Sdepth > MINDEPTH))
331 time0 = current_time;
336 #ifdef QUIETBACKGROUND
338 #endif /* QUIETBACKGROUND */
345 #endif /* HAVE_GETTIMEOFDAY */