Skip to content

Commit

Permalink
migrate to c++11
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Blechmann <[email protected]>
  • Loading branch information
timblechmann committed Aug 20, 2013
1 parent ada02f2 commit 736145e
Show file tree
Hide file tree
Showing 17 changed files with 42 additions and 71 deletions.
13 changes: 4 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ if(CMAKE_COMPILER_IS_GNUCXX)
endif()

option(SC_SYMLINK_CLASSLIB "Place a symlink of SCCLassLibrary instead of copying" OFF)
option(SC_CPP11 "Compile in C++11 mode" OFF)

option(SYSTEM_BOOST "Use boost libraries from system" OFF)
option(SYSTEM_YAMLCPP "Use yaml-cpp library from system" ON)
Expand Down Expand Up @@ -225,11 +224,9 @@ if (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
endif()

if (SC_CPP11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
if(CMAKE_COMPILER_IS_CLANG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
if(CMAKE_COMPILER_IS_CLANG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
endif()

if(FORTIFY)
Expand All @@ -243,9 +240,7 @@ if (CMAKE_COMPILER_IS_INTEL AND NOT WIN32)
if (SSE)
add_definitions(-mia32)
endif()
if (SC_CPP11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

# disable warnings
add_definitions(-diag-disable 170) # pointer points outside of underlying object ... used heavily in sclang
Expand Down
26 changes: 2 additions & 24 deletions common/SC_Lock.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,43 +22,21 @@
#ifndef _SC_Lock_
#define _SC_Lock_

#if __cplusplus < 201103L
#include <boost/chrono.hpp>
#include <boost/thread/condition_variable.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread.hpp>

typedef boost::mutex SC_Lock;
typedef boost::timed_mutex timed_mutex;
using boost::lock_guard;
using boost::unique_lock;
using boost::cv_status;
typedef boost::condition_variable_any condition_variable_any;
namespace mutex_chrono = boost::chrono;
using boost::thread;
namespace this_thread = boost::this_thread;
namespace chrono = boost::chrono;
namespace thread_namespace = boost;

#else
#include <chrono>
#include <condition_variable>
#include <mutex>
#include <thread>

typedef std::mutex SC_Lock;
typedef std::timed_mutex timed_mutex;
using std::mutex;
using std::timed_mutex;
using std::lock_guard;
using std::unique_lock;
using std::cv_status;
typedef std::condition_variable_any condition_variable_any;
namespace mutex_chrono = std::chrono;
using std::thread;
namespace this_thread = std::this_thread;
namespace chrono = std::chrono;
namespace thread_namespace = std;

#endif

typedef SC_Lock mutex;

Expand Down
2 changes: 1 addition & 1 deletion lang/LangPrimSource/OSCData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,7 @@ int prQuitInProcessServer(VMGlobals *g, int numArgsPushed)
World *world = gInternalSynthServer.mWorld;
gInternalSynthServer.mWorld = 0;

thread thread(thread_namespace::bind(World_WaitForQuit, world));
thread thread(std::bind(World_WaitForQuit, world));

thread.detach();
}
Expand Down
18 changes: 9 additions & 9 deletions lang/LangPrimSource/PyrSched.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ SC_DLLEXPORT_C void schedInit()
#ifdef SC_DARWIN
syncOSCOffsetWithTimeOfDay();
thread thread(resyncThread);
gResyncThread = thread_namespace::move(thread);
gResyncThread = std::move(thread);

gHostStartNanos = AudioConvertHostTimeToNanos(AudioGetCurrentHostTime());
gElapsedOSCoffset = (int64)(gHostStartNanos * kNanosToOSC) + gHostOSCoffset;
Expand Down Expand Up @@ -288,15 +288,15 @@ double OSCToElapsedTime(int64 oscTime)
return (double)(oscTime - gElapsedOSCoffset) * kOSCtoSecs;
}

void ElapsedTimeToChrono(double elapsed, mutex_chrono::system_clock::time_point & out_time_point)
void ElapsedTimeToChrono(double elapsed, chrono::system_clock::time_point & out_time_point)
{
int64 oscTime = ElapsedTimeToOSC(elapsed);

int64 secs = ((oscTime >> 32) - kSECONDS_FROM_1900_to_1970);
int32 nano_secs = (int32)((oscTime & 0xFFFFFFFF) * kOSCtoNanos);


using namespace mutex_chrono;
using namespace chrono;
#if 0 // TODO: check system_clock precision
system_clock::time_point time_point = system_clock::time_point(seconds(secs) + nanoseconds(nano_secs));
#else
Expand Down Expand Up @@ -445,7 +445,7 @@ static void schedRunFunc()
do {
elapsed = elapsedTime();
if (elapsed >= slotRawFloat(inQueue->slots + 1)) break;
mutex_chrono::system_clock::time_point absTime;
chrono::system_clock::time_point absTime;

ElapsedTimeToChrono(slotRawFloat(inQueue->slots + 1), absTime);

Expand Down Expand Up @@ -609,7 +609,7 @@ static void SC_LinuxSetRealtimePriority(pthread_t thread, int priority)
SC_DLLEXPORT_C void schedRun()
{
thread thread(schedRunFunc);
gSchedThread = thread_namespace::move(thread);
gSchedThread = std::move(thread);

#ifdef SC_DARWIN
int policy;
Expand Down Expand Up @@ -749,8 +749,8 @@ TempoClock::TempoClock(VMGlobals *inVMGlobals, PyrObject* inTempoClockObj,
mQueue->size = 1;
SetInt(&mQueue->count, 0);

thread thread(thread_namespace::bind(&TempoClock::Run, this));
mThread = thread_namespace::move(thread);
thread thread(std::bind(&TempoClock::Run, this));
mThread = std::move(thread);

#ifdef SC_DARWIN
int machprio;
Expand All @@ -777,7 +777,7 @@ TempoClock::TempoClock(VMGlobals *inVMGlobals, PyrObject* inTempoClockObj,
void TempoClock::StopReq()
{
//printf("->TempoClock::StopReq\n");
thread stopThread(thread_namespace::bind(&TempoClock::StopAndDelete, this));
thread stopThread(std::bind(&TempoClock::StopAndDelete, this));
stopThread.detach();

//printf("<-TempoClock::StopReq\n");
Expand Down Expand Up @@ -862,7 +862,7 @@ void* TempoClock::Run()
elapsedBeats = ElapsedBeats();
if (elapsedBeats >= slotRawFloat(mQueue->slots)) break;

mutex_chrono::system_clock::time_point absTime;
chrono::system_clock::time_point absTime;

//printf("event ready at %g . elapsed beats %g\n", mQueue->slots->uf, elapsedBeats);
double wakeTime = BeatsToSecs(slotRawFloat(mQueue->slots));
Expand Down
4 changes: 2 additions & 2 deletions lang/LangPrimSource/PyrSerialPrim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,8 @@ SerialPort::SerialPort(PyrObject* obj, const char* serialport, const Options& op
m_rxErrors[0] = m_rxErrors[1] = 0;

try {
thread thread(thread_namespace::bind(&SerialPort::threadLoop, this));
m_thread = thread_namespace::move(thread);
thread thread(std::bind(&SerialPort::threadLoop, this));
m_thread = std::move(thread);
} catch(std::exception & e) {
close(m_fd);
throw e;
Expand Down
2 changes: 1 addition & 1 deletion lang/LangPrimSource/PyrUnixPrim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ int prString_POpen(struct VMGlobals *g, int numArgsPushed)
return errFailed;
}

thread thread(thread_namespace::bind(string_popen_thread_func, process));
thread thread(std::bind(string_popen_thread_func, process));
thread.detach();

SetInt(a, process->pid);
Expand Down
2 changes: 1 addition & 1 deletion lang/LangPrimSource/SC_ComPort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static void asioFunction()
void startAsioThread()
{
thread asioThread (&asioFunction);
gAsioThread = thread_namespace::move(asioThread);
gAsioThread = std::move(asioThread);
}

void stopAsioThread()
Expand Down
2 changes: 1 addition & 1 deletion lang/LangSource/PyrSched.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ inline int lockLanguageOrQuit(bool shouldBeRunning)
}
} else {
for (;;) {
locked = gLangMutex.try_lock_for(mutex_chrono::seconds(1));
locked = gLangMutex.try_lock_for(chrono::seconds(1));
if (shouldBeRunning == false) {
if (locked)
gLangMutex.unlock();
Expand Down
8 changes: 4 additions & 4 deletions lang/LangSource/SC_TerminalClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ void SC_TerminalClient::onQuit( int exitCode )
stop();
}

extern void ElapsedTimeToChrono(double elapsed, mutex_chrono::system_clock::time_point & out_time_point);
extern void ElapsedTimeToChrono(double elapsed, chrono::system_clock::time_point & out_time_point);

void SC_TerminalClient::tick( const boost::system::error_code& error )
{
Expand All @@ -387,7 +387,7 @@ void SC_TerminalClient::tick( const boost::system::error_code& error )

flush();

mutex_chrono::system_clock::time_point nextAbsTime;
chrono::system_clock::time_point nextAbsTime;
ElapsedTimeToChrono( secs, nextAbsTime );

if (haveNext) {
Expand Down Expand Up @@ -588,8 +588,8 @@ void SC_TerminalClient::initInput()

void SC_TerminalClient::startInput()
{
thread thread(thread_namespace::bind(&SC_TerminalClient::inputThreadFn, this));
mInputThread = thread_namespace::move(thread);
thread thread(std::bind(&SC_TerminalClient::inputThreadFn, this));
mInputThread = std::move(thread);
}

void SC_TerminalClient::endInput()
Expand Down
2 changes: 1 addition & 1 deletion lang/LangSource/SC_TerminalClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class SC_DLLEXPORT SC_TerminalClient : public SC_LanguageClient
boost::asio::io_service mIoService;
private:
boost::asio::io_service::work mWork;
boost::asio::basic_waitable_timer<mutex_chrono::system_clock> mTimer;
boost::asio::basic_waitable_timer<chrono::system_clock> mTimer;

// input io service
boost::asio::io_service mInputService;
Expand Down
4 changes: 1 addition & 3 deletions server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ else()
set(Boost_THREAD_LIBRARY boost_thread)
endif()

if (SC_CPP11)
set(Boost_THREAD_LIBRARY "")
endif()
set(Boost_THREAD_LIBRARY "")

# here we choose who provides us with the FFT lib
if (APPLE)
Expand Down
4 changes: 2 additions & 2 deletions server/plugins/DiskIO_UGens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,10 @@ struct DiskIOThread

void launchThread()
{
using namespace std;
mRunning.store(true);

thread thread(thread_namespace::bind(&DiskIOThread::ioThreadFunc, this));
mThread = thread_namespace::move(thread);
mThread = move( thread( bind(&DiskIOThread::ioThreadFunc, this) ) );
}

bool Write(DiskIOMsg& data)
Expand Down
2 changes: 1 addition & 1 deletion server/plugins/UIUGens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ PluginLoad(UIUGens)
ft = inTable;

thread thread( gstate_update_func );
uiListenThread = thread_namespace::move(thread);
uiListenThread = std::move(thread);
uiListenThread.detach();

DefineSimpleUnit(KeyState);
Expand Down
2 changes: 1 addition & 1 deletion server/plugins/UIUGens.mm
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ void cmdDemoFunc(World *inWorld, void* inUserData, struct sc_msg_iter *args, voi
ft = inTable;

thread thread( gstate_update_func );
uiListenThread = thread_namespace::move(thread);
uiListenThread = std::move(thread);
uiListenThread.detach();

DefineSimpleUnit(KeyState);
Expand Down
6 changes: 3 additions & 3 deletions server/scsynth/SC_ComPort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ class SC_UdpInPort
#ifdef USE_RENDEZVOUS
if (world->mRendezvous) {
thread thread( boost::bind( PublishPortToRendezvous, kSCRendezvous_UDP, sc_htons(mPortNum) ) );
mRendezvousThread = thread_namespace::move(thread);
mRendezvousThread = std::move(thread);
}
#endif

Expand Down Expand Up @@ -406,7 +406,7 @@ class SC_TcpInPort
#ifdef USE_RENDEZVOUS
if (world->mRendezvous) {
thread thread( boost::bind( PublishPortToRendezvous, kSCRendezvous_TCP, sc_htons(inPortNum) ) );
mRendezvousThread = thread_namespace::move(thread);
mRendezvousThread = std::move(thread);
}
#endif

Expand Down Expand Up @@ -467,7 +467,7 @@ static void asioFunction()
void startAsioThread()
{
thread asioThread (&asioFunction);
gAsioThread = thread_namespace::move(asioThread);
gAsioThread = std::move(asioThread);
}

void stopAsioThread()
Expand Down
4 changes: 2 additions & 2 deletions server/scsynth/SC_CoreAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,8 @@ void SC_ScheduledEvent::Perform()
bool SC_AudioDriver::Setup()
{
mRunThreadFlag = true;
thread thread(thread_namespace::bind(&SC_AudioDriver::RunThread, this));
mThread = thread_namespace::move(thread);
thread thread(std::bind(&SC_AudioDriver::RunThread, this));
mThread = std::move(thread);

int numSamples;
double sampleRate;
Expand Down
12 changes: 6 additions & 6 deletions server/scsynth/SC_Time.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,23 @@ const double kSecondsToOSCunits = 4294967296.; // pow(2,32)
const double kMicrosToOSCunits = 4294.967296; // pow(2,32)/1e6
const double kNanosToOSCunits = 4.294967296; // pow(2,32)/1e9

typedef mutex_chrono::system_clock::time_point HostTime;
typedef chrono::system_clock::time_point HostTime;

static inline mutex_chrono::system_clock::time_point getTime()
static inline chrono::system_clock::time_point getTime()
{
return mutex_chrono::system_clock::now();
return chrono::system_clock::now();
}

template <typename TimePoint>
static inline double secondsSinceEpoch(TimePoint const & tp)
{
return mutex_chrono::duration_cast<mutex_chrono::nanoseconds>(tp.time_since_epoch()).count() * 1e-9;
return chrono::duration_cast<chrono::nanoseconds>(tp.time_since_epoch()).count() * 1e-9;
}

template <typename TimePoint>
static inline int64 OSCTime(TimePoint const & tp)
{
using namespace mutex_chrono;
using namespace chrono;
typedef typename TimePoint::duration Duration;
Duration sinceEpoch = tp.time_since_epoch();
seconds secs = duration_cast<seconds>(sinceEpoch);
Expand All @@ -61,7 +61,7 @@ static inline int64 OSCTime(TimePoint const & tp)

static inline int32 timeSeed()
{
using namespace mutex_chrono;
using namespace chrono;
static int32 count = 0;

typedef high_resolution_clock::time_point TimePoint;
Expand Down

0 comments on commit 736145e

Please sign in to comment.