Skip to content

Commit

Permalink
COMMON: Replace Boost atomic with C++11 atomic
Browse files Browse the repository at this point in the history
  • Loading branch information
vkremianskii authored and DrMcCoy committed Mar 16, 2019
1 parent 61c5034 commit b568a79
Show file tree
Hide file tree
Showing 11 changed files with 16 additions and 71 deletions.
1 change: 0 additions & 1 deletion BUILDDEP.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ Build-time library dependencies
- Boost.Uuid
- Boost.Smart_Ptr
- Boost.ScopeExit
- Boost.Atomic
- Boost.Locale
- Boost.Thread

Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ find_package(ZLIB REQUIRED)
include_directories(${ZLIB_INCLUDE_DIRS})
list(APPEND PHAETHON_LIBRARIES ${ZLIB_LIBRARIES})

find_package(Boost COMPONENTS system filesystem regex date_time atomic locale chrono thread REQUIRED)
find_package(Boost COMPONENTS system filesystem regex date_time locale chrono thread REQUIRED)

include_directories(${Boost_INCLUDE_DIRS})
list(APPEND PHAETHON_LIBRARIES ${Boost_LIBRARIES})
Expand Down
1 change: 0 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ LIBSL_BOOST = $(BOOST_SYSTEM_LDFLAGS) $(BOOST_SYSTEM_LIBS) \
$(BOOST_REGEX_LDFLAGS) $(BOOST_REGEX_LIBS) \
$(BOOST_DATE_TIME_LDFLAGS) $(BOOST_DATE_TIME_LIBS) \
$(BOOST_CHRONO_LDFLAGS) $(BOOST_CHRONO_LIBS) \
$(BOOST_ATOMIC_LDFLAGS) $(BOOST_ATOMIC_LIBS) \
$(BOOST_LOCALE_LDFLAGS) $(BOOST_LOCALE_LIBS) \
$(BOOST_THREAD_LDFLAGS) $(BOOST_THREAD_LIBS)
LIBSL = $(LIBSL_PHAETHON) $(LIBSL_GENERAL) $(LIBSL_GRAPHIC) \
Expand Down
1 change: 0 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ BOOST_BIND
BOOST_UUID
BOOST_SMART_PTR
BOOST_SCOPE_EXIT
BOOST_ATOMIC
BOOST_LOCALE
BOOST_THREAD

Expand Down
2 changes: 1 addition & 1 deletion dists/debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Source: phaethon
Section: misc
Priority: optional
Maintainer: Sven Hesse <drmccoy@drmccoy.de>
Build-Depends: debhelper (>= 9), dh-autoreconf, autotools-dev, autoconf (>= 2.65), gettext, zlib1g-dev (>= 1:1.2.3.4), liblzma-dev (>= 5.0.5), libboost-dev (>= 1.53), libboost-atomic-dev (>= 1.53), libboost-date-time-dev (>= 1.53), libboost-filesystem-dev (>= 1.53), libboost-locale-dev (>= 1.53), libboost-regex-dev (>= 1.53), libboost-system-dev (>= 1.53), libboost-chrono-dev (>= 1.53), libboost-thread-dev (>= 1.53), libopenal-dev (>= 1:1.12), libmad0-dev (>= 0.15.1b), libogg-dev (>= 1.2.0), libvorbis-dev (>= 1.3.1), libfaad-dev (>= 2.7), libxvidcore-dev (>= 2:1.2.2), qtbase5-dev (>= 5.7.1), libqt5gui5 (>= 5.7.1), libqt5widgets5 (>= 5.7.1)
Build-Depends: debhelper (>= 9), dh-autoreconf, autotools-dev, autoconf (>= 2.65), gettext, zlib1g-dev (>= 1:1.2.3.4), liblzma-dev (>= 5.0.5), libboost-dev (>= 1.53), libboost-date-time-dev (>= 1.53), libboost-filesystem-dev (>= 1.53), libboost-locale-dev (>= 1.53), libboost-regex-dev (>= 1.53), libboost-system-dev (>= 1.53), libboost-chrono-dev (>= 1.53), libboost-thread-dev (>= 1.53), libopenal-dev (>= 1:1.12), libmad0-dev (>= 0.15.1b), libogg-dev (>= 1.2.0), libvorbis-dev (>= 1.3.1), libfaad-dev (>= 2.7), libxvidcore-dev (>= 2:1.2.2), qtbase5-dev (>= 5.7.1), libqt5gui5 (>= 5.7.1), libqt5widgets5 (>= 5.7.1)
Standards-Version: 3.9.6
Homepage: https://xoreos.org/

Expand Down
2 changes: 1 addition & 1 deletion dists/fedora/phaethon.spec
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ BuildRequires: qt5-devel qt5-qtbase-devel
BuildRequires: qt5-qtbase-gui

# Boost dependencies.
BuildRequires: boost-devel, boost-system, boost-filesystem, boost-atomic
BuildRequires: boost-devel, boost-system, boost-filesystem
BuildRequires: boost-regex, boost-locale, boost-date-time boost-chrono
BuildRequires: boost-thread

Expand Down
52 changes: 0 additions & 52 deletions src/common/atomic.h

This file was deleted.

1 change: 0 additions & 1 deletion src/common/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ src_common_libcommon_la_SOURCES += \
src/common/cosinetables.h \
src/common/fft.h \
src/common/mdct.h \
src/common/atomic.h \
src/common/mutex.h \
src/common/thread.h \
src/common/binsearch.h \
Expand Down
16 changes: 8 additions & 8 deletions src/common/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Thread::~Thread() {
}

bool Thread::createThread(const UString &name) {
if (_threadRunning.load(boost::memory_order_relaxed)) {
if (_threadRunning.load(std::memory_order_relaxed)) {
if (_name == name) {
warning("Thread::createThread(): Thread \"%s\" already running", _name.c_str());
return true;
Expand All @@ -60,23 +60,23 @@ bool Thread::createThread(const UString &name) {
}

bool Thread::destroyThread() {
if (!_threadRunning.load(boost::memory_order_seq_cst)) {
if (!_threadRunning.load(std::memory_order_seq_cst)) {
if (_thread.joinable())
_thread.join();

return true;
}

// Signal the thread that it should die
_killThread.store(true, boost::memory_order_seq_cst);
_killThread.store(true, std::memory_order_seq_cst);

// Wait a whole second for the thread to finish on its own
for (int i = 0; _threadRunning.load(boost::memory_order_seq_cst) && (i < 100); i++)
for (int i = 0; _threadRunning.load(std::memory_order_seq_cst) && (i < 100); i++)
std::this_thread::sleep_for(std::chrono::duration<int, std::milli>(10));

_killThread.store(false, boost::memory_order_seq_cst);
_killThread.store(false, std::memory_order_seq_cst);

const bool stillRunning = _threadRunning.load(boost::memory_order_seq_cst);
const bool stillRunning = _threadRunning.load(std::memory_order_seq_cst);

/* Clean up the thread if it's not still running. If the thread is still running,
* this would block, potentially indefinitely, so we leak instead in that case.
Expand All @@ -100,13 +100,13 @@ int Thread::threadHelper(void *obj) {
Thread *thread = static_cast<Thread *>(obj);

// The thread is running.
thread->_threadRunning.store(true, boost::memory_order_relaxed);
thread->_threadRunning.store(true, std::memory_order_relaxed);

// Run the thread
thread->threadMethod();

// Thread thread is not running.
thread->_threadRunning.store(false, boost::memory_order_relaxed);
thread->_threadRunning.store(false, std::memory_order_relaxed);

return 0;
}
Expand Down
7 changes: 4 additions & 3 deletions src/common/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@
#include <thread>
#endif

#include <atomic>

#include <boost/noncopyable.hpp>

#include "src/common/atomic.h"
#include "src/common/ustring.h"

namespace Common {
Expand All @@ -48,13 +49,13 @@ class Thread : boost::noncopyable {
bool destroyThread();

protected:
boost::atomic<bool> _killThread;
std::atomic<bool> _killThread;

private:
std::thread _thread;
Common::UString _name;

boost::atomic<bool> _threadRunning;
std::atomic<bool> _threadRunning;

virtual void threadMethod() = 0;

Expand Down
2 changes: 1 addition & 1 deletion src/sound/sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ void SoundManager::freeChannel(size_t channel) {
}

void SoundManager::threadMethod() {
while (!_killThread.load(boost::memory_order_relaxed)) {
while (!_killThread.load(std::memory_order_relaxed)) {
update();
_needUpdate.wait(100);
}
Expand Down

0 comments on commit b568a79

Please sign in to comment.