summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--NEWS1
-rw-r--r--raul.pc.in2
-rw-r--r--raul/Thread.hpp49
-rw-r--r--wscript45
4 files changed, 49 insertions, 48 deletions
diff --git a/NEWS b/NEWS
index de79e0f..44047f6 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,7 @@ raul (9999) unstable;
* Remove glib dpendency
* Remove OSC and RDF library dependent code
+ * Remove remaining library code, now header only
* Improve RingBuffer
* Add ThreadVar, a thread-specific variable class
* Implement Semaphore for Windows
diff --git a/raul.pc.in b/raul.pc.in
index 4f641af..dec7559 100644
--- a/raul.pc.in
+++ b/raul.pc.in
@@ -6,5 +6,5 @@ includedir=@INCLUDEDIR@
Name: raul
Version: @RAUL_VERSION@
Description: A C++ convenience library for realtime audio applications
-Libs: -L${libdir} -lraul @RAUL_PC_LIBS@
+Libs: @RAUL_PC_LIBS@
Cflags: -I${includedir}
diff --git a/raul/Thread.hpp b/raul/Thread.hpp
index fa5a3cb..ddd771b 100644
--- a/raul/Thread.hpp
+++ b/raul/Thread.hpp
@@ -33,26 +33,48 @@ struct ThreadImpl;
class Thread : Noncopyable
{
public:
- virtual ~Thread();
+ virtual ~Thread() {
+ join();
+ }
/** Start the thread if it is not already running.
*
* This is separate from construction to prevent race conditions during
* construction of derived classes.
*/
- virtual void start();
+ virtual void start() {
+ if (!_thread_exists) {
+ pthread_attr_t attr;
+ pthread_attr_init(&attr);
+ pthread_attr_setstacksize(&attr, 1500000);
+
+ pthread_create(&_pthread, &attr, _static_run, this);
+ _thread_exists = true;
+ }
+ }
/** Stop the thread and block the caller until the thread exits.
*
* This sets _exit_flag to true, derived classes must ensure they actually
* exit when this occurs.
*/
- virtual void join();
+ virtual void join() {
+ if (_thread_exists) {
+ _exit_flag = true;
+ pthread_join(_pthread, NULL);
+ _thread_exists = false;
+ }
+ }
/** Set the scheduling policy for this thread.
* @return True on success.
*/
- virtual bool set_scheduling(bool realtime, unsigned priority);
+ virtual bool set_scheduling(bool realtime, unsigned priority) {
+ sched_param sp;
+ sp.sched_priority = priority;
+ const int policy = realtime ? SCHED_FIFO : SCHED_OTHER;
+ return !pthread_setschedparam(_pthread, policy, &sp);
+ }
protected:
/** Construct a thread.
@@ -60,7 +82,11 @@ protected:
* Note this does not actually start a thread to prevent race conditions
* during construction. To actually begin execution, call start().
*/
- explicit Thread();
+ explicit Thread()
+ : _thread_exists(false)
+ , _exit_flag(false)
+ {}
+
/** Thread function to execute.
*
@@ -73,10 +99,15 @@ protected:
virtual void _run() {}
private:
- static void* _static_run(void* me);
-
- ThreadImpl* _impl;
- bool _thread_exists;
+ static void* _static_run(void* thread) {
+ Thread* me = static_cast<Thread*>(thread);
+ me->_run();
+ me->_thread_exists = false;
+ return NULL;
+ }
+
+ pthread_t _pthread;
+ bool _thread_exists;
protected:
bool _exit_flag;
diff --git a/wscript b/wscript
index 78cab4c..031750f 100644
--- a/wscript
+++ b/wscript
@@ -1,4 +1,5 @@
#!/usr/bin/env python
+import os
import subprocess
import waflib.Options as Options
import waflib.extras.autowaf as autowaf
@@ -64,6 +65,10 @@ def configure(conf):
autowaf.check_header(conf, 'cxx', 'boost/shared_ptr.hpp')
autowaf.check_header(conf, 'cxx', 'boost/weak_ptr.hpp')
+ # TODO: Version includes and use autowaf.set_lib_env() here
+ conf.env['INCLUDES_RAUL'] = [os.path.abspath(top) + '/raul']
+
+ autowaf.define(conf, 'RAUL_VERSION', RAUL_VERSION)
conf.write_config_header('raul_config.h', remove=False)
autowaf.display_msg(conf, "Unit tests", str(conf.env.BUILD_TESTS))
@@ -96,32 +101,10 @@ def build(bld):
autowaf.build_pc(bld, 'RAUL', RAUL_VERSION, '',
'GLIB GTHREAD', subst_dict=dict)
- lib_source = '''
- src/Thread.cpp
- '''
-
framework = ''
if Options.platform == 'darwin':
framework = ' CoreServices '
- def set_defines(obj):
- if bld.env.RAUL_CPP0x:
- obj.defines = ['RAUL_CPP0x']
-
- # Library
- obj = bld(features = 'cxx cxxshlib',
- export_includes = ['.'],
- source = lib_source,
- includes = ['.', './src'],
- name = 'libraul',
- target = 'raul',
- uselib = 'GLIB GTHREAD',
- lib = ['pthread'],
- framework = framework,
- install_path = '${LIBDIR}',
- vnum = RAUL_LIB_VERSION)
- set_defines(obj);
-
if bld.env.BUILD_TESTS:
test_libs = ['pthread', 'rt']
test_cxxflags = []
@@ -129,19 +112,6 @@ def build(bld):
test_libs += ['gcov']
test_cxxflags += ['-fprofile-arcs', '-ftest-coverage']
- # Static library (for unit test code coverage)
- obj = bld(features = 'cxx cxxstlib',
- source = lib_source,
- includes = ['.', './src'],
- lib = test_libs,
- name = 'libraul_static',
- target = 'raul_static',
- uselib = 'GLIB GTHREAD',
- framework = framework,
- install_path = '',
- cxxflags = test_cxxflags)
- set_defines(obj);
-
# Unit tests
for i in tests.split():
obj = bld(features = 'cxx cxxprogram',
@@ -154,13 +124,12 @@ def build(bld):
target = i,
install_path = '',
cxxflags = test_cxxflags)
- set_defines(obj);
+ if bld.env.RAUL_CPP0x:
+ obj.defines = ['RAUL_CPP0x']
# Documentation
autowaf.build_dox(bld, 'RAUL', RAUL_VERSION, top, out)
- bld.add_post_fun(autowaf.run_ldconfig)
-
def test(ctx):
autowaf.pre_test(ctx, APPNAME, dirs=['.', 'src', 'test'])
autowaf.run_tests(ctx, APPNAME, tests.split(), dirs=['.', 'src', 'test'])