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""], ...@@ -32,6 +32,19 @@ AS_IF([test x"$CCP4" != x""],
LDFLAGS="$LDFLAGS -L${CCP4}/lib" 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_BASE([1.73])
AX_BOOST_REGEX AX_BOOST_REGEX
...@@ -123,5 +136,4 @@ AX_CHECK_LIBRARY([LIBBZ2], [bzlib.h], [bz2], [], ...@@ -123,5 +136,4 @@ AX_CHECK_LIBRARY([LIBBZ2], [bzlib.h], [bz2], [],
# [enable_debug=auto]) # [enable_debug=auto])
dnl Process files dnl Process files
AC_OUTPUT([GNUmakefile AC_OUTPUT([GNUmakefile])
libcif++.pc])
...@@ -14,7 +14,6 @@ enum AtomType : uint8_t ...@@ -14,7 +14,6 @@ enum AtomType : uint8_t
Nn = 0, // Unknown Nn = 0, // Unknown
H = 1, // Hydro­gen H = 1, // Hydro­gen
D = 129, // Deuterium
He = 2, // He­lium He = 2, // He­lium
Li = 3, // Lith­ium Li = 3, // Lith­ium
...@@ -140,6 +139,8 @@ enum AtomType : uint8_t ...@@ -140,6 +139,8 @@ enum AtomType : uint8_t
Md = 101, // Mende­levium Md = 101, // Mende­levium
No = 102, // Nobel­ium No = 102, // Nobel­ium
Lr = 103, // Lawren­cium Lr = 103, // Lawren­cium
D = 129, // Deuterium
}; };
// -------------------------------------------------------------------- // --------------------------------------------------------------------
......
...@@ -17,7 +17,6 @@ const AtomTypeInfo kKnownAtoms[] = ...@@ -17,7 +17,6 @@ const AtomTypeInfo kKnownAtoms[] =
{ {
{ Nn, "Unknown", "Nn", 0, false, { kNA, kNA, kNA, kNA, kNA, kNA, kNA } }, // 0 Nn Unknown { 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 { 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 { 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 { 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 { Be, "Beryllium", "Be", 9.0122, true, { 112, 105, 90, 102, 90, 85, kNA } }, // 4 Be Beryl­lium
...@@ -134,7 +133,9 @@ const AtomTypeInfo kKnownAtoms[] = ...@@ -134,7 +133,9 @@ const AtomTypeInfo kKnownAtoms[] =
{ Mc, "Moscovium", "Mc", 290, true, { kNA, kNA, kNA, 162, kNA, kNA, kNA } }, // 115 Mc Moscov­ium { 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 { 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 { 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); uint32_t kKnownAtomsCount = sizeof(kKnownAtoms) / sizeof(AtomTypeInfo);
......
...@@ -18,9 +18,8 @@ ...@@ -18,9 +18,8 @@
#endif #endif
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#if BOOST_VERSION >= 104800
#include <boost/timer/timer.hpp> #include <boost/timer/timer.hpp>
#endif #include <boost/date_time/posix_time/posix_time.hpp>
#include "cif++/CifUtils.hpp" #include "cif++/CifUtils.hpp"
...@@ -440,9 +439,16 @@ struct ProgressImpl ...@@ -440,9 +439,16 @@ struct ProgressImpl
{ {
ProgressImpl(int64_t inMax, const string& inAction) ProgressImpl(int64_t inMax, const string& inAction)
: mMax(inMax), mConsumed(0), mAction(inAction), mMessage(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 Run();
void Stop()
{
mStop = true;
if (mThread.joinable())
mThread.join();
}
void PrintProgress(); void PrintProgress();
void PrintDone(); void PrintDone();
...@@ -454,29 +460,35 @@ struct ProgressImpl ...@@ -454,29 +460,35 @@ struct ProgressImpl
string mAction, mMessage; string mAction, mMessage;
std::mutex mMutex; std::mutex mMutex;
std::thread mThread; std::thread mThread;
boost::timer::cpu_timer boost::timer::cpu_timer mTimer;
mTimer; boost::posix_time::ptime mStart;
bool mStop = false;
}; };
void ProgressImpl::Run() void ProgressImpl::Run()
{ {
using namespace boost::posix_time;
// using namespace boost::local_time;
bool printedAny = false; bool printedAny = false;
try try
{ {
std::this_thread::sleep_for(std::chrono::seconds(5));
for (;;) for (;;)
{ {
std::this_thread::sleep_for(std::chrono::milliseconds(100));
std::unique_lock lock(mMutex); std::unique_lock lock(mMutex);
if (mConsumed == mMax) if (mStop or mConsumed == mMax)
break; break;
if (second_clock::local_time() - mStart < seconds(5))
continue;
PrintProgress(); PrintProgress();
printedAny = true; printedAny = true;
std::this_thread::sleep_for(std::chrono::milliseconds(100));
} }
} }
catch (...) {} catch (...) {}
...@@ -593,11 +605,8 @@ Progress::Progress(int64_t inMax, const string& inAction) ...@@ -593,11 +605,8 @@ Progress::Progress(int64_t inMax, const string& inAction)
Progress::~Progress() Progress::~Progress()
{ {
if (mImpl != nullptr and mImpl->mThread.joinable()) if (mImpl != nullptr)
{ mImpl->Stop();
// mImpl->mThread.interrupt();
mImpl->mThread.join();
}
delete mImpl; delete mImpl;
} }
...@@ -605,22 +614,18 @@ Progress::~Progress() ...@@ -605,22 +614,18 @@ Progress::~Progress()
void Progress::consumed(int64_t inConsumed) void Progress::consumed(int64_t inConsumed)
{ {
if (mImpl != nullptr and if (mImpl != nullptr and
(mImpl->mConsumed += inConsumed) >= mImpl->mMax and (mImpl->mConsumed += inConsumed) >= mImpl->mMax)
mImpl->mThread.joinable())
{ {
// mImpl->mThread.interrupt(); mImpl->Stop();
mImpl->mThread.join();
} }
} }
void Progress::progress(int64_t inProgress) void Progress::progress(int64_t inProgress)
{ {
if (mImpl != nullptr and if (mImpl != nullptr and
(mImpl->mConsumed = inProgress) >= mImpl->mMax and (mImpl->mConsumed = inProgress) >= mImpl->mMax)
mImpl->mThread.joinable())
{ {
// mImpl->mThread.interrupt(); mImpl->Stop();
mImpl->mThread.join();
} }
} }
......
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