Skip to content
This repository has been archived by the owner on Jan 7, 2019. It is now read-only.

Commit

Permalink
[boost] Use C++11 stdlib classes instead of boost.
Browse files Browse the repository at this point in the history
  • Loading branch information
salkinium committed Jan 3, 2018
1 parent 3b47fa5 commit 5ef8009
Show file tree
Hide file tree
Showing 22 changed files with 72 additions and 65 deletions.
10 changes: 5 additions & 5 deletions src/xpcc/architecture/platform/driver/can/canusb/canusb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
#include <string>

#include <xpcc/architecture/interface/can.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread.hpp>
#include <mutex>
#include <thread>

namespace xpcc
{
Expand Down Expand Up @@ -83,8 +83,8 @@ class CanUsb : public ::xpcc::Can
update();

private:
typedef boost::mutex Mutex;
typedef boost::mutex::scoped_lock MutexGuard;
typedef std::mutex Mutex;
typedef std::lock_guard<Mutex> MutexGuard;

Mutex stateLock;
Mutex readBufferLock;
Expand All @@ -97,7 +97,7 @@ class CanUsb : public ::xpcc::Can
std::string tmpRead;
std::queue<can::Message> readBuffer;

boost::thread* thread;
std::thread* thread;
};

} // namespace hosted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ xpcc::hosted::CanUsb<SerialPort>::open(xpcc::Can::Bitrate canBitrate)
MutexGuard stateGuard(this->stateLock);
this->active = true;
}
this->thread = new boost::thread(
boost::bind(&xpcc::hosted::CanUsb<SerialPort>::update, this));
this->thread = new std::thread(&xpcc::hosted::CanUsb<SerialPort>::update, this);

busState = BusState::Connected;
this->tmpRead.clear();
Expand Down
2 changes: 1 addition & 1 deletion src/xpcc/communication/xpcc/backend/tipc/receiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ xpcc::tipc::Receiver::Receiver(
isAlive_(true)
{
// The start of the thread has to be placed _after_ the initialization of isAlive_
this->receiverThread_.reset(new Thread(boost::bind(&Receiver::runReceiver, this)));
this->receiverThread_.reset(new Thread(&Receiver::runReceiver, this));
}

// ----------------------------------------------------------------------------
Expand Down
16 changes: 8 additions & 8 deletions src/xpcc/communication/xpcc/backend/tipc/receiver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@

#include <queue>

#include <boost/thread/mutex.hpp>
#include <boost/thread/thread.hpp>
#include <boost/scoped_ptr.hpp>
#include <mutex>
#include <thread>
#include <memory>

#include <xpcc/container/smart_pointer.hpp>

Expand Down Expand Up @@ -95,10 +95,10 @@ namespace xpcc
dropPacket();

private:
typedef xpcc::SmartPointer Payload;
typedef boost::mutex Mutex;
typedef boost::mutex::scoped_lock MutexGuard;
typedef boost::thread Thread;
typedef xpcc::SmartPointer Payload;
typedef std::mutex Mutex;
typedef std::lock_guard<Mutex> MutexGuard;
typedef std::thread Thread;

bool
isAlive();
Expand All @@ -115,7 +115,7 @@ namespace xpcc

std::queue<Payload> packetQueue_;

boost::scoped_ptr<Thread> receiverThread_;
std::unique_ptr<Thread> receiverThread_;
mutable Mutex receiverSocketLock_;
mutable Mutex packetQueueLock_;

Expand Down
6 changes: 4 additions & 2 deletions src/xpcc/communication/xpcc/backend/tipc/receiver_socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@
#include <linux/tipc.h>
#include <errno.h>
#include <cstring>
#include <unistd.h>

#include <boost/scoped_array.hpp>
#include <memory>

#include <iostream>

Expand Down Expand Up @@ -144,7 +145,8 @@ xpcc::tipc::ReceiverSocket::receivePayload(uint8_t* payloadPointer, size_t paylo
int result = 0;

// Allocate memory for the whole packet inclusive header
boost::scoped_array<uint8_t> packetPointer ( new uint8_t[ sizeof(Header) + payloadLength ] );

std::unique_ptr<uint8_t[]> packetPointer ( new uint8_t[ sizeof(Header) + payloadLength ] );

result = recv( this->socketDescriptor_,
packetPointer.get(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

#include "header.hpp"

#include <boost/scoped_array.hpp>
#include <stdint.h>

namespace xpcc {
Expand Down
2 changes: 1 addition & 1 deletion src/xpcc/processing/rtos/mutex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include <xpcc/architecture/utils.hpp>

#ifdef XPCC__OS_HOSTED
# include "boost/mutex.hpp"
# include "stdlib/mutex.hpp"
#elif defined(XPCC__CPU_CORTEX_M3) || defined(XPCC__CPU_CORTEX_M4)
# include "freertos/mutex.hpp"
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/xpcc/processing/rtos/queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include <xpcc/architecture/utils.hpp>

#ifdef XPCC__OS_HOSTED
# include "boost/queue.hpp"
# include "stdlib/queue.hpp"
#elif defined(XPCC__CPU_CORTEX_M3) || defined(XPCC__CPU_CORTEX_M4)
# include "freertos/queue.hpp"
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/xpcc/processing/rtos/scheduler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include <xpcc/architecture/utils.hpp>

#ifdef XPCC__OS_HOSTED
# include "boost/scheduler.hpp"
# include "stdlib/scheduler.hpp"
#elif defined(XPCC__CPU_CORTEX_M3) || defined(XPCC__CPU_CORTEX_M4)
# include "freertos/scheduler.hpp"
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/xpcc/processing/rtos/semaphore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include <xpcc/architecture/utils.hpp>

#ifdef XPCC__OS_HOSTED
# include "boost/semaphore.hpp"
# include "stdlib/semaphore.hpp"
#elif defined(XPCC__CPU_CORTEX_M3) || defined(XPCC__CPU_CORTEX_M4)
# include "freertos/semaphore.hpp"
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
// ----------------------------------------------------------------------------

#include "../mutex.hpp"
#include <chrono>

// ----------------------------------------------------------------------------
xpcc::rtos::Mutex::Mutex()
Expand All @@ -43,6 +44,5 @@ xpcc::rtos::Mutex::~Mutex()
bool
xpcc::rtos::Mutex::acquire(uint32_t timeout)
{
return mutex.timed_lock(
boost::posix_time::milliseconds(timeout));
return mutex.try_lock_for(std::chrono::milliseconds(timeout));
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@
# error "Don't include this file directly, use <xpcc/processing/rtos/mutex.hpp>"
#endif

#include <boost/thread/mutex.hpp>
#include <boost/thread/locks.hpp>
#include <mutex>

namespace xpcc
{
Expand All @@ -48,7 +47,7 @@ namespace xpcc
/**
* \brief Mutex
*
* \ingroup boost_rtos
* \ingroup stdlib_rtos
*/
class Mutex
{
Expand Down Expand Up @@ -85,19 +84,19 @@ namespace xpcc
Mutex&
operator = (const Mutex& other);

boost::timed_mutex mutex;
std::timed_mutex mutex;
};

/**
* Implements a RAII-style locking.
*
* Locks the Mutex when created and unlocks it on destruction.
*/
class MutexGuard : boost::lock_guard<boost::timed_mutex>
class MutexGuard : std::lock_guard<std::timed_mutex>
{
public:
MutexGuard(Mutex& m) :
boost::lock_guard<boost::timed_mutex>(m.mutex)
std::lock_guard<std::timed_mutex>(m.mutex)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#include <stdint.h>
#include <deque>

#include <boost/thread/mutex.hpp>
#include <mutex>
#include <xpcc/container/deque.hpp>

namespace xpcc
Expand Down Expand Up @@ -101,7 +101,7 @@ namespace xpcc
Queue&
operator = (const Queue& other);

mutable boost::timed_mutex mutex;
mutable std::timed_mutex mutex;

uint32_t maxSize;
std::deque<T> deque;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
# error "Don't use this file directly, use 'queue.hpp' instead!"
#endif

#include <chrono>

template <typename T>
xpcc::rtos::Queue<T>::Queue(uint32_t length) :
maxSize(length)
Expand All @@ -47,15 +49,15 @@ template <typename T>
std::size_t
xpcc::rtos::Queue<T>::getSize() const
{
boost::lock_guard<boost::timed_mutex> lock(mutex);
std::lock_guard<std::timed_mutex> lock(mutex);
deque.size();
}

template <typename T>
bool
xpcc::rtos::Queue<T>::append(const T& item, uint32_t timeout = -1)
{
if (!mutex.timed_lock(boost::posix_time::milliseconds(timeout)) ||
if (!mutex.try_lock_for(std::chrono::milliseconds(timeout)) ||
deque.size() >= maxSize) {
return false;
}
Expand All @@ -68,7 +70,7 @@ template <typename T>
bool
xpcc::rtos::Queue<T>::prepend(const T& item, uint32_t timeout = -1)
{
if (!mutex.timed_lock(boost::posix_time::milliseconds(timeout))) {
if (!mutex.try_lock_for(std::chrono::milliseconds(timeout))) {
return false;
}

Expand All @@ -88,7 +90,7 @@ template <typename T>
bool
xpcc::rtos::Queue<T>::peek(T& item, uint32_t timeout = -1) const
{
if (!mutex.timed_lock(boost::posix_time::milliseconds(timeout))) {
if (!mutex.try_lock_for(std::chrono::milliseconds(timeout))) {
return false;
}

Expand All @@ -107,7 +109,7 @@ template <typename T>
bool
xpcc::rtos::Queue<T>::get(T& item, uint32_t timeout = -1)
{
if (!mutex.timed_lock(boost::posix_time::milliseconds(timeout))) {
if (!mutex.try_lock_for(std::chrono::milliseconds(timeout))) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ xpcc::rtos::Scheduler::schedule()
{
// Threads are started and will do all the work. Just
// sleep a bit here when there is nothing else to do.
boost::this_thread::sleep(boost::posix_time::milliseconds(1000));
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
# error "Don't include this file directly, use <xpcc/processing/rtos/scheduler.hpp>"
#endif

#include <boost/thread/thread.hpp>
#include <thread>

namespace xpcc
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
// ----------------------------------------------------------------------------

#include "../semaphore.hpp"
#include <chrono>

// ----------------------------------------------------------------------------
xpcc::rtos::Semaphore::Semaphore(uint32_t max, uint32_t initial) :
Expand All @@ -40,11 +41,10 @@ xpcc::rtos::Semaphore::Semaphore(uint32_t max, uint32_t initial) :
bool
xpcc::rtos::Semaphore::acquire(uint32_t timeout)
{
boost::unique_lock<boost::mutex> lock(mutex);
std::unique_lock<std::mutex> lock(mutex);
while (count == 0)
{
if (!condition.timed_wait(lock,
boost::posix_time::milliseconds(timeout))) {
if (condition.wait_for(lock, std::chrono::milliseconds(timeout)) == std::cv_status::timeout) {
return false;
}
}
Expand All @@ -56,7 +56,7 @@ xpcc::rtos::Semaphore::acquire(uint32_t timeout)
void
xpcc::rtos::Semaphore::release()
{
boost::unique_lock<boost::mutex> lock(mutex);
std::unique_lock<std::mutex> lock(mutex);

if (count < maxCount) {
++count;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
# error "Don't include this file directly, use <xpcc/processing/rtos/semaphore.hpp>"
#endif

#include <boost/thread/mutex.hpp>
#include <boost/thread/condition_variable.hpp>
#include <mutex>
#include <condition_variable>

namespace xpcc
{
Expand Down Expand Up @@ -125,10 +125,10 @@ namespace xpcc
//
// Any code that reads or writes the count_ data must hold a lock
// on the mutex.
mutable boost::mutex mutex;
mutable std::mutex mutex;

// Code that increments count_ must notify the condition variable.
mutable boost::condition_variable condition;
mutable std::condition_variable condition;

};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,5 @@ xpcc::rtos::Thread::~Thread()
void
xpcc::rtos::Thread::start()
{
this->thread.reset(new boost::thread(boost::bind(&Thread::run, this)));
this->thread.reset(new std::thread(&Thread::run, this));
}
Loading

0 comments on commit 5ef8009

Please sign in to comment.