diff options
author | David Robillard <d@drobilla.net> | 2018-09-16 19:38:29 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2018-09-16 19:38:29 +0200 |
commit | 3b43c3b85392aaf5d52a6d4e35bff49656321b20 (patch) | |
tree | 986bf30114abe79da089cabbe207631bd5343b87 | |
parent | 95dd2be3d15e81a3f958d42b14140f53886f1d18 (diff) | |
download | raul-3b43c3b85392aaf5d52a6d4e35bff49656321b20.tar.gz raul-3b43c3b85392aaf5d52a6d4e35bff49656321b20.tar.bz2 raul-3b43c3b85392aaf5d52a6d4e35bff49656321b20.zip |
Use std::thread in ringbuffer test
-rw-r--r-- | test/ringbuffer_test.cpp | 34 | ||||
-rw-r--r-- | wscript | 1 |
2 files changed, 13 insertions, 22 deletions
diff --git a/test/ringbuffer_test.cpp b/test/ringbuffer_test.cpp index ee80e6a..7fc4042 100644 --- a/test/ringbuffer_test.cpp +++ b/test/ringbuffer_test.cpp @@ -20,6 +20,7 @@ #include <cstring> #include <iostream> #include <string> +#include <thread> #include "raul/RingBuffer.hpp" @@ -57,8 +58,8 @@ cmp_msg(int* msg1, int* msg2) return 1; } -void* -reader(void* arg) +void +reader() { printf("Reader starting\n"); @@ -72,12 +73,12 @@ reader(void* arg) if (n_read != MSG_SIZE * sizeof(int)) { fprintf(stderr, "FAIL: Read size incorrect\n"); ring_error = true; - return NULL; + return; } if (!cmp_msg(ref_msg, read_msg)) { fprintf(stderr, "FAIL: Message %zu is corrupt\n", count); ring_error = true; - return NULL; + return; } start = gen_msg(ref_msg, start); ++count; @@ -85,11 +86,10 @@ reader(void* arg) } printf("Reader finished\n"); - return NULL; } -void* -writer(void* arg) +void +writer() { printf("Writer starting\n"); @@ -101,14 +101,13 @@ writer(void* arg) if (n_write != MSG_SIZE * sizeof(int)) { fprintf(stderr, "FAIL: Write size incorrect\n"); ring_error = true; - return NULL; + return; } start = gen_msg(write_msg, start); } } printf("Writer finished\n"); - return NULL; } } // namespace @@ -191,20 +190,11 @@ main(int argc, char** argv) ring->reset(); - pthread_t reader_thread; - if (pthread_create(&reader_thread, NULL, reader, NULL)) { - fprintf(stderr, "Failed to create reader thread\n"); - return 1; - } - - pthread_t writer_thread; - if (pthread_create(&writer_thread, NULL, writer, NULL)) { - fprintf(stderr, "Failed to create writer thread\n"); - return 1; - } + std::thread reader_thread(reader); + std::thread writer_thread(writer); - pthread_join(reader_thread, NULL); - pthread_join(writer_thread, NULL); + reader_thread.join(); + writer_thread.join(); if (ring_error) { fprintf(stderr, "FAIL: Error occurred\n"); @@ -43,6 +43,7 @@ def configure(conf): conf.load('compiler_cxx', cache=True) conf.load('autowaf', cache=True) autowaf.set_c_lang(conf, 'c99') + autowaf.set_cxx_lang(conf, 'c++11') if conf.env.DEST_OS == 'darwin': conf.check(framework_name='CoreServices') |