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 ElapsedTime_FIONREAD(ElapsedTime_mode iop)
94 #ifdef HAVE_GETTIMEOFDAY
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 #ifdef HAVE_GETTIMEOFDAY
117 gettimeofday(&tv, NULL);
118 current_time = tv.tv_sec*100 + (tv.tv_usec/10000);
120 et = ((current_time = time((long *) 0)) - time0) * 100;
123 #ifdef INTERRUPT_TEST
124 if (iop == INIT_INTERRUPT_MODE)
126 itime0 = current_time;
128 else if (iop == COMPUTE_INTERRUPT_MODE)
130 it = current_time - itime0;
135 #ifdef HAVE_GETTIMEOFDAY
136 et = current_time - time0;
138 ETnodes = NodeCnt + znodes;
142 #ifdef INTERRUPT_TEST
143 printf("elapsed time %ld not positive\n", et);
148 if (iop == COMPUTE_AND_INIT_MODE)
150 if ((et > (ResponseTime + ExtraTime)) && (Sdepth > MINDEPTH))
153 time0 = current_time;
158 #ifdef QUIETBACKGROUND
168 ElapsedTime_NOFIONREAD(ElapsedTime_mode iop)
171 #ifdef HAVE_GETTIMEOFDAY
173 gettimeofday(&tv, NULL);
174 current_time = tv.tv_sec*100 + (tv.tv_usec/10000);
176 et = ((current_time = time((long *) 0)) - time0) * 100;
179 #ifdef INTERRUPT_TEST
180 if (iop == INIT_INTERRUPT_MODE)
182 itime0 = current_time;
184 else if (iop == COMPUTE_INTERRUPT_MODE)
186 it = current_time - itime0;
191 #ifdef HAVE_GETTIMEOFDAY
192 et = current_time - time0;
194 ETnodes = NodeCnt + znodes;
198 #ifdef INTERRUPT_TEST
199 printf("elapsed time %ld not positive\n", et);
204 if (iop == COMPUTE_AND_INIT_MODE)
206 if ((et > (ResponseTime + ExtraTime)) && (Sdepth > MINDEPTH))
209 time0 = current_time;
214 #ifdef QUIETBACKGROUND