Skip to content

Commit e4ce574

Browse files
committed
This should fix the Unix build at last.
1 parent e921ef4 commit e4ce574

File tree

5 files changed

+47
-36
lines changed

5 files changed

+47
-36
lines changed

platform/unix/syspovtimer.cpp

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@
4949
#include <sys/time.h>
5050
#endif
5151

52+
#include "base/types.h"
53+
54+
// this must be the last file included
55+
#include "base/povdebug.h"
56+
5257
#if !defined(HAVE_CLOCKID_T)
5358
typedef int clockid_t;
5459
#endif
@@ -104,11 +109,11 @@ static inline bool ClockGettimeMillisec(POV_ULONG& result, clockid_t source)
104109
static inline bool GetrusageMillisec(POV_ULONG& result, int source)
105110
{
106111
#if defined(HAVE_GETRUSAGE)
107-
bool success;
108-
success = (getrusage(source, &ru) == 0);
112+
struct rusage ru;
113+
bool success = (getrusage(source, &ru) == 0);
109114
if (success)
110-
result = static_cast<POV_ULONG>(ru.ru_utime.tv_sec) + static_cast<POV_ULONG>(ru.ru_stime.tv_sec)) *1000
111-
+ static_cast<POV_ULONG>(ru.ru_utime.tv_usec) + static_cast<POV_ULONG>(ru.ru_stime.tv_usec)) /1000;
115+
result = (static_cast<POV_ULONG>(ru.ru_utime.tv_sec) + static_cast<POV_ULONG>(ru.ru_stime.tv_sec)) *1000
116+
+ (static_cast<POV_ULONG>(ru.ru_utime.tv_usec) + static_cast<POV_ULONG>(ru.ru_stime.tv_usec)) /1000;
112117
return success;
113118
#else
114119
return false;
@@ -131,7 +136,6 @@ static inline bool GettimeofdayMillisec(POV_ULONG& result)
131136
}
132137

133138
Timer::Timer () :
134-
mThreadTimeOnly (CPUTimeIsThreadOnly),
135139
mWallTimeUseClockGettimeMonotonic (false),
136140
mWallTimeUseClockGettimeRealtime (false),
137141
mWallTimeUseGettimeofday (false),
@@ -141,17 +145,17 @@ Timer::Timer () :
141145
mThreadTimeUseGetrusageThread (false),
142146
mThreadTimeUseGetrusageLwp (false),
143147
mThreadTimeUseClockGettimeThread (false),
144-
mThreadTimeUseFallback (false),
148+
mThreadTimeUseFallback (false)
145149
{
146150
// Figure out which timer source to use for wall clock time.
147151
bool haveWallTime = false;
148-
#if defined(HAVE_CLOCK_MONOTONIC)
152+
#if defined(HAVE_DECL_CLOCK_MONOTONIC) && HAVE_DECL_CLOCK_MONOTONIC
149153
if (!haveWallTime)
150154
haveWallTime = mWallTimeUseClockGettimeMonotonic = ClockGettimeMillisec(mWallTimeStart, CLOCK_MONOTONIC);
151155
#endif
152156
// we prefer CLOCK_MONOTONIC over CLOCK_REALTIME because the former will not be affected if someone adjusts the
153157
// system's real-time clock.
154-
#if defined(HAVE_CLOCK_REALTIME)
158+
#if defined(HAVE_DECL_CLOCK_REALTIME) && HAVE_DECL_CLOCK_REALTIME
155159
if (!haveWallTime)
156160
haveWallTime = mWallTimeUseClockGettimeRealtime = ClockGettimeMillisec(mWallTimeStart, CLOCK_REALTIME);
157161
#endif
@@ -168,15 +172,15 @@ Timer::Timer () :
168172

169173
// Figure out which timer source to use for per-process CPU time.
170174
bool haveProcessTime = false;
171-
#if defined(HAVE_RUSAGE_SELF)
175+
#if defined(HAVE_DECL_RUSAGE_SELF) && HAVE_DECL_RUSAGE_SELF
172176
if (!haveProcessTime)
173177
haveProcessTime = mProcessTimeUseGetrusageSelf = GetrusageMillisec(mProcessTimeStart, RUSAGE_SELF);
174178
#endif
175179
// We prefer getrusage() over clock_gettime() because the latter may be inaccurate on systems
176180
// with multiple physical processors.
177-
#if defined(HAVE_CLOCK_PROCESS_CPUTIME_ID)
181+
#if defined(HAVE_DECL_CLOCK_PROCESS_CPUTIME_ID) && HAVE_DECL_CLOCK_PROCESS_CPUTIME_ID
178182
if (!haveProcessTime)
179-
haveProcessTime = mProcessTimeUseGettimeProcess = ClockGettimeMillisec(mProcessTimeStart, CLOCK_PROCESS_CPUTIME_ID);
183+
haveProcessTime = mProcessTimeUseClockGettimeProcess = ClockGettimeMillisec(mProcessTimeStart, CLOCK_PROCESS_CPUTIME_ID);
180184
#endif
181185
if (!haveProcessTime)
182186
{
@@ -186,20 +190,20 @@ Timer::Timer () :
186190

187191
// Figure out which timer source to use for per-thread CPU time.
188192
bool haveThreadTime = false;
189-
#if defined(HAVE_RUSAGE_THREAD)
193+
#if defined(HAVE_DECL_RUSAGE_THREAD) && HAVE_DECL_RUSAGE_THREAD
190194
if (!haveThreadTime)
191195
haveThreadTime = mThreadTimeUseGetrusageThread = GetrusageMillisec(mThreadTimeStart, RUSAGE_THREAD);
192-
#elif defined(HAVE_RUSAGE_LWP) // should be alias of RUSAGE_THREAD on systems that support both
196+
#elif defined(HAVE_DECL_RUSAGE_LWP) && HAVE_DECL_RUSAGE_LWP // should be alias of RUSAGE_THREAD on systems that support both
193197
if (!haveThreadTime)
194198
haveThreadTime = mThreadTimeUseGetrusageLwp = GetrusageMillisec(mThreadTimeStart, RUSAGE_LWP);
195199
#endif
196200
// We prefer getrusage() over clock_gettime() because the latter may be inaccurate on systems
197201
// with multiple physical processors.
198-
#if defined(HAVE_CLOCK_THREAD_CPUTIME_ID)
202+
#if defined(HAVE_DECL_CLOCK_THREAD_CPUTIME_ID) && HAVE_DECL_CLOCK_THREAD_CPUTIME_ID
199203
if (!haveThreadTime)
200-
haveThreadTime = mThreadTimeUseGettimeThread = ClockGettimeMillisec(mThreadTimeStart, CLOCK_THREAD_CPUTIME_ID);
204+
haveThreadTime = mThreadTimeUseClockGettimeThread = ClockGettimeMillisec(mThreadTimeStart, CLOCK_THREAD_CPUTIME_ID);
201205
#endif
202-
if (!haveProcessTime)
206+
if (!haveThreadTime)
203207
{
204208
haveThreadTime = mThreadTimeUseFallback = haveProcessTime;
205209
mThreadTimeStart = mProcessTimeStart;
@@ -214,11 +218,11 @@ Timer::~Timer ()
214218
POV_ULONG Timer::GetWallTime () const
215219
{
216220
POV_ULONG result;
217-
#if defined(HAVE_CLOCK_MONOTONIC)
221+
#if defined(HAVE_DECL_CLOCK_MONOTONIC) && HAVE_DECL_CLOCK_MONOTONIC
218222
if (mWallTimeUseClockGettimeMonotonic)
219223
return (ClockGettimeMillisec(result, CLOCK_MONOTONIC) ? result : 0);
220224
#endif
221-
#if defined(HAVE_CLOCK_REALTIME)
225+
#if defined(HAVE_DECL_CLOCK_REALTIME) && HAVE_DECL_CLOCK_REALTIME
222226
if (mWallTimeUseClockGettimeRealtime)
223227
return (ClockGettimeMillisec(result, CLOCK_REALTIME) ? result : 0);
224228
#endif
@@ -227,34 +231,34 @@ POV_ULONG Timer::GetWallTime () const
227231
return 0;
228232
}
229233

230-
POV_ULONG Timer::GetProcessCPUTime () const
234+
POV_ULONG Timer::GetProcessTime () const
231235
{
232236
POV_ULONG result;
233-
#if defined(HAVE_RUSAGE_SELF)
237+
#if defined(HAVE_DECL_RUSAGE_SELF) && HAVE_DECL_RUSAGE_SELF
234238
if (mProcessTimeUseGetrusageSelf)
235239
return (GetrusageMillisec(result, RUSAGE_SELF) ? result : 0);
236240
#endif
237-
#if defined(HAVE_CLOCK_PROCESS_CPUTIME_ID)
238-
if (mProcessTimeUseGettimeProcess)
241+
#if defined(HAVE_DECL_CLOCK_PROCESS_CPUTIME_ID) && HAVE_DECL_CLOCK_PROCESS_CPUTIME_ID
242+
if (mProcessTimeUseClockGettimeProcess)
239243
return (ClockGettimeMillisec(result, CLOCK_PROCESS_CPUTIME_ID) ? result : 0);
240244
#endif
241245
if (mProcessTimeUseFallback)
242246
return GetWallTime ();
243247
return 0;
244248
}
245249

246-
POV_ULONG Timer::GetThreadCPUTime () const
250+
POV_ULONG Timer::GetThreadTime () const
247251
{
248252
POV_ULONG result;
249-
#if defined(HAVE_RUSAGE_THREAD)
253+
#if defined(HAVE_DECL_RUSAGE_THREAD) && HAVE_DECL_RUSAGE_THREAD
250254
if (mThreadTimeUseGetrusageThread)
251255
return (GetrusageMillisec(result, RUSAGE_THREAD) ? result : 0);
252256
#endif
253-
#if defined(HAVE_RUSAGE_LWP)
257+
#if defined(HAVE_DECL_RUSAGE_LWP) && HAVE_DECL_RUSAGE_LWP
254258
if (mThreadTimeUseGetrusageLwp)
255259
return (GetrusageMillisec(result, RUSAGE_LWP) ? result : 0);
256260
#endif
257-
#if defined(HAVE_CLOCK_THREAD_CPUTIME_ID)
261+
#if defined(HAVE_DECL_CLOCK_THREAD_CPUTIME_ID) && HAVE_DECL_CLOCK_THREAD_CPUTIME_ID
258262
if (mThreadTimeUseClockGettimeThread)
259263
return (ClockGettimeMillisec(result, CLOCK_THREAD_CPUTIME_ID) ? result : 0);
260264
#endif
@@ -281,8 +285,8 @@ POV_LONG Timer::ElapsedThreadCPUTime () const
281285
void Timer::Reset ()
282286
{
283287
mWallTimeStart = GetWallTime ();
284-
mProcessTimeStart = (mProcessTimeUseFallback ? mWallTimeStart : GetProcessTime ());
285-
mThreadTimeStart = (mThreadTimeUseFallback ? mProcessTimeStart : GetThreadTime ());
288+
mProcessTimeStart = GetProcessTime ();
289+
mThreadTimeStart = GetThreadTime ();
286290
}
287291

288292
bool Timer::HasValidProcessCPUTime () const

source/base/version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
#define OFFICIAL_VERSION_STRING "3.7.1"
4646
#define OFFICIAL_VERSION_NUMBER 371
4747

48-
#define POV_RAY_PRERELEASE "alpha.8772266"
48+
#define POV_RAY_PRERELEASE "alpha.8772877"
4949

5050
#if (POV_RAY_IS_AUTOBUILD == 1) && ((POV_RAY_IS_OFFICIAL == 1) || (POV_RAY_IS_SEMI_OFFICIAL == 1))
5151
#ifdef POV_RAY_PRERELEASE

unix/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.7.1-alpha.8772266
1+
3.7.1-alpha.8772877

unix/configure.ac

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -646,12 +646,16 @@ AC_CHECK_TYPES([useconds_t])
646646

647647
# clock_gettime and related <time.h>
648648
AC_CHECK_FUNCS([clock_gettime])
649-
AC_CHECK_DECLS([CLOCK_MONOTONIC, CLOCK_REALTIME, CLOCK_PROCESS_CPUTIME_ID, CLOCK_THREAD_CPUTIME_ID])
649+
AC_CHECK_DECLS([CLOCK_MONOTONIC, CLOCK_REALTIME, CLOCK_PROCESS_CPUTIME_ID, CLOCK_THREAD_CPUTIME_ID],
650+
[], [], [[#include <time.h>]]
651+
)
650652
AC_CHECK_TYPES([clockid_t])
651653

652654
# getrusage and related <sys/resource.h>
653655
AC_CHECK_FUNCS([getrusage])
654-
AC_CHECK_DECLS([RUSAGE_SELF, RUSAGE_THREAD, RUSAGE_LWP])
656+
AC_CHECK_DECLS([RUSAGE_SELF, RUSAGE_THREAD, RUSAGE_LWP]
657+
[], [], [[#include <sys/resource.h>]]
658+
)
655659

656660
# gettimeofday <sys/time.h>
657661
AC_CHECK_FUNCS([gettimeofday])
@@ -1219,8 +1223,8 @@ AC_CONFIG_FILES([\
12191223
Makefile \
12201224
source/Makefile \
12211225
vfe/Makefile \
1226+
platform/Makefile \
12221227
unix/Makefile \
1223-
platform/unix/Makefile \
12241228
])
12251229

12261230

unix/prebuild.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -441,10 +441,12 @@ AM_CPPFLAGS = \\
441441
442442
# Libraries to link with.
443443
# Beware: order does matter!
444+
# TODO - Having vfe/libvfe.a twice in this list is a bit of a hackish way to cope with cyclic dependencies.
444445
LDADD = \\
445-
\$(top_builddir)/platform/libplatform.a \\
446446
\$(top_builddir)/vfe/libvfe.a \\
447-
\$(top_builddir)/source/libpovray.a
447+
\$(top_builddir)/source/libpovray.a \\
448+
\$(top_builddir)/vfe/libvfe.a \\
449+
\$(top_builddir)/platform/libplatform.a
448450
pbEOF
449451
;;
450452
esac
@@ -576,7 +578,7 @@ povowner = @povowner@
576578
povgroup = @povgroup@
577579
578580
# Directories to build.
579-
SUBDIRS = source vfe unix platform
581+
SUBDIRS = source vfe platform unix
580582
581583
# Additional files to distribute.
582584
EXTRA_DIST = \\
@@ -1387,6 +1389,7 @@ libplatform_a_SOURCES = \\
13871389
AM_CPPFLAGS = \\
13881390
-I\$(top_srcdir)/unix/povconfig \\
13891391
-I\$(top_srcdir)/platform/unix \\
1392+
-I\$(top_srcdir)/vfe \\
13901393
-I\$(top_srcdir)/vfe/unix \\
13911394
-I\$(top_srcdir)/unix \\
13921395
-I\$(top_srcdir)/source

0 commit comments

Comments
 (0)