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)
96 if ((i = ioctl((int) 0, FIONREAD, &nchar)))
100 "You probably have a non-ANSI <ioctl.h>; "
101 "see README. %d %d %x\n",
111 flag.bothsides = false;
114 gettimeofday(&tv, NULL);
115 current_time = tv.tv_sec*100 + (tv.tv_usec/10000);
117 # ifdef INTERRUPT_TEST
118 if (iop == INIT_INTERRUPT_MODE)
120 itime0 = current_time;
122 else if (iop == COMPUTE_INTERRUPT_MODE)
124 it = current_time - itime0;
129 et = current_time - time0;
130 ETnodes = NodeCnt + znodes;
134 # ifdef INTERRUPT_TEST
135 printf("elapsed time %ld not positive\n", et);
140 if (iop == COMPUTE_AND_INIT_MODE)
142 if ((et > ResponseTime + ExtraTime) && (Sdepth > MINDEPTH))
145 time0 = current_time;
150 # ifdef QUIETBACKGROUND
152 # endif /* QUIETBACKGROUND */
160 ElapsedTime_NOFIONREAD(ElapsedTime_mode iop)
165 gettimeofday(&tv, NULL);
166 current_time = tv.tv_sec*100 + (tv.tv_usec/10000);
168 # ifdef INTERRUPT_TEST
169 if (iop == INIT_INTERRUPT_MODE)
171 itime0 = current_time;
173 else if (iop == COMPUTE_INTERRUPT_MODE)
175 it = current_time - itime0;
180 et = current_time - time0;
181 ETnodes = NodeCnt + znodes;
185 # ifdef INTERRUPT_TEST
186 printf("elapsed time %ld not positive\n", et);
191 if (iop == COMPUTE_AND_INIT_MODE)
193 if ((et > ResponseTime + ExtraTime) && (Sdepth > MINDEPTH))
196 time0 = current_time;
201 # ifdef QUIETBACKGROUND
203 # endif /* QUIETBACKGROUND */
210 #else /* !HAVE_GETTIMEOFDAY */
214 * Determine the time that has passed since the search was started. If the
215 * elapsed time exceeds the target (ResponseTime + ExtraTime) then set
216 * timeout to true which will terminate the search.
218 * iop = 0 calculate et, bump ETnodes
219 * iop = 1 calculate et, set timeout if time exceeded, calculate et
224 ElapsedTime_FIONREAD(ElapsedTime_mode iop)
233 if ((i = ioctl((int) 0, FIONREAD, &nchar)))
237 "You probably have a non-ANSI <ioctl.h>; "
238 "see README. %d %d %x\n",
247 flag.bothsides = false;
250 et = ((current_time = time((long *) 0)) - time0) * 100;
252 #ifdef INTERRUPT_TEST
253 if (iop == INIT_INTERRUPT_MODE)
255 itime0 = current_time;
257 else if (iop == COMPUTE_INTERRUPT_MODE)
259 it = current_time - itime0;
264 ETnodes = NodeCnt + znodes;
268 #ifdef INTERRUPT_TEST
269 printf("elapsed time %ld not positive\n", et);
274 if (iop == COMPUTE_AND_INIT_MODE)
276 if ((et > (ResponseTime + ExtraTime)) && (Sdepth > MINDEPTH))
279 time0 = current_time;
284 #ifdef QUIETBACKGROUND
286 #endif /* QUIETBACKGROUND */
295 ElapsedTime_NOFIONREAD(ElapsedTime_mode iop)
299 et = ((current_time = time((long *) 0)) - time0) * 100;
301 #ifdef INTERRUPT_TEST
302 if (iop == INIT_INTERRUPT_MODE)
304 itime0 = current_time;
306 else if (iop == COMPUTE_INTERRUPT_MODE)
308 it = current_time - itime0;
313 ETnodes = NodeCnt + znodes;
317 #ifdef INTERRUPT_TEST
318 printf("elapsed time %ld not positive\n", et);
323 if (iop == COMPUTE_AND_INIT_MODE)
325 if ((et > (ResponseTime + ExtraTime)) && (Sdepth > MINDEPTH))
328 time0 = current_time;
333 #ifdef QUIETBACKGROUND
335 #endif /* QUIETBACKGROUND */
342 #endif /* HAVE_GETTIMEOFDAY */