Skip to content

Commit 77d267d

Browse files
committed
More miscellaneous code cleanup / modernization.
- Change include hierarchy, using more dedicated forward declaration headers. - Make use of C++11 standard library for threads and timing. - Start work on tearing down `TraceThreadData`. - Some odds and ends.
1 parent 55c0488 commit 77d267d

File tree

172 files changed

+1433
-1099
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

172 files changed

+1433
-1099
lines changed

.travis.yml

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ addons:
2424
packages:
2525
- libboost-dev
2626
- libboost-date-time-dev
27-
- libboost-thread-dev
2827
- libjpeg8-dev
2928
- libopenexr-dev
3029
- libpng12-dev

changes.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ Reported by Coverity static code analysis:
155155

156156
Miscellaneous:
157157

158-
- Fix `interior_texture` for text objects (as mentioned in GitHub issue #65)
158+
- Fix `interior_texture` for text objects (as mentioned in GitHub issue #65).
159159
- Eliminated use of deprecated C++ `register` keyword (except in 3rd party
160160
libraries bundled with the POV-Ray source code).
161161
- Fix long-standing bug in Julia fractal primitive using hypercomplex numbers.
@@ -195,6 +195,7 @@ Other Noteworthy
195195
- The `./configure` script can now be run without the `COMPILED_BY=...`
196196
option. In this case it defaults to `$USER <no contact address>`, where
197197
`$USER` is your login name.
198+
- The `boost_thread` and `boost_system` libraries are no longer required.
198199

199200

200201
Changes between 3.7.1-beta.9 and 3.7.1-rc.1

platform/unix/syspovtimer.cpp

+56-17
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
#include "syspovtimer.h"
3838

39+
#include <cerrno>
3940
#include <ctime>
4041

4142
#ifdef HAVE_UNISTD_H
@@ -69,24 +70,47 @@ namespace pov_base
6970

7071
//******************************************************************************
7172

72-
#if !POV_USE_DEFAULT_DELAY
73+
#if (POV_USE_PLATFORM_DELAY == 1)
7374

75+
// NOTE: Even if we decide to discontinue the use of this implementation,
76+
// we may want to keep it around in case it may turn out to be superior on some
77+
// exotic systems.
7478
void Delay(unsigned int msec)
7579
{
76-
#if defined(HAVE_NANOSLEEP)
77-
timespec ts;
80+
timespec ts, remain;
7881
ts.tv_sec = msec / 1000;
7982
ts.tv_nsec = (POV_ULONG) (1000000) * (msec % 1000);
80-
nanosleep(&ts, nullptr);
81-
#elif defined(HAVE_USLEEP)
82-
POV_ASSERT(msec < 1000); // On some systems, usleep() does not support sleeping for 1 second or more.
83-
usleep (msec * (useconds_t)1000);
84-
#else
85-
#error "Bad compile-time configuration."
86-
#endif
83+
errno = 0;
84+
while ((nanosleep(&ts, &remain) != 0) && (errno == EINTR))
85+
{
86+
ts = remain;
87+
errno = 0;
88+
}
89+
}
90+
91+
#elif (POV_USE_PLATFORM_DELAY == 2)
92+
93+
// ATTENTION: According to the POSIX standard, `usleep()` need not be
94+
// thread-safe!
95+
96+
// NOTE: Although we're currently not using this implementation, we may want to
97+
// keep it around in case we find the default implementation wanting on some
98+
// systems.
99+
void Delay(unsigned int msec)
100+
{
101+
// According to the POSIX standard, `usleep()` may not support parameter
102+
// values of 1 million or higher (corresponding to 1s). We work around this
103+
// by simply calling `usleep()` repeatedly until we're good.
104+
for (unsigned int sec = 0; sec < (msec/1000); ++sec)
105+
usleep((useconds_t)999999); // not exactly 1s, but close enough.
106+
usleep ((msec % 1000) * (useconds_t)1000);
87107
}
88108

89-
#endif // !POV_USE_DEFAULT_DELAY
109+
#else // POV_USE_PLATFORM_DELAY
110+
111+
#error "Bad compile-time configuration."
112+
113+
#endif // POV_USE_PLATFORM_DELAY
90114

91115
//******************************************************************************
92116

@@ -138,9 +162,11 @@ static inline bool GettimeofdayMillisec(POV_ULONG& result)
138162
}
139163

140164
Timer::Timer () :
165+
#if !POVUNIX_USE_DEFAULT_REAL_TIMER
141166
mWallTimeUseClockGettimeMonotonic (false),
142167
mWallTimeUseClockGettimeRealtime (false),
143168
mWallTimeUseGettimeofday (false),
169+
#endif
144170
mProcessTimeUseGetrusageSelf (false),
145171
mProcessTimeUseClockGettimeProcess (false),
146172
mProcessTimeUseFallback (false),
@@ -149,6 +175,7 @@ Timer::Timer () :
149175
mThreadTimeUseClockGettimeThread (false),
150176
mThreadTimeUseFallback (false)
151177
{
178+
#if !POVUNIX_USE_DEFAULT_REAL_TIMER
152179
// Figure out which timer source to use for wall clock time.
153180
bool haveWallTime = false;
154181
#if defined(HAVE_DECL_CLOCK_MONOTONIC) && HAVE_DECL_CLOCK_MONOTONIC
@@ -165,12 +192,13 @@ Timer::Timer () :
165192
// gettimeofday(), and document it here.
166193
if (!haveWallTime)
167194
haveWallTime = mWallTimeUseGettimeofday = GettimeofdayMillisec(mWallTimeStart);
168-
// FIXME: add fallback, using ftime(), or time() + a counter for ms, or maybe boost::date_time
195+
// FIXME: add fallback, using ftime(), or time() + a counter for ms, or maybe std::chrono
169196
if (!haveWallTime)
170197
{
171198
POV_ASSERT(false);
172199
mWallTimeStart = 0;
173200
}
201+
#endif
174202

175203
// Figure out which timer source to use for per-process CPU time.
176204
bool haveProcessTime = false;
@@ -186,8 +214,12 @@ Timer::Timer () :
186214
#endif
187215
if (!haveProcessTime)
188216
{
217+
#if POVUNIX_USE_DEFAULT_REAL_TIMER
218+
haveProcessTime = mProcessTimeUseFallback = true;
219+
#else
189220
haveProcessTime = mProcessTimeUseFallback = haveWallTime;
190221
mProcessTimeStart = mWallTimeStart;
222+
#endif
191223
}
192224

193225
// Figure out which timer source to use for per-thread CPU time.
@@ -212,11 +244,7 @@ Timer::Timer () :
212244
}
213245
}
214246

215-
Timer::~Timer ()
216-
{
217-
// nothing to do
218-
}
219-
247+
#if !POVUNIX_USE_DEFAULT_REAL_TIMER
220248
POV_ULONG Timer::GetWallTime () const
221249
{
222250
POV_ULONG result;
@@ -232,6 +260,7 @@ POV_ULONG Timer::GetWallTime () const
232260
return (GettimeofdayMillisec(result) ? result : 0);
233261
return 0;
234262
}
263+
#endif
235264

236265
POV_ULONG Timer::GetProcessTime () const
237266
{
@@ -245,7 +274,11 @@ POV_ULONG Timer::GetProcessTime () const
245274
return (ClockGettimeMillisec(result, CLOCK_PROCESS_CPUTIME_ID) ? result : 0);
246275
#endif
247276
if (mProcessTimeUseFallback)
277+
#if POVUNIX_USE_DEFAULT_REAL_TIMER
278+
return mRealTimer.ElapsedTime();
279+
#else
248280
return GetWallTime ();
281+
#endif
249282
return 0;
250283
}
251284

@@ -269,10 +302,12 @@ POV_ULONG Timer::GetThreadTime () const
269302
return 0;
270303
}
271304

305+
#if !POVUNIX_USE_DEFAULT_REAL_TIMER
272306
POV_LONG Timer::ElapsedRealTime () const
273307
{
274308
return GetWallTime () - mWallTimeStart;
275309
}
310+
#endif
276311

277312
POV_LONG Timer::ElapsedProcessCPUTime () const
278313
{
@@ -286,7 +321,11 @@ POV_LONG Timer::ElapsedThreadCPUTime () const
286321

287322
void Timer::Reset ()
288323
{
324+
#if POVUNIX_USE_DEFAULT_REAL_TIMER
325+
mRealTimer.Reset();
326+
#else
289327
mWallTimeStart = GetWallTime ();
328+
#endif
290329
mProcessTimeStart = GetProcessTime ();
291330
mThreadTimeStart = GetThreadTime ();
292331
}

platform/unix/syspovtimer.h

+21-7
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,19 @@
3939

4040
#include "base/configbase.h"
4141

42+
#include "base/timer.h"
43+
4244
namespace pov_base
4345
{
4446

45-
#if !POV_USE_DEFAULT_DELAY
46-
47-
void Delay(unsigned int msec);
48-
49-
#endif // !POV_USE_DEFAULT_DELAY
47+
#if !POV_USE_DEFAULT_TIMER
5048

49+
// NOTE: Although we're currently not using platform-specific implementations
50+
// of the wall clock timer, we may want to keep them around in case we find the
51+
// default implementation wanting on particular flavours of Unix.
52+
#define POVUNIX_USE_DEFAULT_REAL_TIMER 1
5153

52-
#if !POV_USE_DEFAULT_TIMER
54+
class DefaultRealTimer;
5355

5456
/// Millisecond-precision timer.
5557
///
@@ -67,9 +69,13 @@ class Timer final
6769
public:
6870

6971
Timer();
70-
~Timer();
72+
~Timer() = default;
7173

74+
#if POVUNIX_USE_DEFAULT_REAL_TIMER
75+
inline POV_LONG ElapsedRealTime() const { return mRealTimer.ElapsedTime(); }
76+
#else
7277
POV_LONG ElapsedRealTime() const;
78+
#endif
7379
POV_LONG ElapsedProcessCPUTime() const;
7480
POV_LONG ElapsedThreadCPUTime() const;
7581

@@ -80,13 +86,19 @@ class Timer final
8086

8187
private:
8288

89+
#if POVUNIX_USE_DEFAULT_REAL_TIMER
90+
DefaultRealTimer mRealTimer;
91+
#else
8392
POV_ULONG mWallTimeStart;
93+
#endif
8494
POV_ULONG mProcessTimeStart;
8595
POV_ULONG mThreadTimeStart;
8696

97+
#if !POVUNIX_USE_DEFAULT_REAL_TIMER
8798
bool mWallTimeUseClockGettimeMonotonic : 1; ///< Whether we'll measure elapsed wall-clock time using `clock_gettime(CLOCK_MONOTONIC)`.
8899
bool mWallTimeUseClockGettimeRealtime : 1; ///< Whether we'll measure elapsed wall-clock time using `clock_gettime(CLOCK_REALTIME)`.
89100
bool mWallTimeUseGettimeofday : 1; ///< Whether we'll measure elapsed wall-clock time using `gettimeofday()`.
101+
#endif
90102

91103
bool mProcessTimeUseGetrusageSelf : 1; ///< Whether we'll measure per-process CPU time using `getrusage(RUSAGE_SELF)`.
92104
bool mProcessTimeUseClockGettimeProcess : 1; ///< Whether we'll measure per-process CPU time using `clock_gettime(CLOCK_PROCESS_CPUTIME_ID)`.
@@ -97,7 +109,9 @@ class Timer final
97109
bool mThreadTimeUseClockGettimeThread : 1; ///< Whether we'll measure per-thread CPU time `clock_gettime(CLOCK_THREAD_CPUTIME_ID)`.
98110
bool mThreadTimeUseFallback : 1; ///< Whether we'll fall back to per-process CPU time (or wall-clock time) instead of per-thread CPU time.
99111

112+
#if !POVUNIX_USE_DEFAULT_REAL_TIMER
100113
POV_ULONG GetWallTime() const;
114+
#endif
101115
POV_ULONG GetThreadTime() const;
102116
POV_ULONG GetProcessTime() const;
103117
};

platform/windows/syspovtimer.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,22 @@ namespace pov_base
5353

5454
//******************************************************************************
5555

56+
#if POV_USE_PLATFORM_DELAY
57+
58+
// NOTE: Although we're currently not using this implementation, we may want to
59+
// keep it around in case we find the default implementation wanting on Windows
60+
// systems in general or some flavours in particular.
5661
void Delay(unsigned int msec)
5762
{
5863
Sleep (msec);
5964
}
6065

66+
#endif // POV_USE_PLATFORM_DELAY
67+
6168
//******************************************************************************
6269

70+
#if !POV_USE_DEFAULT_TIMER
71+
6372
Timer::Timer () :
6473
// TODO - sources on the internet indicate that GetThreadTimes() and GetProcessTimes() have been
6574
// around as early as NT 3.1. Is there a reason we're only making use of it in NT 4.0 and
@@ -175,5 +184,9 @@ bool Timer::HasValidProcessCPUTime () const
175184
return mCPUTimeSupported;
176185
}
177186

187+
#endif // POV_USE_DEFAULT_TIMER
188+
189+
//******************************************************************************
190+
178191
}
179192
// end of namespace pov_base

platform/windows/syspovtimer.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
namespace pov_base
4343
{
4444

45-
void Delay(unsigned int msec);
45+
#if !POV_USE_DEFAULT_TIMER
4646

4747
class Timer final
4848
{
@@ -72,6 +72,8 @@ class Timer final
7272
POV_ULONG GetProcessTime () const;
7373
};
7474

75+
#endif // POV_USE_DEFAULT_TIMER
76+
7577
}
7678
// end of namespace pov_base
7779

platform/x86/avx/avxnoise.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ static inline __m256d permute4x64_functional(const __m256d& x, int i)
7979
const int idx1 = ((i >> 2) & 0x3);
8080
const int idx2 = ((i >> 4) & 0x3);
8181
const int idx3 = ((i >> 6) & 0x3);
82-
ALIGN32 double p[4];
82+
alignas(32) double p[4];
8383
_mm256_store_pd(p,x);
8484

8585
if (idx0 == idx1 && idx1 == idx2 && idx2 == idx3)
@@ -134,7 +134,7 @@ static inline __m256d permute4x64_functional(const __m256d& x, int i)
134134

135135
extern DBL RTable[];
136136

137-
ALIGN32 static AVXTABLETYPE AVXRTable[267];
137+
alignas(32) static AVXTABLETYPE AVXRTable[267];
138138

139139
void AVXNoiseInit()
140140
{

platform/x86/avx2fma3/avx2fma3noise.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ const bool kAVX2FMA3NoiseEnabled = true;
121121

122122
extern DBL RTable[];
123123

124-
ALIGN32 static AVX2TABLETYPE AVX2RTable[267];
124+
alignas(32) static AVX2TABLETYPE AVX2RTable[267];
125125

126126
void AVX2FMA3NoiseInit()
127127
{

source-doc/styleguide.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ POV-Ray is being developed with portability high in mind. In practice and at pre
5353
- While POV-Ray does require boost, we want to keep dependency on it to a minimum. The following are currently
5454
considered fair game:
5555
- Flyweights.
56-
- Threads.
5756
- DateTime **except** features that may require linking with the lib (mostly conversions to/from string).
5857
- SmartPtr intrusive pointers.
5958
.
@@ -171,6 +170,8 @@ Parameter and variable names might carry one or more additional prefixes. These
171170
.
172171
- Protected or private member variable names should begin with a (possibly additional) `m` prefix.
173172
- Global variable names should begin with a (possibly additional) `g` prefix.
173+
- Global variables with thread-local storage should begin with a (possibly additional) `gt`
174+
- prefix.
174175
- Constants should begin with a `k` prefix. (Does not apply to const parameters.)
175176
.
176177

source/backend/bounding/boundingtask.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545

4646
// Boost header files
4747
#include <boost/bind.hpp>
48-
#include <boost/thread.hpp>
4948

5049
// POV-Ray header files (base module)
5150
// (none at the moment)

0 commit comments

Comments
 (0)