Commit 359538e1 by Maarten L. Hekkelman

resources, fix progress' implementations move to std::thread

parent d45ce506
......@@ -32,6 +32,19 @@ AS_IF([test x"$CCP4" != x""],
LDFLAGS="$LDFLAGS -L${CCP4}/lib"
])
AC_ARG_VAR([USE_RSRC], [Use resources to store internal data, requires mrc])
AC_ARG_VAR([MRC], [Specify a location for the mrc executable])
dnl We really like to use mrc
if test "x$MRC" = "x"; then
AC_PATH_PROG([MRC], [mrc])
fi
if test "x$MRC" = "x"; then
AC_MSG_WARN([mrc not found, building without support for resources.])
else
USE_RSRC=1
fi
AX_BOOST_BASE([1.73])
AX_BOOST_REGEX
......@@ -123,5 +136,4 @@ AX_CHECK_LIBRARY([LIBBZ2], [bzlib.h], [bz2], [],
# [enable_debug=auto])
dnl Process files
AC_OUTPUT([GNUmakefile
libcif++.pc])
AC_OUTPUT([GNUmakefile])
......@@ -14,7 +14,6 @@ enum AtomType : uint8_t
Nn = 0, // Unknown
H = 1, // Hydro­gen
D = 129, // Deuterium
He = 2, // He­lium
Li = 3, // Lith­ium
......@@ -140,6 +139,8 @@ enum AtomType : uint8_t
Md = 101, // Mende­levium
No = 102, // Nobel­ium
Lr = 103, // Lawren­cium
D = 129, // Deuterium
};
// --------------------------------------------------------------------
......
......@@ -17,7 +17,6 @@ const AtomTypeInfo kKnownAtoms[] =
{
{ Nn, "Unknown", "Nn", 0, false, { kNA, kNA, kNA, kNA, kNA, kNA, kNA } }, // 0 Nn Unknown
{ H, "Hydrogen", "H", 1.008, false, { 53, 25, 37, 32, kNA, kNA, 120 } }, // 1 H Hydro­gen
{ D, "Deuterium", "D", 2.014, false, { 53, 25, 37, 32, kNA, kNA, 120 } }, // 1 D Deuterium
{ He, "Helium", "He", 4.0026, false, { 31, kNA, 32, 46, kNA, kNA, 140 } }, // 2 He He­lium
{ Li, "Lithium", "Li", 6.94, true, { 167, 145, 134, 133, 124, kNA, 182 } }, // 3 Li Lith­ium
{ Be, "Beryllium", "Be", 9.0122, true, { 112, 105, 90, 102, 90, 85, kNA } }, // 4 Be Beryl­lium
......@@ -134,7 +133,9 @@ const AtomTypeInfo kKnownAtoms[] =
{ Mc, "Moscovium", "Mc", 290, true, { kNA, kNA, kNA, 162, kNA, kNA, kNA } }, // 115 Mc Moscov­ium
{ Lv, "Livermorium", "Lv", 293, true, { kNA, kNA, kNA, 175, kNA, kNA, kNA } }, // 116 Lv Liver­morium
{ Ts, "Tennessine", "Ts", 294, true, { kNA, kNA, kNA, 165, kNA, kNA, kNA } }, // 117 Ts Tenness­ine
{ Og, "Oganesson", "Og", 294, true, { kNA, kNA, kNA, 157, kNA, kNA, kNA } } // 118 Og Oga­nesson
{ Og, "Oganesson", "Og", 294, true, { kNA, kNA, kNA, 157, kNA, kNA, kNA } }, // 118 Og Oga­nesson
{ D, "Deuterium", "D", 2.014, false, { 53, 25, 37, 32, kNA, kNA, 120 } }, // 1 D Deuterium
};
uint32_t kKnownAtomsCount = sizeof(kKnownAtoms) / sizeof(AtomTypeInfo);
......
......@@ -18,9 +18,8 @@
#endif
#include <boost/algorithm/string.hpp>
#if BOOST_VERSION >= 104800
#include <boost/timer/timer.hpp>
#endif
#include <boost/date_time/posix_time/posix_time.hpp>
#include "cif++/CifUtils.hpp"
......@@ -440,9 +439,16 @@ struct ProgressImpl
{
ProgressImpl(int64_t inMax, const string& inAction)
: mMax(inMax), mConsumed(0), mAction(inAction), mMessage(inAction)
, mThread(std::bind(&ProgressImpl::Run, this)) {}
, mThread(std::bind(&ProgressImpl::Run, this))
, mStart(boost::posix_time::second_clock::local_time()) {}
void Run();
void Stop()
{
mStop = true;
if (mThread.joinable())
mThread.join();
}
void PrintProgress();
void PrintDone();
......@@ -454,29 +460,35 @@ struct ProgressImpl
string mAction, mMessage;
std::mutex mMutex;
std::thread mThread;
boost::timer::cpu_timer
mTimer;
boost::timer::cpu_timer mTimer;
boost::posix_time::ptime mStart;
bool mStop = false;
};
void ProgressImpl::Run()
{
using namespace boost::posix_time;
// using namespace boost::local_time;
bool printedAny = false;
try
{
std::this_thread::sleep_for(std::chrono::seconds(5));
for (;;)
{
std::this_thread::sleep_for(std::chrono::milliseconds(100));
std::unique_lock lock(mMutex);
if (mConsumed == mMax)
if (mStop or mConsumed == mMax)
break;
if (second_clock::local_time() - mStart < seconds(5))
continue;
PrintProgress();
printedAny = true;
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
}
catch (...) {}
......@@ -593,11 +605,8 @@ Progress::Progress(int64_t inMax, const string& inAction)
Progress::~Progress()
{
if (mImpl != nullptr and mImpl->mThread.joinable())
{
// mImpl->mThread.interrupt();
mImpl->mThread.join();
}
if (mImpl != nullptr)
mImpl->Stop();
delete mImpl;
}
......@@ -605,22 +614,18 @@ Progress::~Progress()
void Progress::consumed(int64_t inConsumed)
{
if (mImpl != nullptr and
(mImpl->mConsumed += inConsumed) >= mImpl->mMax and
mImpl->mThread.joinable())
(mImpl->mConsumed += inConsumed) >= mImpl->mMax)
{
// mImpl->mThread.interrupt();
mImpl->mThread.join();
mImpl->Stop();
}
}
void Progress::progress(int64_t inProgress)
{
if (mImpl != nullptr and
(mImpl->mConsumed = inProgress) >= mImpl->mMax and
mImpl->mThread.joinable())
(mImpl->mConsumed = inProgress) >= mImpl->mMax)
{
// mImpl->mThread.interrupt();
mImpl->mThread.join();
mImpl->Stop();
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment