4 * System-dependent functions for GNU Shogi.
6 * ----------------------------------------------------------------------
8 * Copyright (c) 2012 Free Software Foundation
10 * GNU SHOGI is based on GNU CHESS
12 * This file is part of GNU SHOGI.
14 * GNU Shogi is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License as published by the
16 * Free Software Foundation; either version 3 of the License,
17 * or (at your option) any later version.
19 * GNU Shogi is distributed in the hope that it will be useful, but WITHOUT
20 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24 * You should have received a copy of the GNU General Public License along
25 * with GNU Shogi; see the file COPYING. If not, see
26 * <http://www.gnu.org/licenses/>.
27 * ----------------------------------------------------------------------
38 /* Definition of FIONREAD */
39 #include <sys/filio.h>
43 /* Definition of errno(). */
47 /* Forward declarations. */
49 void ElapsedTime_NOFIONREAD(ElapsedTime_mode iop);
50 void ElapsedTime_FIONREAD(ElapsedTime_mode iop);
54 * Determine the time that has passed since the search was started. If the
55 * elapsed time exceeds the target(ResponseTime + ExtraTime) then set timeout
56 * to true which will terminate the search.
57 * iop = COMPUTE_MODE calculate et, bump ETnodes
58 * iop = COMPUTE_AND_INIT_MODE calculate et, set timeout if time exceeded,
63 * ElapsedTime() is actually a wrapper function around the different
64 * versions of ElapsedTime_XXX(). This allows us to compile all the
65 * different ways of measuring time in one executable.
69 ElapsedTime(ElapsedTime_mode iop)
74 ElapsedTime_NOFIONREAD(iop);
78 ElapsedTime_FIONREAD(iop);
85 #ifdef HAVE_GETTIMEOFDAY
87 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)
229 if ((i = ioctl((int) 0, FIONREAD, &nchar)))
233 "You probably have a non-ANSI <ioctl.h>; "
234 "see README. %d %d %x\n",
243 flag.bothsides = false;
246 et = ((current_time = time((long *) 0)) - time0) * 100;
248 #ifdef INTERRUPT_TEST
249 if (iop == INIT_INTERRUPT_MODE)
251 itime0 = current_time;
253 else if (iop == COMPUTE_INTERRUPT_MODE)
255 it = current_time - itime0;
260 ETnodes = NodeCnt + znodes;
264 #ifdef INTERRUPT_TEST
265 printf("elapsed time %ld not positive\n", et);
270 if (iop == COMPUTE_AND_INIT_MODE)
272 if ((et > (ResponseTime + ExtraTime)) && (Sdepth > MINDEPTH))
275 time0 = current_time;
280 #ifdef QUIETBACKGROUND
282 #endif /* QUIETBACKGROUND */
291 ElapsedTime_NOFIONREAD(ElapsedTime_mode iop)
295 et = ((current_time = time((long *) 0)) - time0) * 100;
297 #ifdef INTERRUPT_TEST
298 if (iop == INIT_INTERRUPT_MODE)
300 itime0 = current_time;
302 else if (iop == COMPUTE_INTERRUPT_MODE)
304 it = current_time - itime0;
309 ETnodes = NodeCnt + znodes;
313 #ifdef INTERRUPT_TEST
314 printf("elapsed time %ld not positive\n", et);
319 if (iop == COMPUTE_AND_INIT_MODE)
321 if ((et > (ResponseTime + ExtraTime)) && (Sdepth > MINDEPTH))
324 time0 = current_time;
329 #ifdef QUIETBACKGROUND
331 #endif /* QUIETBACKGROUND */
338 #endif /* HAVE_GETTIMEOFDAY */