Skip to content

Commit

Permalink
More miscellaneous code cleanup / modernization.
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
c-lipka committed Feb 18, 2019
1 parent 55c0488 commit 77d267d
Show file tree
Hide file tree
Showing 172 changed files with 1,433 additions and 1,099 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ addons:
packages:
- libboost-dev
- libboost-date-time-dev
- libboost-thread-dev
- libjpeg8-dev
- libopenexr-dev
- libpng12-dev
Expand Down
3 changes: 2 additions & 1 deletion changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ Reported by Coverity static code analysis:

Miscellaneous:

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


Changes between 3.7.1-beta.9 and 3.7.1-rc.1
Expand Down
73 changes: 56 additions & 17 deletions platform/unix/syspovtimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

#include "syspovtimer.h"

#include <cerrno>
#include <ctime>

#ifdef HAVE_UNISTD_H
Expand Down Expand Up @@ -69,24 +70,47 @@ namespace pov_base

//******************************************************************************

#if !POV_USE_DEFAULT_DELAY
#if (POV_USE_PLATFORM_DELAY == 1)

// NOTE: Even if we decide to discontinue the use of this implementation,
// we may want to keep it around in case it may turn out to be superior on some
// exotic systems.
void Delay(unsigned int msec)
{
#if defined(HAVE_NANOSLEEP)
timespec ts;
timespec ts, remain;
ts.tv_sec = msec / 1000;
ts.tv_nsec = (POV_ULONG) (1000000) * (msec % 1000);
nanosleep(&ts, nullptr);
#elif defined(HAVE_USLEEP)
POV_ASSERT(msec < 1000); // On some systems, usleep() does not support sleeping for 1 second or more.
usleep (msec * (useconds_t)1000);
#else
#error "Bad compile-time configuration."
#endif
errno = 0;
while ((nanosleep(&ts, &remain) != 0) && (errno == EINTR))
{
ts = remain;
errno = 0;
}
}

#elif (POV_USE_PLATFORM_DELAY == 2)

// ATTENTION: According to the POSIX standard, `usleep()` need not be
// thread-safe!

// NOTE: Although we're currently not using this implementation, we may want to
// keep it around in case we find the default implementation wanting on some
// systems.
void Delay(unsigned int msec)
{
// According to the POSIX standard, `usleep()` may not support parameter
// values of 1 million or higher (corresponding to 1s). We work around this
// by simply calling `usleep()` repeatedly until we're good.
for (unsigned int sec = 0; sec < (msec/1000); ++sec)
usleep((useconds_t)999999); // not exactly 1s, but close enough.
usleep ((msec % 1000) * (useconds_t)1000);
}

#endif // !POV_USE_DEFAULT_DELAY
#else // POV_USE_PLATFORM_DELAY

#error "Bad compile-time configuration."

#endif // POV_USE_PLATFORM_DELAY

//******************************************************************************

Expand Down Expand Up @@ -138,9 +162,11 @@ static inline bool GettimeofdayMillisec(POV_ULONG& result)
}

Timer::Timer () :
#if !POVUNIX_USE_DEFAULT_REAL_TIMER
mWallTimeUseClockGettimeMonotonic (false),
mWallTimeUseClockGettimeRealtime (false),
mWallTimeUseGettimeofday (false),
#endif
mProcessTimeUseGetrusageSelf (false),
mProcessTimeUseClockGettimeProcess (false),
mProcessTimeUseFallback (false),
Expand All @@ -149,6 +175,7 @@ Timer::Timer () :
mThreadTimeUseClockGettimeThread (false),
mThreadTimeUseFallback (false)
{
#if !POVUNIX_USE_DEFAULT_REAL_TIMER
// Figure out which timer source to use for wall clock time.
bool haveWallTime = false;
#if defined(HAVE_DECL_CLOCK_MONOTONIC) && HAVE_DECL_CLOCK_MONOTONIC
Expand All @@ -165,12 +192,13 @@ Timer::Timer () :
// gettimeofday(), and document it here.
if (!haveWallTime)
haveWallTime = mWallTimeUseGettimeofday = GettimeofdayMillisec(mWallTimeStart);
// FIXME: add fallback, using ftime(), or time() + a counter for ms, or maybe boost::date_time
// FIXME: add fallback, using ftime(), or time() + a counter for ms, or maybe std::chrono
if (!haveWallTime)
{
POV_ASSERT(false);
mWallTimeStart = 0;
}
#endif

// Figure out which timer source to use for per-process CPU time.
bool haveProcessTime = false;
Expand All @@ -186,8 +214,12 @@ Timer::Timer () :
#endif
if (!haveProcessTime)
{
#if POVUNIX_USE_DEFAULT_REAL_TIMER
haveProcessTime = mProcessTimeUseFallback = true;
#else
haveProcessTime = mProcessTimeUseFallback = haveWallTime;
mProcessTimeStart = mWallTimeStart;
#endif
}

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

Timer::~Timer ()
{
// nothing to do
}

#if !POVUNIX_USE_DEFAULT_REAL_TIMER
POV_ULONG Timer::GetWallTime () const
{
POV_ULONG result;
Expand All @@ -232,6 +260,7 @@ POV_ULONG Timer::GetWallTime () const
return (GettimeofdayMillisec(result) ? result : 0);
return 0;
}
#endif

POV_ULONG Timer::GetProcessTime () const
{
Expand All @@ -245,7 +274,11 @@ POV_ULONG Timer::GetProcessTime () const
return (ClockGettimeMillisec(result, CLOCK_PROCESS_CPUTIME_ID) ? result : 0);
#endif
if (mProcessTimeUseFallback)
#if POVUNIX_USE_DEFAULT_REAL_TIMER
return mRealTimer.ElapsedTime();
#else
return GetWallTime ();
#endif
return 0;
}

Expand All @@ -269,10 +302,12 @@ POV_ULONG Timer::GetThreadTime () const
return 0;
}

#if !POVUNIX_USE_DEFAULT_REAL_TIMER
POV_LONG Timer::ElapsedRealTime () const
{
return GetWallTime () - mWallTimeStart;
}
#endif

POV_LONG Timer::ElapsedProcessCPUTime () const
{
Expand All @@ -286,7 +321,11 @@ POV_LONG Timer::ElapsedThreadCPUTime () const

void Timer::Reset ()
{
#if POVUNIX_USE_DEFAULT_REAL_TIMER
mRealTimer.Reset();
#else
mWallTimeStart = GetWallTime ();
#endif
mProcessTimeStart = GetProcessTime ();
mThreadTimeStart = GetThreadTime ();
}
Expand Down
28 changes: 21 additions & 7 deletions platform/unix/syspovtimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,19 @@

#include "base/configbase.h"

#include "base/timer.h"

namespace pov_base
{

#if !POV_USE_DEFAULT_DELAY

void Delay(unsigned int msec);

#endif // !POV_USE_DEFAULT_DELAY
#if !POV_USE_DEFAULT_TIMER

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

#if !POV_USE_DEFAULT_TIMER
class DefaultRealTimer;

/// Millisecond-precision timer.
///
Expand All @@ -67,9 +69,13 @@ class Timer final
public:

Timer();
~Timer();
~Timer() = default;

#if POVUNIX_USE_DEFAULT_REAL_TIMER
inline POV_LONG ElapsedRealTime() const { return mRealTimer.ElapsedTime(); }
#else
POV_LONG ElapsedRealTime() const;
#endif
POV_LONG ElapsedProcessCPUTime() const;
POV_LONG ElapsedThreadCPUTime() const;

Expand All @@ -80,13 +86,19 @@ class Timer final

private:

#if POVUNIX_USE_DEFAULT_REAL_TIMER
DefaultRealTimer mRealTimer;
#else
POV_ULONG mWallTimeStart;
#endif
POV_ULONG mProcessTimeStart;
POV_ULONG mThreadTimeStart;

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

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

#if !POVUNIX_USE_DEFAULT_REAL_TIMER
POV_ULONG GetWallTime() const;
#endif
POV_ULONG GetThreadTime() const;
POV_ULONG GetProcessTime() const;
};
Expand Down
13 changes: 13 additions & 0 deletions platform/windows/syspovtimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,22 @@ namespace pov_base

//******************************************************************************

#if POV_USE_PLATFORM_DELAY

// NOTE: Although we're currently not using this implementation, we may want to
// keep it around in case we find the default implementation wanting on Windows
// systems in general or some flavours in particular.
void Delay(unsigned int msec)
{
Sleep (msec);
}

#endif // POV_USE_PLATFORM_DELAY

//******************************************************************************

#if !POV_USE_DEFAULT_TIMER

Timer::Timer () :
// TODO - sources on the internet indicate that GetThreadTimes() and GetProcessTimes() have been
// around as early as NT 3.1. Is there a reason we're only making use of it in NT 4.0 and
Expand Down Expand Up @@ -175,5 +184,9 @@ bool Timer::HasValidProcessCPUTime () const
return mCPUTimeSupported;
}

#endif // POV_USE_DEFAULT_TIMER

//******************************************************************************

}
// end of namespace pov_base
4 changes: 3 additions & 1 deletion platform/windows/syspovtimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
namespace pov_base
{

void Delay(unsigned int msec);
#if !POV_USE_DEFAULT_TIMER

class Timer final
{
Expand Down Expand Up @@ -72,6 +72,8 @@ class Timer final
POV_ULONG GetProcessTime () const;
};

#endif // POV_USE_DEFAULT_TIMER

}
// end of namespace pov_base

Expand Down
4 changes: 2 additions & 2 deletions platform/x86/avx/avxnoise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ static inline __m256d permute4x64_functional(const __m256d& x, int i)
const int idx1 = ((i >> 2) & 0x3);
const int idx2 = ((i >> 4) & 0x3);
const int idx3 = ((i >> 6) & 0x3);
ALIGN32 double p[4];
alignas(32) double p[4];
_mm256_store_pd(p,x);

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

extern DBL RTable[];

ALIGN32 static AVXTABLETYPE AVXRTable[267];
alignas(32) static AVXTABLETYPE AVXRTable[267];

void AVXNoiseInit()
{
Expand Down
2 changes: 1 addition & 1 deletion platform/x86/avx2fma3/avx2fma3noise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ const bool kAVX2FMA3NoiseEnabled = true;

extern DBL RTable[];

ALIGN32 static AVX2TABLETYPE AVX2RTable[267];
alignas(32) static AVX2TABLETYPE AVX2RTable[267];

void AVX2FMA3NoiseInit()
{
Expand Down
3 changes: 2 additions & 1 deletion source-doc/styleguide.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ POV-Ray is being developed with portability high in mind. In practice and at pre
- While POV-Ray does require boost, we want to keep dependency on it to a minimum. The following are currently
considered fair game:
- Flyweights.
- Threads.
- DateTime **except** features that may require linking with the lib (mostly conversions to/from string).
- SmartPtr intrusive pointers.
.
Expand Down Expand Up @@ -171,6 +170,8 @@ Parameter and variable names might carry one or more additional prefixes. These
.
- Protected or private member variable names should begin with a (possibly additional) `m` prefix.
- Global variable names should begin with a (possibly additional) `g` prefix.
- Global variables with thread-local storage should begin with a (possibly additional) `gt`
- prefix.
- Constants should begin with a `k` prefix. (Does not apply to const parameters.)
.

Expand Down
1 change: 0 additions & 1 deletion source/backend/bounding/boundingtask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@

// Boost header files
#include <boost/bind.hpp>
#include <boost/thread.hpp>

// POV-Ray header files (base module)
// (none at the moment)
Expand Down
Loading

0 comments on commit 77d267d

Please sign in to comment.