diff --git a/doc/CHANGELOG.md b/doc/CHANGELOG.md index 46b39c43..cf295ec7 100644 --- a/doc/CHANGELOG.md +++ b/doc/CHANGELOG.md @@ -31,6 +31,8 @@ The full set of tests is only run for tagged releases. - the Coverity results triggered a general backend code review - fix coverity detected defects - get backend code `-Wall -Wextra -Wpedantic` clean + - exploit c++11 language constructs (e.g. emplace,lambda,auto,move,...) + - completely replace boost with std - add KW11-P (programmable clock) to all w11 systems. It is usefull in test benches (fast interrupt source) and enables on the long run to port the 2.10BSD kernel profiling code to 2.11BSD. @@ -102,11 +104,12 @@ The full set of tests is only run for tagged releases. - use auto, emplace() and range loops - use unique_ptr instead of free pointers, avoid explicit `delete` - add and use move semantic in RlinkCommandExpect - - replace boost with std + - completely replace boost with std - use std::unique_ptr instead of boost::scoped_ptr - use std::shared_ptr instead of boost - use std::function instead of boost - - use std::bind or in most cases a lambda instead of boost::bind + - use std::bind or in most cases a lambda, instead of boost::bind + - use std::thread instead of boost - use mutex and friends from std:: instead from boost:: - use std::mutex - use std::recursive_mutex diff --git a/doc/INSTALL.md b/doc/INSTALL.md index ba51d510..a185f05a 100644 --- a/doc/INSTALL.md +++ b/doc/INSTALL.md @@ -57,9 +57,6 @@ distributions should be straight forward. - building and using the rlink backend software requires: - full C/C++ development chain (gcc,g++,cpp,make) -> package: `build-essential` - - Boost C++ library (>= 1.40), with date-time, thread, and regex - -> package: `libboost-dev` `libboost-date-time-dev` `libboost-thread-dev` - `libboost-regex-dev` - libusb 1.0 (>= 1.0.6) -> package: `libusb-1.0-0-dev` - Perl (>= 5.10) (usually included in base installations) @@ -108,8 +105,9 @@ For bash and alike use export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$RETROBASE/tools/lib export MANPATH=$MANPATH:$RETROBASE/tools/man -In most cases the boost library version coming with the distribution will -work, similar for Tcl, in those cases simply use +Boost was essential in the pre-c++11 times, but has been completely replaced +by std:: classes provided by c++11. In most cases the Tcl version coming with +the distribution will work, in those cases simply use export TCLINC=/usr/include/tcl8.6 export TCLLIBNAME=tcl8.6 @@ -147,7 +145,6 @@ A C++ compiler with full `c++11` support is therefore needed, so either Required tools and libraries: g++ >= 4.8.1 (see c++11 usage above) - boost >= 1.35 (boost::thread api changed, new one is used) libusb >= 1.0.5 (timerfd support) Build was tested under: diff --git a/tools/src/librlink/RlinkPortCuff.cpp b/tools/src/librlink/RlinkPortCuff.cpp index 96aee5fb..7239f465 100644 --- a/tools/src/librlink/RlinkPortCuff.cpp +++ b/tools/src/librlink/RlinkPortCuff.cpp @@ -1,4 +1,4 @@ -// $Id: RlinkPortCuff.cpp 1081 2018-12-14 22:29:42Z mueller $ +// $Id: RlinkPortCuff.cpp 1088 2018-12-17 17:37:00Z mueller $ // // Copyright 2012-2018 by Walter F.J. Mueller // @@ -13,6 +13,7 @@ // // Revision History: // Date Rev Version Comment +// 2018-12-17 1088 1.1.9 use std::thread instead of boost // 2018-12-14 1081 1.1.8 use std::bind instead of boost // 2018-11-09 1066 1.1.7 use auto // 2018-10-27 1059 1.1.6 coverity fixup (uncaught exception in dtor) @@ -244,7 +245,7 @@ bool RlinkPortCuff::Open(const std::string& url, RerrMsg& emsg) libusb_set_pollfd_notifiers(fpUsbContext, ThunkPollfdAdd, ThunkPollfdRemove, this); - fDriverThread = boost::thread(std::bind(&RlinkPortCuff::Driver, this)); + fDriverThread = thread([this](){ Driver(); }); fIsOpen = true; @@ -275,13 +276,7 @@ void RlinkPortCuff::Cleanup() CloseFd(fFdWrite); // wait till driver thread terminates - // use timed join, throw in case driver doesn't stop - if (fDriverThread.get_id() != boost::thread::id()) { - if (!fDriverThread.timed_join(boost::posix_time::milliseconds(500))) { - throw Rexception("RlinkPortCuff::Cleanup()", - "driver thread failed to stop"); - } - } + if (fDriverThread.joinable()) fDriverThread.join(); // cleanup pipes CloseFd(fFdRead); @@ -332,7 +327,7 @@ bool RlinkPortCuff::OpenPipe(int& fdread, int& fdwrite, RerrMsg& emsg) //------------------------------------------+----------------------------------- //! FIXME_docs -// executed in separate boost thread !! +// executed in separate thread !! void RlinkPortCuff::Driver() { try { diff --git a/tools/src/librlink/RlinkPortCuff.hpp b/tools/src/librlink/RlinkPortCuff.hpp index 3c8803a3..bca2cfc4 100644 --- a/tools/src/librlink/RlinkPortCuff.hpp +++ b/tools/src/librlink/RlinkPortCuff.hpp @@ -1,4 +1,4 @@ -// $Id: RlinkPortCuff.hpp 1060 2018-10-27 11:32:39Z mueller $ +// $Id: RlinkPortCuff.hpp 1088 2018-12-17 17:37:00Z mueller $ // // Copyright 2012-2018 by Walter F.J. Mueller // @@ -13,6 +13,7 @@ // // Revision History: // Date Rev Version Comment +// 2018-12-17 1088 1.0.2 use std::thread instead of boost // 2013-01-02 467 1.0.1 get cleanup code right; add USBErrorName() // 2012-12-26 465 1.0 Initial version // --------------------------------------------------------------------------- @@ -33,8 +34,7 @@ #include #include - -#include "boost/thread/thread.hpp" +#include namespace Retro { @@ -72,7 +72,7 @@ namespace Retro { protected: int fFdReadDriver; //!< fd for read (driver end) int fFdWriteDriver; //!< fd for write (driver end) - boost::thread fDriverThread; //!< driver thread + std::thread fDriverThread; //!< driver thread libusb_context* fpUsbContext; libusb_device** fpUsbDevList; ssize_t fUsbDevCount; diff --git a/tools/src/librlink/RlinkServer.cpp b/tools/src/librlink/RlinkServer.cpp index 354f9e97..cf954e8c 100644 --- a/tools/src/librlink/RlinkServer.cpp +++ b/tools/src/librlink/RlinkServer.cpp @@ -1,4 +1,4 @@ -// $Id: RlinkServer.cpp 1085 2018-12-16 14:11:16Z mueller $ +// $Id: RlinkServer.cpp 1088 2018-12-17 17:37:00Z mueller $ // // Copyright 2013-2018 by Walter F.J. Mueller // @@ -13,7 +13,7 @@ // // Revision History: // Date Rev Version Comment -// 2018-12-17 1085 1.2.8 use std::lock_guard instead of boost +// 2018-12-17 1088 2.2.8 use std::lock_guard, std::thread instead of boost // 2018-12-15 1083 2.2.7 for std::function setups: use rval ref and move // 2018-12-14 1081 2.2.6 use std::bind instead of boost // 2018-12-07 1078 2.2.5 use std::shared_ptr instead of boost @@ -36,6 +36,8 @@ \brief Implemenation of RlinkServer. */ +#include + #include "librtools/Rexception.hpp" #include "librtools/RosFill.hpp" #include "librtools/RosPrintf.hpp" @@ -188,7 +190,7 @@ void RlinkServer::GetAttnInfo(AttnArgs& args) //! FIXME_docs void RlinkServer::RemoveAttnHandler(uint16_t mask, void* cdata) -{ +{ lock_guard lock(*fspConn); AttnId id(mask, cdata); @@ -269,7 +271,8 @@ void RlinkServer::Start() //! FIXME_docs void RlinkServer::Stop() -{ +{ + if (!IsActive()) return; fELoop.Stop(); Wakeup(); fServerThread.join(); @@ -280,7 +283,7 @@ void RlinkServer::Stop() //! FIXME_docs void RlinkServer::Resume() -{ +{ StartOrResume(true); return; } @@ -289,9 +292,9 @@ void RlinkServer::Resume() //! FIXME_docs void RlinkServer::Wakeup() -{ +{ uint64_t one(1); - int irc = write(fWakeupEvent, &one, sizeof(one)); + int irc = ::write(fWakeupEvent, &one, sizeof(one)); if (irc < 0) throw Rexception("RlinkServer::Wakeup()", "write() to eventfd failed: ", errno); @@ -302,7 +305,7 @@ void RlinkServer::Wakeup() //! FIXME_docs void RlinkServer::SignalAttnNotify(uint16_t apat) -{ +{ // only called under lock !! if (apat & fAttnNotiPatt) { RlogMsg lmsg(LogFile(), 'W'); @@ -322,8 +325,8 @@ void RlinkServer::SignalAttnNotify(uint16_t apat) */ bool RlinkServer::IsActive() const -{ - return fServerThread.get_id() != boost::thread::id(); +{ + return fServerThread.joinable(); } //------------------------------------------+----------------------------------- @@ -334,7 +337,7 @@ bool RlinkServer::IsActive() const bool RlinkServer::IsActiveInside() const { - return IsActive() && boost::this_thread::get_id() == fServerThread.get_id(); + return IsActive() && this_thread::get_id() == fServerThread.get_id(); } //------------------------------------------+----------------------------------- @@ -346,7 +349,7 @@ bool RlinkServer::IsActiveInside() const bool RlinkServer::IsActiveOutside() const { - return IsActive() && boost::this_thread::get_id() != fServerThread.get_id(); + return IsActive() && this_thread::get_id() != fServerThread.get_id(); } //------------------------------------------+----------------------------------- @@ -421,8 +424,7 @@ void RlinkServer::StartOrResume(bool resume) // and start server thread fELoop.UnStop(); - fServerThread = boost::thread(std::bind(&RlinkServerEventLoop::EventLoop, - &fELoop)); + fServerThread = thread([this](){ fELoop.EventLoop(); }); if (resume) { RerrMsg emsg; @@ -557,7 +559,7 @@ int RlinkServer::WakeupHandler(const pollfd& pfd) if (pfd.revents & (~pfd.events)) return -1; uint64_t buf; - int irc = read(fWakeupEvent, &buf, sizeof(buf)); + int irc = ::read(fWakeupEvent, &buf, sizeof(buf)); if (irc < 0) throw Rexception("RlinkServer::WakeupHandler()", "read() from eventfd failed: ", errno); diff --git a/tools/src/librlink/RlinkServer.hpp b/tools/src/librlink/RlinkServer.hpp index 78025704..4926d6a0 100644 --- a/tools/src/librlink/RlinkServer.hpp +++ b/tools/src/librlink/RlinkServer.hpp @@ -1,4 +1,4 @@ -// $Id: RlinkServer.hpp 1084 2018-12-16 12:23:53Z mueller $ +// $Id: RlinkServer.hpp 1088 2018-12-17 17:37:00Z mueller $ // // Copyright 2013-2018 by Walter F.J. Mueller // @@ -13,6 +13,7 @@ // // Revision History: // Date Rev Version Comment +// 2018-12-17 1088 2.2.6 use std::thread instead of boost // 2018-12-16 1084 2.2.5 use =delete for noncopyable instead of boost // 2018-12-15 1083 2.2.4 for std::function setups: use rval ref and move // 2018-12-14 1081 2.2.3 use std::function instead of boost @@ -42,8 +43,7 @@ #include #include #include - -#include "boost/thread/thread.hpp" +#include #include "librtools/Rstats.hpp" @@ -179,7 +179,7 @@ namespace Retro { std::list fActnList; ReventFd fWakeupEvent; RlinkServerEventLoop fELoop; - boost::thread fServerThread; + std::thread fServerThread; uint16_t fAttnPatt; //!< current attn pattern uint16_t fAttnNotiPatt; //!< attn notifier pattern uint32_t fTraceLevel; //!< trace level diff --git a/tools/src/librlinktpp/RtclAttnShuttle.cpp b/tools/src/librlinktpp/RtclAttnShuttle.cpp index a646b96d..f08bfd90 100644 --- a/tools/src/librlinktpp/RtclAttnShuttle.cpp +++ b/tools/src/librlinktpp/RtclAttnShuttle.cpp @@ -1,4 +1,4 @@ -// $Id: RtclAttnShuttle.cpp 1082 2018-12-15 13:56:20Z mueller $ +// $Id: RtclAttnShuttle.cpp 1088 2018-12-17 17:37:00Z mueller $ // // Copyright 2013-2018 by Walter F.J. Mueller // @@ -28,6 +28,7 @@ \brief Implemenation of class RtclAttnShuttle. */ +#include #include #include "librtools/Rexception.hpp" diff --git a/tools/src/librlinktpp/RtclRlinkServer.cpp b/tools/src/librlinktpp/RtclRlinkServer.cpp index 9f507bfb..8197abb1 100644 --- a/tools/src/librlinktpp/RtclRlinkServer.cpp +++ b/tools/src/librlinktpp/RtclRlinkServer.cpp @@ -1,4 +1,4 @@ -// $Id: RtclRlinkServer.cpp 1087 2018-12-17 08:25:37Z mueller $ +// $Id: RtclRlinkServer.cpp 1088 2018-12-17 17:37:00Z mueller $ // // Copyright 2013-2018 by Walter F.J. Mueller // @@ -140,11 +140,13 @@ int RtclRlinkServer::M_server(RtclArgs& args) if (args.NextOpt(opt, optset)) { if (opt == "-start") { // server -start if (!args.AllDone()) return kERR; + if (Obj().IsActive()) return args.Quit("-E: server already running"); Obj().Start(); } else if (opt == "-stop") { // server -stop if (!args.AllDone()) return kERR; Obj().Stop(); } else if (opt == "-resume") { // server -resume + if (Obj().IsActive()) return args.Quit("-E: server already running"); if (!args.AllDone()) return kERR; Obj().Resume(); } else if (opt == "-test") { // server -test diff --git a/tools/src/librtcltools/RtclGetBase.hpp b/tools/src/librtcltools/RtclGetBase.hpp index 3e990958..2b5e1445 100644 --- a/tools/src/librtcltools/RtclGetBase.hpp +++ b/tools/src/librtcltools/RtclGetBase.hpp @@ -1,4 +1,4 @@ -// $Id: RtclGetBase.hpp 983 2018-01-02 20:35:59Z mueller $ +// $Id: RtclGetBase.hpp 1088 2018-12-17 17:37:00Z mueller $ // // Copyright 2013- by Walter F.J. Mueller // @@ -29,8 +29,6 @@ #include #include -#include "boost/function.hpp" - namespace Retro { class RtclGetBase { diff --git a/tools/src/librtcltools/RtclGetList.hpp b/tools/src/librtcltools/RtclGetList.hpp index 6703fde2..49c39e7f 100644 --- a/tools/src/librtcltools/RtclGetList.hpp +++ b/tools/src/librtcltools/RtclGetList.hpp @@ -1,4 +1,4 @@ -// $Id: RtclGetList.hpp 1084 2018-12-16 12:23:53Z mueller $ +// $Id: RtclGetList.hpp 1088 2018-12-17 17:37:00Z mueller $ // // Copyright 2013-2018 by Walter F.J. Mueller // @@ -34,6 +34,7 @@ #include #include #include +#include #include #include "RtclGet.hpp" diff --git a/tools/src/librtcltools/RtclSetBase.hpp b/tools/src/librtcltools/RtclSetBase.hpp index a4bb837e..82808563 100644 --- a/tools/src/librtcltools/RtclSetBase.hpp +++ b/tools/src/librtcltools/RtclSetBase.hpp @@ -1,4 +1,4 @@ -// $Id: RtclSetBase.hpp 983 2018-01-02 20:35:59Z mueller $ +// $Id: RtclSetBase.hpp 1088 2018-12-17 17:37:00Z mueller $ // // Copyright 2013- by Walter F.J. Mueller // @@ -29,8 +29,6 @@ #include #include -#include "boost/function.hpp" - #include "RtclArgs.hpp" namespace Retro { diff --git a/tools/src/librtcltools/RtclSetList.hpp b/tools/src/librtcltools/RtclSetList.hpp index 63a37878..918b385a 100644 --- a/tools/src/librtcltools/RtclSetList.hpp +++ b/tools/src/librtcltools/RtclSetList.hpp @@ -1,4 +1,4 @@ -// $Id: RtclSetList.hpp 1084 2018-12-16 12:23:53Z mueller $ +// $Id: RtclSetList.hpp 1088 2018-12-17 17:37:00Z mueller $ // // Copyright 2013-2018 by Walter F.J. Mueller // @@ -34,6 +34,7 @@ #include #include #include +#include #include #include "RtclSet.hpp" diff --git a/tools/src/librtools/Rtools.cpp b/tools/src/librtools/Rtools.cpp index afb87ce7..080201ed 100644 --- a/tools/src/librtools/Rtools.cpp +++ b/tools/src/librtools/Rtools.cpp @@ -1,4 +1,4 @@ -// $Id: Rtools.cpp 1063 2018-10-29 18:37:42Z mueller $ +// $Id: Rtools.cpp 1088 2018-12-17 17:37:00Z mueller $ // // Copyright 2011-2018 by Walter F.J. Mueller // @@ -186,7 +186,7 @@ void Catch2Cerr(const char* msg, std::function func) << " caught and dropped in " << msg << endl; } catch (exception& e) { cerr << "Catch2Cerr-E: exception '" << e.what() - << " caught and dropped in " << msg << endl; + << "' caught and dropped in " << msg << endl; } catch(...) { cerr << "Catch2Cerr-E: non std::exception" << " caught and dropped in " << msg << endl; diff --git a/tools/src/librw11/Rw11Cpu.cpp b/tools/src/librw11/Rw11Cpu.cpp index 3863f651..36031873 100644 --- a/tools/src/librw11/Rw11Cpu.cpp +++ b/tools/src/librw11/Rw11Cpu.cpp @@ -1,4 +1,4 @@ -// $Id: Rw11Cpu.cpp 1085 2018-12-16 14:11:16Z mueller $ +// $Id: Rw11Cpu.cpp 1088 2018-12-17 17:37:00Z mueller $ // // Copyright 2013-2018 by Walter F.J. Mueller // @@ -48,6 +48,7 @@ #include #include #include +#include #include #include @@ -573,7 +574,7 @@ bool Rw11Cpu::LoadAbs(const std::string& fname, RerrMsg& emsg, bool trace) while (go) { uint8_t byte; - int irc = read(fd, &byte, 1); + int irc = ::read(fd, &byte, 1); if (irc == 0) { if (state == s_chr0) { ok = true; @@ -701,7 +702,7 @@ bool Rw11Cpu::LoadAbs(const std::string& fname, RerrMsg& emsg, bool trace) } // switch(state) } // while(go) - close(fd); + ::close(fd); return ok; } diff --git a/tools/src/librw11/Rw11VirtEthTap.cpp b/tools/src/librw11/Rw11VirtEthTap.cpp index c2f7473a..cc907dca 100644 --- a/tools/src/librw11/Rw11VirtEthTap.cpp +++ b/tools/src/librw11/Rw11VirtEthTap.cpp @@ -1,4 +1,4 @@ -// $Id: Rw11VirtEthTap.cpp 1082 2018-12-15 13:56:20Z mueller $ +// $Id: Rw11VirtEthTap.cpp 1088 2018-12-17 17:37:00Z mueller $ // // Copyright 2014-2018 by Walter F.J. Mueller // @@ -31,6 +31,7 @@ #include #include #include +#include #include #include diff --git a/tools/src/librw11/Rw11VirtTermTcp.cpp b/tools/src/librw11/Rw11VirtTermTcp.cpp index 6eca8bfe..4febd5c4 100644 --- a/tools/src/librw11/Rw11VirtTermTcp.cpp +++ b/tools/src/librw11/Rw11VirtTermTcp.cpp @@ -1,4 +1,4 @@ -// $Id: Rw11VirtTermTcp.cpp 1082 2018-12-15 13:56:20Z mueller $ +// $Id: Rw11VirtTermTcp.cpp 1088 2018-12-17 17:37:00Z mueller $ // // Copyright 2013-2018 by Walter F.J. Mueller // @@ -35,6 +35,7 @@ #include #include #include +#include #include @@ -152,7 +153,7 @@ bool Rw11VirtTermTcp::Open(const std::string& url, RerrMsg& emsg) int on = 1; if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) < 0) { emsg.InitErrno("Rw11VirtTermTcp::Open","setsockop() failed: ", errno); - close(fd); + ::close(fd); return false; } @@ -164,13 +165,13 @@ bool Rw11VirtTermTcp::Open(const std::string& url, RerrMsg& emsg) // Note: ::bind needed below to avoid collision with std::bind... if (::bind(fd, (sockaddr*) &sa, sizeof(sa)) < 0) { emsg.InitErrno("Rw11VirtTermTcp::Open","bind() failed: ", errno); - close(fd); + ::close(fd); return false; } if (listen(fd, 1) <0) { emsg.InitErrno("Rw11VirtTermTcp::Open","listen() failed: ", errno); - close(fd); + ::close(fd); return false; } @@ -219,7 +220,7 @@ bool Rw11VirtTermTcp::Snd(const uint8_t* data, size_t count, RerrMsg& /*emsg*/) *pobuf++ = *pdata++; } - int irc = write(fFd, obuf, pobuf-obuf); + int irc = ::write(fFd, obuf, pobuf-obuf); if (irc < 0) { RlogMsg lmsg(LogFile(),'E'); RerrMsg emsg("Rw11VirtTermTcp::Snd", @@ -295,11 +296,11 @@ int Rw11VirtTermTcp::ListenPollHandler(const pollfd& pfd) int nerr = 0; // send initial negotiation WILLs and DOs - if (write(fFd, buf_1, sizeof(buf_1)) < 0) nerr += 1; - if (write(fFd, buf_2, sizeof(buf_2)) < 0) nerr += 1; - if (write(fFd, buf_3, sizeof(buf_3)) < 0) nerr += 1; - if (write(fFd, buf_4, sizeof(buf_4)) < 0) nerr += 1; - if (write(fFd, buf_5, sizeof(buf_5)) < 0) nerr += 1; + if (::write(fFd, buf_1, sizeof(buf_1)) < 0) nerr += 1; + if (::write(fFd, buf_2, sizeof(buf_2)) < 0) nerr += 1; + if (::write(fFd, buf_3, sizeof(buf_3)) < 0) nerr += 1; + if (::write(fFd, buf_4, sizeof(buf_4)) < 0) nerr += 1; + if (::write(fFd, buf_5, sizeof(buf_5)) < 0) nerr += 1; // send connect message if (nerr==0) { @@ -322,7 +323,7 @@ int Rw11VirtTermTcp::ListenPollHandler(const pollfd& pfd) } if (nerr) { - close(fFd); + ::close(fFd); fFd = -1; RlogMsg lmsg(LogFile(),'E'); RerrMsg emsg("Rw11VirtTermTcp::ListenPollHandler", @@ -360,7 +361,7 @@ int Rw11VirtTermTcp::RcvPollHandler(const pollfd& pfd) uint8_t obuf[1024]; uint8_t* pobuf = obuf; - irc = read(fFd, ibuf, 1024); + irc = ::read(fFd, ibuf, 1024); if (irc < 0 && (errno == EAGAIN || errno == EWOULDBLOCK)) return 0; @@ -425,7 +426,7 @@ int Rw11VirtTermTcp::RcvPollHandler(const pollfd& pfd) RlogMsg lmsg(LogFile(),'I'); lmsg << "TermTcp: close on " << fChannelId << " for " << Unit().Name(); } - close(fFd); + ::close(fFd); fFd = -1; Server().AddPollHandler([this](const pollfd& pfd) { return ListenPollHandler(pfd); },