Replace boost threading with c++11

Mostly straightforward port, some refactoring was needed in StreamThread to workaround thread::interrupt not being available.
c++11
scrawl 10 years ago
parent c5ae95aedd
commit b2a1c940b0

@ -190,7 +190,7 @@ if (HAVE_UNORDERED_MAP)
endif ()
set(BOOST_COMPONENTS system filesystem program_options thread)
set(BOOST_COMPONENTS system filesystem program_options)
if(WIN32)
set(BOOST_COMPONENTS ${BOOST_COMPONENTS} locale)
endif(WIN32)

@ -1,7 +1,5 @@
#include "idcompletionmanager.hpp"
#include <boost/make_shared.hpp>
#include <QCompleter>
#include "../../view/widget/completerpopup.hpp"

@ -117,7 +117,6 @@ include_directories(${SOUND_INPUT_INCLUDES})
target_link_libraries(openmw
${OPENSCENEGRAPH_LIBRARIES}
${Boost_SYSTEM_LIBRARY}
${Boost_THREAD_LIBRARY}
${Boost_FILESYSTEM_LIBRARY}
${Boost_PROGRAM_OPTIONS_LIBRARY}
${OPENAL_LIBRARY}

@ -9,8 +9,6 @@
#include <stdint.h>
#include <boost/function.hpp>
#include <boost/make_shared.hpp>
#include <components/misc/utf8stream.hpp>
namespace MWGui

@ -2,7 +2,6 @@
#include <map>
#include <sstream>
#include <boost/make_shared.hpp>
#include <MyGUI_LanguageManager.h>

@ -1,14 +1,16 @@
#include <algorithm>
#include <stdexcept>
#include <cstring>
#include <iostream>
#include <vector>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <stdint.h>
#include <components/vfs/manager.hpp>
#include <boost/thread.hpp>
#include "openal_output.hpp"
#include "sound_decoder.hpp"
#include "sound.hpp"
@ -211,24 +213,32 @@ const ALfloat OpenAL_SoundStream::sBufferLength = 0.125f;
struct OpenAL_Output::StreamThread {
typedef std::vector<OpenAL_SoundStream*> StreamVec;
StreamVec mStreams;
boost::recursive_mutex mMutex;
boost::thread mThread;
std::mutex mMutex;
std::thread mThread;
std::condition_variable mCondition;
volatile bool mExit;
StreamThread()
: mThread(boost::ref(*this))
: mThread(std::ref(*this))
, mExit(false)
{
}
~StreamThread()
{
mThread.interrupt();
mMutex.lock();
mExit = true;
mMutex.unlock();
mCondition.notify_one();
mThread.join();
}
// boost::thread entry point
// std::thread entry point
void operator()()
{
while(1)
while(!mExit)
{
mMutex.lock();
std::unique_lock<std::mutex> lock (mMutex);
StreamVec::iterator iter = mStreams.begin();
while(iter != mStreams.end())
{
@ -237,8 +247,7 @@ struct OpenAL_Output::StreamThread {
else
++iter;
}
mMutex.unlock();
boost::this_thread::sleep(boost::posix_time::milliseconds(50));
mCondition.wait_for(lock, std::chrono::milliseconds(50));
}
}

@ -173,7 +173,6 @@ add_library(components STATIC ${COMPONENT_FILES} ${MOC_SRCS} ${ESM_UI_HDR})
target_link_libraries(components
${Boost_SYSTEM_LIBRARY}
${Boost_FILESYSTEM_LIBRARY}
${Boost_THREAD_LIBRARY}
${Boost_PROGRAM_OPTIONS_LIBRARY}
${OPENSCENEGRAPH_LIBRARIES}
${BULLET_LIBRARIES}

@ -13,6 +13,6 @@ set(OSG_FFMPEG_VIDEOPLAYER_SOURCE_FILES
include_directories(${FFMPEG_INCLUDE_DIRS})
add_library(${OSG_FFMPEG_VIDEOPLAYER_LIBRARY} STATIC ${OSG_FFMPEG_VIDEOPLAYER_SOURCE_FILES})
target_link_libraries(${OSG_FFMPEG_VIDEOPLAYER_LIBRARY} ${FFMPEG_LIBRARIES} ${Boost_THREAD_LIBRARY})
target_link_libraries(${OSG_FFMPEG_VIDEOPLAYER_LIBRARY} ${FFMPEG_LIBRARIES})
link_directories(${CMAKE_CURRENT_BINARY_DIR})

@ -1,6 +1,9 @@
#include "videostate.hpp"
#include <iostream>
#include <mutex>
#include <cassert>
#include <chrono>
#include <osg/Texture2D>
@ -116,7 +119,7 @@ void PacketQueue::put(AVPacket *pkt)
int PacketQueue::get(AVPacket *pkt, VideoState *is)
{
boost::unique_lock<boost::mutex> lock(this->mutex);
std::unique_lock<std::mutex> lock(this->mutex);
while(!is->mQuit)
{
AVPacketList *pkt1 = this->first_pkt;
@ -240,7 +243,7 @@ void VideoState::video_display(VideoPicture *vp)
void VideoState::video_refresh()
{
boost::mutex::scoped_lock lock(this->pictq_mutex);
std::lock_guard<std::mutex> lock(this->pictq_mutex);
if(this->pictq_size == 0)
return;
@ -293,9 +296,9 @@ int VideoState::queue_picture(AVFrame *pFrame, double pts)
/* wait until we have a new pic */
{
boost::unique_lock<boost::mutex> lock(this->pictq_mutex);
std::unique_lock<std::mutex> lock(this->pictq_mutex);
while(this->pictq_size >= VIDEO_PICTURE_QUEUE_SIZE && !this->mQuit)
this->pictq_cond.timed_wait(lock, boost::posix_time::milliseconds(1));
this->pictq_cond.wait_for(lock, std::chrono::milliseconds(1));
}
if(this->mQuit)
return -1;
@ -508,7 +511,7 @@ void VideoState::decode_thread_loop(VideoState *self)
if((self->audio_st && self->audioq.size > MAX_AUDIOQ_SIZE) ||
(self->video_st && self->videoq.size > MAX_VIDEOQ_SIZE))
{
boost::this_thread::sleep(boost::posix_time::milliseconds(10));
std::this_thread::sleep_for(std::chrono::milliseconds(10));
continue;
}
@ -591,7 +594,7 @@ int VideoState::stream_open(int stream_index, AVFormatContext *pFormatCtx)
codecCtx->get_buffer = our_get_buffer;
codecCtx->release_buffer = our_release_buffer;
this->video_thread = boost::thread(video_thread_loop, this);
this->video_thread = std::thread(video_thread_loop, this);
break;
default:
@ -673,7 +676,7 @@ void VideoState::init(std::shared_ptr<std::istream> inputstream, const std::stri
}
this->parse_thread = boost::thread(decode_thread_loop, this);
this->parse_thread = std::thread(decode_thread_loop, this);
}
void VideoState::deinit()
@ -783,7 +786,7 @@ ExternalClock::ExternalClock()
void ExternalClock::setPaused(bool paused)
{
boost::mutex::scoped_lock lock(mMutex);
std::lock_guard<std::mutex> lock(mMutex);
if (mPaused == paused)
return;
if (paused)
@ -797,7 +800,7 @@ void ExternalClock::setPaused(bool paused)
uint64_t ExternalClock::get()
{
boost::mutex::scoped_lock lock(mMutex);
std::lock_guard<std::mutex> lock(mMutex);
if (mPaused)
return mPausedAt;
else
@ -806,7 +809,7 @@ uint64_t ExternalClock::get()
void ExternalClock::set(uint64_t time)
{
boost::mutex::scoped_lock lock(mMutex);
std::lock_guard<std::mutex> lock(mMutex);
mTimeBase = av_gettime() - time;
mPausedAt = time;
}

@ -3,7 +3,10 @@
#include <stdint.h>
#include <boost/thread.hpp>
#include <thread>
#include <mutex>
#include <vector>
#include <condition_variable>
#include <osg/ref_ptr>
namespace osg
@ -43,7 +46,7 @@ struct ExternalClock
uint64_t mPausedAt;
bool mPaused;
boost::mutex mMutex;
std::mutex mMutex;
void setPaused(bool paused);
uint64_t get();
@ -62,8 +65,8 @@ struct PacketQueue {
int nb_packets;
int size;
boost::mutex mutex;
boost::condition_variable cond;
std::mutex mutex;
std::condition_variable cond;
void put(AVPacket *pkt);
int get(AVPacket *pkt, VideoState *is);
@ -141,11 +144,11 @@ struct VideoState {
VideoPicture pictq[VIDEO_PICTURE_ARRAY_SIZE];
AVFrame* rgbaFrame; // used as buffer for the frame converted from its native format to RGBA
int pictq_size, pictq_rindex, pictq_windex;
boost::mutex pictq_mutex;
boost::condition_variable pictq_cond;
std::mutex pictq_mutex;
std::condition_variable pictq_cond;
boost::thread parse_thread;
boost::thread video_thread;
std::thread parse_thread;
std::thread video_thread;
volatile bool mSeekRequested;
uint64_t mSeekPos;

Loading…
Cancel
Save