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 () endif ()
set(BOOST_COMPONENTS system filesystem program_options thread) set(BOOST_COMPONENTS system filesystem program_options)
if(WIN32) if(WIN32)
set(BOOST_COMPONENTS ${BOOST_COMPONENTS} locale) set(BOOST_COMPONENTS ${BOOST_COMPONENTS} locale)
endif(WIN32) endif(WIN32)

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

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

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

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

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

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

@ -13,6 +13,6 @@ set(OSG_FFMPEG_VIDEOPLAYER_SOURCE_FILES
include_directories(${FFMPEG_INCLUDE_DIRS}) include_directories(${FFMPEG_INCLUDE_DIRS})
add_library(${OSG_FFMPEG_VIDEOPLAYER_LIBRARY} STATIC ${OSG_FFMPEG_VIDEOPLAYER_SOURCE_FILES}) 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}) link_directories(${CMAKE_CURRENT_BINARY_DIR})

@ -1,6 +1,9 @@
#include "videostate.hpp" #include "videostate.hpp"
#include <iostream> #include <iostream>
#include <mutex>
#include <cassert>
#include <chrono>
#include <osg/Texture2D> #include <osg/Texture2D>
@ -116,7 +119,7 @@ void PacketQueue::put(AVPacket *pkt)
int PacketQueue::get(AVPacket *pkt, VideoState *is) 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) while(!is->mQuit)
{ {
AVPacketList *pkt1 = this->first_pkt; AVPacketList *pkt1 = this->first_pkt;
@ -240,7 +243,7 @@ void VideoState::video_display(VideoPicture *vp)
void VideoState::video_refresh() 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) if(this->pictq_size == 0)
return; return;
@ -293,9 +296,9 @@ int VideoState::queue_picture(AVFrame *pFrame, double pts)
/* wait until we have a new pic */ /* 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) 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) if(this->mQuit)
return -1; return -1;
@ -508,7 +511,7 @@ void VideoState::decode_thread_loop(VideoState *self)
if((self->audio_st && self->audioq.size > MAX_AUDIOQ_SIZE) || if((self->audio_st && self->audioq.size > MAX_AUDIOQ_SIZE) ||
(self->video_st && self->videoq.size > MAX_VIDEOQ_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; continue;
} }
@ -591,7 +594,7 @@ int VideoState::stream_open(int stream_index, AVFormatContext *pFormatCtx)
codecCtx->get_buffer = our_get_buffer; codecCtx->get_buffer = our_get_buffer;
codecCtx->release_buffer = our_release_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; break;
default: 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() void VideoState::deinit()
@ -783,7 +786,7 @@ ExternalClock::ExternalClock()
void ExternalClock::setPaused(bool paused) void ExternalClock::setPaused(bool paused)
{ {
boost::mutex::scoped_lock lock(mMutex); std::lock_guard<std::mutex> lock(mMutex);
if (mPaused == paused) if (mPaused == paused)
return; return;
if (paused) if (paused)
@ -797,7 +800,7 @@ void ExternalClock::setPaused(bool paused)
uint64_t ExternalClock::get() uint64_t ExternalClock::get()
{ {
boost::mutex::scoped_lock lock(mMutex); std::lock_guard<std::mutex> lock(mMutex);
if (mPaused) if (mPaused)
return mPausedAt; return mPausedAt;
else else
@ -806,7 +809,7 @@ uint64_t ExternalClock::get()
void ExternalClock::set(uint64_t time) void ExternalClock::set(uint64_t time)
{ {
boost::mutex::scoped_lock lock(mMutex); std::lock_guard<std::mutex> lock(mMutex);
mTimeBase = av_gettime() - time; mTimeBase = av_gettime() - time;
mPausedAt = time; mPausedAt = time;
} }

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

Loading…
Cancel
Save