From 4b4da4852482546157abbf8589f2a85bac6c3509 Mon Sep 17 00:00:00 2001 From: jcorgan Date: Sat, 25 Jul 2009 17:39:00 +0000 Subject: [PATCH] Merge r11462:11485 from jcorgan/omni into trunk. Removes dependency on omnithreads from gnuradio-core. Trunk passes distcheck. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@11486 221aa14e-8319-0410-a670-987f0aec2ac5 --- config/grc_gnuradio_core.m4 | 3 +- config/grc_gr_audio_portaudio.m4 | 1 + debian/control | 4 +-- gnuradio-core/src/lib/io/gr_file_sink_base.cc | 9 ++--- gnuradio-core/src/lib/io/gr_file_sink_base.h | 6 ++-- gnuradio-core/src/lib/io/gr_udp_sink.cc | 8 +++-- gnuradio-core/src/lib/io/gr_udp_sink.h | 8 +++-- gnuradio-core/src/lib/io/gr_udp_source.cc | 6 ++-- gnuradio-core/src/lib/io/gr_udp_source.h | 7 ++-- gnuradio-core/src/lib/io/gr_wavfile_sink.cc | 13 +++---- gnuradio-core/src/lib/io/gr_wavfile_sink.h | 6 ++-- gnuradio-core/src/lib/io/gri_logger.cc | 6 +++- gnuradio-core/src/lib/io/gri_logger.h | 6 +++- .../src/lib/runtime/gr_block_executor.cc | 6 ++-- gnuradio-core/src/lib/runtime/gr_buffer.cc | 8 ++--- gnuradio-core/src/lib/runtime/gr_buffer.h | 14 +++----- gnuradio-core/src/lib/runtime/gr_msg_queue.cc | 26 +++++++------- gnuradio-core/src/lib/runtime/gr_msg_queue.h | 19 ++++++----- gnuradio-core/src/lib/runtime/gr_msg_queue.i | 8 +---- .../src/lib/runtime/gr_sptr_magic.cc | 19 +++-------- gnuradio-core/src/lib/runtime/gr_tpb_detail.h | 17 +++++----- .../src/lib/runtime/gr_tpb_thread_body.cc | 6 ++-- .../src/audio_portaudio_sink.cc | 14 ++++---- gr-audio-portaudio/src/audio_portaudio_sink.h | 4 +-- .../src/audio_portaudio_source.cc | 14 ++++---- .../src/audio_portaudio_source.h | 4 +-- gruel/src/include/gruel/Makefile.am | 3 +- gruel/src/include/gruel/thread.h | 34 +++++++++++++++++++ gruel/src/include/gruel/thread_body_wrapper.h | 4 +-- gruel/src/include/gruel/thread_group.h | 4 +-- 30 files changed, 158 insertions(+), 129 deletions(-) create mode 100644 gruel/src/include/gruel/thread.h diff --git a/config/grc_gnuradio_core.m4 b/config/grc_gnuradio_core.m4 index 3e4cbdf4..26963432 100644 --- a/config/grc_gnuradio_core.m4 +++ b/config/grc_gnuradio_core.m4 @@ -28,9 +28,8 @@ AC_DEFUN([GRC_GNURADIO_CORE],[ gnuradio_core_PYDIRPATH=$pythondir ]) - dnl Don't do gnuradio-core if gruel or omnithread skipped + dnl Don't do gnuradio-core if gruel skipped GRC_CHECK_DEPENDENCY(gnuradio-core, gruel) - GRC_CHECK_DEPENDENCY(gnuradio-core, omnithread) dnl If execution gets to here, $passed will be: dnl with : if the --with code didn't error out diff --git a/config/grc_gr_audio_portaudio.m4 b/config/grc_gr_audio_portaudio.m4 index ff551b38..08d71f8f 100644 --- a/config/grc_gr_audio_portaudio.m4 +++ b/config/grc_gr_audio_portaudio.m4 @@ -22,6 +22,7 @@ AC_DEFUN([GRC_GR_AUDIO_PORTAUDIO],[ dnl Don't do gr-audio-portaudio if gnuradio-core skipped GRC_CHECK_DEPENDENCY(gr-audio-portaudio, gnuradio-core) + GRC_CHECK_DEPENDENCY(gr-audio-portaudio, omnithread) dnl If execution gets to here, $passed will be: dnl with : if the --with code didn't error out diff --git a/debian/control b/debian/control index 9cfd66a6..4c11a965 100644 --- a/debian/control +++ b/debian/control @@ -162,7 +162,7 @@ Description: Client side library for the USRP2 hardware Package: libgnuradio-core Section: libs Architecture: any -Depends: libgruel (= ${binary:Version}), libgnuradio-omnithread (= ${binary:Version}), ${shlibs:Depends} +Depends: libgruel (= ${binary:Version}), ${shlibs:Depends} Conflicts: libgnuradio-core0, libgnuradio-core0c2, libgnuradio-core0c2a Replaces: libgnuradio-core0, libgnuradio-core0c2, libgnuradio-core0c2a Suggests: gnuradio-doc @@ -174,7 +174,7 @@ Section: libdevel Architecture: any Replaces: libgnuradio-core0-dev Conflicts: libgnuradio-core0-dev -Depends: libgnuradio-core (= ${binary:Version}), libgruel-dev (= ${binary:Version}), libgnuradio-omnithread-dev (= ${binary:Version}), libboost-thread1.37-dev, libboost-date-time1.37-dev, libcppunit-dev, libgsl0-dev, libatlas-base-dev, libfftw3-dev, swig +Depends: libgnuradio-core (= ${binary:Version}), libgruel-dev (= ${binary:Version}), libboost-thread1.37-dev, libboost-date-time1.37-dev, libcppunit-dev, libgsl0-dev, libatlas-base-dev, libfftw3-dev, swig Description: The GNU Software Radio Core Library This package contains the core GNU Radio libraries. . diff --git a/gnuradio-core/src/lib/io/gr_file_sink_base.cc b/gnuradio-core/src/lib/io/gr_file_sink_base.cc index 29ac0dbb..5ddeeb4d 100644 --- a/gnuradio-core/src/lib/io/gr_file_sink_base.cc +++ b/gnuradio-core/src/lib/io/gr_file_sink_base.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2006,2007 Free Software Foundation, Inc. + * Copyright 2004,2006,2007,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -31,6 +31,7 @@ #include #include #include +#include // win32 (mingw/msvc) specific #ifdef HAVE_IO_H @@ -68,7 +69,7 @@ gr_file_sink_base::~gr_file_sink_base () bool gr_file_sink_base::open(const char *filename) { - omni_mutex_lock l(d_mutex); // hold mutex for duration of this function + gruel::scoped_lock guard(d_mutex); // hold mutex for duration of this function // we use the open system call to get access to the O_LARGEFILE flag. int fd; @@ -96,7 +97,7 @@ gr_file_sink_base::open(const char *filename) void gr_file_sink_base::close() { - omni_mutex_lock l(d_mutex); // hold mutex for duration of this function + gruel::scoped_lock guard(d_mutex); // hold mutex for duration of this function if (d_new_fp){ fclose(d_new_fp); @@ -109,7 +110,7 @@ void gr_file_sink_base::do_update() { if (d_updated){ - omni_mutex_lock l(d_mutex); // hold mutex for duration of this block + gruel::scoped_lock guard(d_mutex); // hold mutex for duration of this block if (d_fp) fclose(d_fp); d_fp = d_new_fp; // install new file pointer diff --git a/gnuradio-core/src/lib/io/gr_file_sink_base.h b/gnuradio-core/src/lib/io/gr_file_sink_base.h index f36f5ac9..0c028d7f 100644 --- a/gnuradio-core/src/lib/io/gr_file_sink_base.h +++ b/gnuradio-core/src/lib/io/gr_file_sink_base.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2007 Free Software Foundation, Inc. + * Copyright 2004,2007,2008 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -23,7 +23,7 @@ #ifndef INCLUDED_GR_FILE_SINK_BASE_H #define INCLUDED_GR_FILE_SINK_BASE_H -#include +#include #include /*! @@ -36,7 +36,7 @@ class gr_file_sink_base FILE *d_new_fp; // new FILE pointer bool d_updated; // is there a new FILE pointer? bool d_is_binary; - omni_mutex d_mutex; + boost::mutex d_mutex; protected: gr_file_sink_base(const char *filename, bool is_binary); diff --git a/gnuradio-core/src/lib/io/gr_udp_sink.cc b/gnuradio-core/src/lib/io/gr_udp_sink.cc index 215eaf8d..d37adfb8 100644 --- a/gnuradio-core/src/lib/io/gr_udp_sink.cc +++ b/gnuradio-core/src/lib/io/gr_udp_sink.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2007,2008 Free Software Foundation, Inc. + * Copyright 2007,2008,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -36,6 +36,8 @@ typedef void* optval_t; typedef char* optval_t; #endif +#include + #define SNK_VERBOSE 0 gr_udp_sink::gr_udp_sink (size_t itemsize, @@ -110,7 +112,7 @@ gr_udp_sink::~gr_udp_sink () bool gr_udp_sink::open() { - omni_mutex_lock l(d_mutex); // hold mutex for duration of this function + gruel::scoped_lock guard(d_mutex); // hold mutex for duration of this function // create socket if((d_socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) { @@ -153,7 +155,7 @@ gr_udp_sink::open() void gr_udp_sink::close() { - omni_mutex_lock l(d_mutex); // hold mutex for duration of this function + gruel::scoped_lock guard(d_mutex); // hold mutex for duration of this function if (d_socket){ shutdown(d_socket, SHUT_RDWR); diff --git a/gnuradio-core/src/lib/io/gr_udp_sink.h b/gnuradio-core/src/lib/io/gr_udp_sink.h index 13b2befc..f22b92dd 100644 --- a/gnuradio-core/src/lib/io/gr_udp_sink.h +++ b/gnuradio-core/src/lib/io/gr_udp_sink.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2007,2008 Free Software Foundation, Inc. + * Copyright 2007,2008,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -24,7 +24,7 @@ #define INCLUDED_GR_UDP_SINK_H #include -#include +#include #if defined(HAVE_SOCKET) #include #include @@ -36,6 +36,8 @@ #include #endif +#include + class gr_udp_sink; typedef boost::shared_ptr gr_udp_sink_sptr; @@ -69,7 +71,7 @@ class gr_udp_sink : public gr_sync_block private: size_t d_itemsize; bool d_updated; - omni_mutex d_mutex; + gruel::mutex d_mutex; int d_payload_size; // maximum transmission unit (packet length) int d_socket; // handle to socket diff --git a/gnuradio-core/src/lib/io/gr_udp_source.cc b/gnuradio-core/src/lib/io/gr_udp_source.cc index 9b6ee6e7..d76d0ee3 100644 --- a/gnuradio-core/src/lib/io/gr_udp_source.cc +++ b/gnuradio-core/src/lib/io/gr_udp_source.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2007,2008 Free Software Foundation, Inc. + * Copyright 2007,2008,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -90,7 +90,7 @@ gr_udp_source::~gr_udp_source () bool gr_udp_source::open() { - omni_mutex_lock l(d_mutex); // hold mutex for duration of this function + gruel::scoped_lock guard(d_mutex); // hold mutex for duration of this function // create socket d_socket = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); if(d_socket == -1) { @@ -137,7 +137,7 @@ gr_udp_source::open() void gr_udp_source::close() { - omni_mutex_lock l(d_mutex); // hold mutex for duration of this function + gruel::scoped_lock guard(d_mutex); // hold mutex for duration of this function if (d_socket){ shutdown(d_socket, SHUT_RDWR); diff --git a/gnuradio-core/src/lib/io/gr_udp_source.h b/gnuradio-core/src/lib/io/gr_udp_source.h index afc41a45..61d719e4 100644 --- a/gnuradio-core/src/lib/io/gr_udp_source.h +++ b/gnuradio-core/src/lib/io/gr_udp_source.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2007,2008 Free Software Foundation, Inc. + * Copyright 2007,2008,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -24,7 +24,6 @@ #define INCLUDED_GR_UDP_SOURCE_H #include -#include #if defined(HAVE_SOCKET) #include #include @@ -36,6 +35,8 @@ #include #endif +#include + class gr_udp_source; typedef boost::shared_ptr gr_udp_source_sptr; @@ -63,7 +64,7 @@ class gr_udp_source : public gr_sync_block private: size_t d_itemsize; bool d_updated; - omni_mutex d_mutex; + gruel::mutex d_mutex; int d_payload_size; // maximum transmission unit (packet length) int d_socket; // handle to socket diff --git a/gnuradio-core/src/lib/io/gr_wavfile_sink.cc b/gnuradio-core/src/lib/io/gr_wavfile_sink.cc index f06c33d5..72e4ef51 100644 --- a/gnuradio-core/src/lib/io/gr_wavfile_sink.cc +++ b/gnuradio-core/src/lib/io/gr_wavfile_sink.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2006,2007,2008 Free Software Foundation, Inc. + * Copyright 2004,2006,2007,2008,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -32,6 +32,7 @@ #include #include #include +#include // win32 (mingw/msvc) specific #ifdef HAVE_IO_H @@ -103,7 +104,7 @@ gr_wavfile_sink::gr_wavfile_sink(const char *filename, bool gr_wavfile_sink::open(const char* filename) { - omni_mutex_lock l(d_mutex); + gruel::scoped_lock guard(d_mutex); // we use the open system call to get access to the O_LARGEFILE flag. int fd; @@ -141,7 +142,7 @@ gr_wavfile_sink::open(const char* filename) void gr_wavfile_sink::close() { - omni_mutex_lock l(d_mutex); + gruel::scoped_lock guard(d_mutex); if (!d_fp) return; @@ -230,7 +231,7 @@ gr_wavfile_sink::convert_to_short(float sample) void gr_wavfile_sink::set_bits_per_sample(int bits_per_sample) { - omni_mutex_lock l(d_mutex); + gruel::scoped_lock guard(d_mutex); if (bits_per_sample == 8 || bits_per_sample == 16) { d_bytes_per_sample_new = bits_per_sample / 8; } @@ -240,7 +241,7 @@ gr_wavfile_sink::set_bits_per_sample(int bits_per_sample) void gr_wavfile_sink::set_sample_rate(unsigned int sample_rate) { - omni_mutex_lock l(d_mutex); + gruel::scoped_lock guard(d_mutex); d_sample_rate = sample_rate; } @@ -252,7 +253,7 @@ gr_wavfile_sink::do_update() return; } - omni_mutex_lock l(d_mutex); // hold mutex for duration of this block + gruel::scoped_lock guard(d_mutex); // hold mutex for duration of this block if (d_fp) { close_wav(); } diff --git a/gnuradio-core/src/lib/io/gr_wavfile_sink.h b/gnuradio-core/src/lib/io/gr_wavfile_sink.h index fd1d0bf6..a1d6ed52 100644 --- a/gnuradio-core/src/lib/io/gr_wavfile_sink.h +++ b/gnuradio-core/src/lib/io/gr_wavfile_sink.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2008 Free Software Foundation, Inc. + * Copyright 2008,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -25,7 +25,7 @@ #include #include -#include +#include class gr_wavfile_sink; typedef boost::shared_ptr gr_wavfile_sink_sptr; @@ -76,7 +76,7 @@ private: FILE *d_fp; FILE *d_new_fp; bool d_updated; - omni_mutex d_mutex; + boost::mutex d_mutex; /*! * \brief Convert a sample value within [-1;+1] to a corresponding diff --git a/gnuradio-core/src/lib/io/gri_logger.cc b/gnuradio-core/src/lib/io/gri_logger.cc index c085a93c..473a7c5e 100644 --- a/gnuradio-core/src/lib/io/gri_logger.cc +++ b/gnuradio-core/src/lib/io/gri_logger.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006 Free Software Foundation, Inc. + * Copyright 2006,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -24,6 +24,8 @@ #include #endif +#if 0 // This needs reimplementation with boost threads and synchronization + #include #include #include @@ -172,3 +174,5 @@ gri_logger::printf(const char *format, ...) if (n > -1 && n < (ssize_t) sizeof(buf)) write(buf, n); } + +#endif diff --git a/gnuradio-core/src/lib/io/gri_logger.h b/gnuradio-core/src/lib/io/gri_logger.h index e5caf7d0..0a141454 100644 --- a/gnuradio-core/src/lib/io/gri_logger.h +++ b/gnuradio-core/src/lib/io/gri_logger.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006 Free Software Foundation, Inc. + * Copyright 2006,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -22,6 +22,8 @@ #ifndef INCLUDED_GRI_LOGGER_H #define INCLUDED_GRI_LOGGER_H +#if 0 // This needs reimplementation with boost threads and synchronization + #include #include #include @@ -52,4 +54,6 @@ public: void printf(const char *format, ...); }; +#endif + #endif /* INCLUDED_GRI_LOGGER_H */ diff --git a/gnuradio-core/src/lib/runtime/gr_block_executor.cc b/gnuradio-core/src/lib/runtime/gr_block_executor.cc index fd3a916d..e8d30b96 100644 --- a/gnuradio-core/src/lib/runtime/gr_block_executor.cc +++ b/gnuradio-core/src/lib/runtime/gr_block_executor.cc @@ -68,7 +68,7 @@ min_available_space (gr_block_detail *d, int output_multiple) int min_space = std::numeric_limits::max(); for (int i = 0; i < d->noutputs (); i++){ - gr_buffer::scoped_lock guard(*d->output(i)->mutex()); + gruel::scoped_lock guard(*d->output(i)->mutex()); #if 0 int n = round_down(d->output(i)->space_available(), output_multiple); #else @@ -163,7 +163,7 @@ gr_block_executor::run_one_iteration() /* * Acquire the mutex and grab local copies of items_available and done. */ - gr_buffer::scoped_lock guard(*d->input(i)->mutex()); + gruel::scoped_lock guard(*d->input(i)->mutex()); d_ninput_items[i] = d->input(i)->items_available(); d_input_done[i] = d->input(i)->done(); } @@ -205,7 +205,7 @@ gr_block_executor::run_one_iteration() /* * Acquire the mutex and grab local copies of items_available and done. */ - gr_buffer::scoped_lock guard(*d->input(i)->mutex()); + gruel::scoped_lock guard(*d->input(i)->mutex()); d_ninput_items[i] = d->input(i)->items_available (); d_input_done[i] = d->input(i)->done(); } diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.cc b/gnuradio-core/src/lib/runtime/gr_buffer.cc index 31a471ea..db2db5d6 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.cc +++ b/gnuradio-core/src/lib/runtime/gr_buffer.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004 Free Software Foundation, Inc. + * Copyright 2004,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -175,14 +175,14 @@ gr_buffer::write_pointer () void gr_buffer::update_write_pointer (int nitems) { - scoped_lock guard(*mutex()); + gruel::scoped_lock guard(*mutex()); d_write_index = index_add (d_write_index, nitems); } void gr_buffer::set_done (bool done) { - scoped_lock guard(*mutex()); + gruel::scoped_lock guard(*mutex()); d_done = done; } @@ -251,7 +251,7 @@ gr_buffer_reader::read_pointer () void gr_buffer_reader::update_read_pointer (int nitems) { - scoped_lock guard(*mutex()); + gruel::scoped_lock guard(*mutex()); d_read_index = d_buffer->index_add (d_read_index, nitems); } diff --git a/gnuradio-core/src/lib/runtime/gr_buffer.h b/gnuradio-core/src/lib/runtime/gr_buffer.h index cb593eea..207bfe7c 100644 --- a/gnuradio-core/src/lib/runtime/gr_buffer.h +++ b/gnuradio-core/src/lib/runtime/gr_buffer.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004 Free Software Foundation, Inc. + * Copyright 2004,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -25,7 +25,7 @@ #include #include -#include +#include class gr_vmcircbuf; @@ -50,8 +50,6 @@ gr_buffer_sptr gr_make_buffer (int nitems, size_t sizeof_item, gr_block_sptr lin class gr_buffer { public: - typedef boost::unique_lock scoped_lock; - virtual ~gr_buffer (); /*! @@ -88,7 +86,7 @@ class gr_buffer { size_t nreaders() const { return d_readers.size(); } gr_buffer_reader* reader(size_t index) { return d_readers[index]; } - boost::mutex *mutex() { return &d_mutex; } + gruel::mutex *mutex() { return &d_mutex; } // ------------------------------------------------------------------------- @@ -110,7 +108,7 @@ class gr_buffer { // // The mutex protects d_write_index, d_done and the d_read_index's in the buffer readers. // - boost::mutex d_mutex; + gruel::mutex d_mutex; unsigned int d_write_index; // in items [0,d_bufsize) bool d_done; @@ -185,8 +183,6 @@ long gr_buffer_ncurrently_allocated (); class gr_buffer_reader { public: - typedef gr_buffer::scoped_lock scoped_lock; - ~gr_buffer_reader (); /*! @@ -221,7 +217,7 @@ class gr_buffer_reader { void set_done (bool done) { d_buffer->set_done (done); } bool done () const { return d_buffer->done (); } - boost::mutex *mutex() { return d_buffer->mutex(); } + gruel::mutex *mutex() { return d_buffer->mutex(); } /*! diff --git a/gnuradio-core/src/lib/runtime/gr_msg_queue.cc b/gnuradio-core/src/lib/runtime/gr_msg_queue.cc index 922eeda0..3097acc9 100644 --- a/gnuradio-core/src/lib/runtime/gr_msg_queue.cc +++ b/gnuradio-core/src/lib/runtime/gr_msg_queue.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2005 Free Software Foundation, Inc. + * Copyright 2005,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -26,16 +26,14 @@ #include #include - gr_msg_queue_sptr gr_make_msg_queue(unsigned int limit) { return gr_msg_queue_sptr (new gr_msg_queue(limit)); } - gr_msg_queue::gr_msg_queue(unsigned int limit) - : d_not_empty(&d_mutex), d_not_full(&d_mutex), + : d_not_empty(), d_not_full(), /*d_head(0), d_tail(0),*/ d_count(0), d_limit(limit) { } @@ -51,10 +49,10 @@ gr_msg_queue::insert_tail(gr_message_sptr msg) if (msg->d_next) throw std::invalid_argument("gr_msg_queue::insert_tail: msg already in queue"); - omni_mutex_lock l(d_mutex); + gruel::scoped_lock guard(d_mutex); while (full_p()) - d_not_full.wait(); + d_not_full.wait(guard); if (d_tail == 0){ d_tail = d_head = msg; @@ -68,17 +66,17 @@ gr_msg_queue::insert_tail(gr_message_sptr msg) msg->d_next.reset(); } d_count++; - d_not_empty.signal(); + d_not_empty.notify_one(); } gr_message_sptr gr_msg_queue::delete_head() { - omni_mutex_lock l(d_mutex); - gr_message_sptr m; + gruel::scoped_lock guard(d_mutex); + gr_message_sptr m; while ((m = d_head) == 0) - d_not_empty.wait(); + d_not_empty.wait(guard); d_head = m->d_next; if (d_head == 0){ @@ -89,15 +87,15 @@ gr_msg_queue::delete_head() d_count--; // m->d_next = 0; m->d_next.reset(); - d_not_full.signal(); + d_not_full.notify_one(); return m; } gr_message_sptr gr_msg_queue::delete_head_nowait() { - omni_mutex_lock l(d_mutex); - gr_message_sptr m; + gruel::scoped_lock guard(d_mutex); + gr_message_sptr m; if ((m = d_head) == 0){ //return 0; @@ -113,7 +111,7 @@ gr_msg_queue::delete_head_nowait() d_count--; //m->d_next = 0; m->d_next.reset(); - d_not_full.signal(); + d_not_full.notify_one(); return m; } diff --git a/gnuradio-core/src/lib/runtime/gr_msg_queue.h b/gnuradio-core/src/lib/runtime/gr_msg_queue.h index f965887e..477b1ddf 100644 --- a/gnuradio-core/src/lib/runtime/gr_msg_queue.h +++ b/gnuradio-core/src/lib/runtime/gr_msg_queue.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2005 Free Software Foundation, Inc. + * Copyright 2005,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -23,7 +23,7 @@ #define INCLUDED_GR_MSG_QUEUE_H #include -#include +#include class gr_msg_queue; typedef boost::shared_ptr gr_msg_queue_sptr; @@ -35,13 +35,14 @@ gr_msg_queue_sptr gr_make_msg_queue(unsigned int limit=0); * \ingroup misc */ class gr_msg_queue : public gr_msg_handler { - omni_mutex d_mutex; - omni_condition d_not_empty; - omni_condition d_not_full; - gr_message_sptr d_head; - gr_message_sptr d_tail; - unsigned int d_count; // # of messages in queue. - unsigned int d_limit; // max # of messages in queue. 0 -> unbounded + + gruel::mutex d_mutex; + gruel::condition_variable d_not_empty; + gruel::condition_variable d_not_full; + gr_message_sptr d_head; + gr_message_sptr d_tail; + unsigned int d_count; // # of messages in queue. + unsigned int d_limit; // max # of messages in queue. 0 -> unbounded public: gr_msg_queue(unsigned int limit); diff --git a/gnuradio-core/src/lib/runtime/gr_msg_queue.i b/gnuradio-core/src/lib/runtime/gr_msg_queue.i index 254a7a94..9ca92b6e 100644 --- a/gnuradio-core/src/lib/runtime/gr_msg_queue.i +++ b/gnuradio-core/src/lib/runtime/gr_msg_queue.i @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2005 Free Software Foundation, Inc. + * Copyright 2005,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -32,12 +32,6 @@ gr_msg_queue_sptr gr_make_msg_queue(unsigned limit=0); */ %ignore gr_msg_queue; class gr_msg_queue : public gr_msg_handler { - omni_mutex d_mutex; - omni_condition d_cond; - gr_message_sptr d_head; - gr_message_sptr d_tail; - int d_count; - public: gr_msg_queue(unsigned int limit); ~gr_msg_queue(); diff --git a/gnuradio-core/src/lib/runtime/gr_sptr_magic.cc b/gnuradio-core/src/lib/runtime/gr_sptr_magic.cc index 3295f849..96ffae85 100644 --- a/gnuradio-core/src/lib/runtime/gr_sptr_magic.cc +++ b/gnuradio-core/src/lib/runtime/gr_sptr_magic.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2008 Free Software Foundation, Inc. + * Copyright 2008,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -27,19 +27,11 @@ #include -#if 0 - #include - typedef boost::mutex mutex; - typedef boost::mutex::scoped_lock scoped_lock; -#else - #include - typedef omni_mutex mutex; - typedef omni_mutex_lock scoped_lock; -#endif +#include namespace gnuradio { - static mutex s_mutex; + static gruel::mutex s_mutex; typedef std::map sptr_map; static sptr_map s_map; @@ -47,7 +39,7 @@ namespace gnuradio { detail::sptr_magic::create_and_stash_initial_sptr(gr_hier_block2 *p) { gr_basic_block_sptr sptr(p); - scoped_lock l(); + gruel::scoped_lock guard(); s_map.insert(sptr_map::value_type(static_cast(p), sptr)); } @@ -68,7 +60,7 @@ namespace gnuradio { * p is a subclass of gr_hier_block2, thus we've already created the shared pointer * and stashed it away. Fish it out and return it. */ - scoped_lock l(); + gruel::scoped_lock guard(); sptr_map::iterator pos = s_map.find(static_cast(p)); if (pos == s_map.end()) throw std::invalid_argument("gr_sptr_magic: invalid pointer!"); @@ -78,4 +70,3 @@ namespace gnuradio { return sptr; } }; - diff --git a/gnuradio-core/src/lib/runtime/gr_tpb_detail.h b/gnuradio-core/src/lib/runtime/gr_tpb_detail.h index 9566312d..ab955240 100644 --- a/gnuradio-core/src/lib/runtime/gr_tpb_detail.h +++ b/gnuradio-core/src/lib/runtime/gr_tpb_detail.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2008 Free Software Foundation, Inc. + * Copyright 2008,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -21,7 +21,7 @@ #ifndef INCLUDED_GR_TPB_DETAIL_H #define INCLUDED_GR_TPB_DETAIL_H -#include +#include class gr_block_detail; @@ -29,13 +29,12 @@ class gr_block_detail; * \brief used by thread-per-block scheduler */ struct gr_tpb_detail { - typedef boost::unique_lock scoped_lock; - boost::mutex mutex; //< protects all vars + gruel::mutex mutex; //< protects all vars bool input_changed; - boost::condition_variable input_cond; + gruel::condition_variable input_cond; bool output_changed; - boost::condition_variable output_cond; + gruel::condition_variable output_cond; gr_tpb_detail() : input_changed(false), output_changed(false) {} @@ -53,7 +52,7 @@ struct gr_tpb_detail { //! Called by us void clear_changed() { - scoped_lock guard(mutex); + gruel::scoped_lock guard(mutex); input_changed = false; output_changed = false; } @@ -63,7 +62,7 @@ private: //! Used by notify_downstream void set_input_changed() { - scoped_lock guard(mutex); + gruel::scoped_lock guard(mutex); input_changed = true; input_cond.notify_one(); } @@ -71,7 +70,7 @@ private: //! Used by notify_upstream void set_output_changed() { - scoped_lock guard(mutex); + gruel::scoped_lock guard(mutex); output_changed = true; output_cond.notify_one(); } diff --git a/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc b/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc index e3abf6d8..458b16d6 100644 --- a/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc +++ b/gnuradio-core/src/lib/runtime/gr_tpb_thread_body.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2008 Free Software Foundation, Inc. + * Copyright 2008,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -54,7 +54,7 @@ gr_tpb_thread_body::gr_tpb_thread_body(gr_block_sptr block) case gr_block_executor::BLKD_IN: // Wait for input. { - gr_tpb_detail::scoped_lock guard(d->d_tpb.mutex); + gruel::scoped_lock guard(d->d_tpb.mutex); while(!d->d_tpb.input_changed) d->d_tpb.input_cond.wait(guard); } @@ -62,7 +62,7 @@ gr_tpb_thread_body::gr_tpb_thread_body(gr_block_sptr block) case gr_block_executor::BLKD_OUT: // Wait for output buffer space. { - gr_tpb_detail::scoped_lock guard(d->d_tpb.mutex); + gruel::scoped_lock guard(d->d_tpb.mutex); while(!d->d_tpb.output_changed) d->d_tpb.output_cond.wait(guard); } diff --git a/gr-audio-portaudio/src/audio_portaudio_sink.cc b/gr-audio-portaudio/src/audio_portaudio_sink.cc index cfdc6302..2e48feb4 100644 --- a/gr-audio-portaudio/src/audio_portaudio_sink.cc +++ b/gr-audio-portaudio/src/audio_portaudio_sink.cc @@ -35,7 +35,7 @@ #include #include -#define LOGGING 0 // define to 0 or 1 +//#define LOGGING 0 // define to 0 or 1 #define SAMPLE_FORMAT paFloat32 typedef float sample_t; @@ -85,8 +85,8 @@ portaudio_sink_callback (const void *inputBuffer, int navail_samples = self->d_reader->items_available(); if (nreqd_samples <= navail_samples){ // We've got enough data... - if (LOGGING) - self->d_log->printf("PAsink cb: f/b = %4ld\n", framesPerBuffer); + //if (LOGGING) + // self->d_log->printf("PAsink cb: f/b = %4ld\n", framesPerBuffer); // copy from ringbuffer into output buffer memcpy(outputBuffer, self->d_reader->read_pointer(), @@ -99,8 +99,8 @@ portaudio_sink_callback (const void *inputBuffer, } else { // underrun - if (LOGGING) - self->d_log->printf("PAsink cb: f/b = %4ld UNDERRUN\n", framesPerBuffer); + //if (LOGGING) + // self->d_log->printf("PAsink cb: f/b = %4ld UNDERRUN\n", framesPerBuffer); self->d_nunderuns++; ::write(2, "aU", 2); // FIXME change to non-blocking call @@ -139,8 +139,8 @@ audio_portaudio_sink::audio_portaudio_sink(int sampling_rate, d_nunderuns(0) { memset(&d_output_parameters, 0, sizeof(d_output_parameters)); - if (LOGGING) - d_log = gri_logger::singleton(); + //if (LOGGING) + // d_log = gri_logger::singleton(); PaError err; int i, numDevices; diff --git a/gr-audio-portaudio/src/audio_portaudio_sink.h b/gr-audio-portaudio/src/audio_portaudio_sink.h index 0e082c5e..1a072979 100644 --- a/gr-audio-portaudio/src/audio_portaudio_sink.h +++ b/gr-audio-portaudio/src/audio_portaudio_sink.h @@ -28,7 +28,7 @@ #include #include #include -#include +//#include class audio_portaudio_sink; typedef boost::shared_ptr audio_portaudio_sink_sptr; @@ -79,7 +79,7 @@ class audio_portaudio_sink : public gr_sync_block { // random stats int d_nunderuns; // count of underruns - gri_logger_sptr d_log; // handle to non-blocking logging instance + //gri_logger_sptr d_log; // handle to non-blocking logging instance void output_error_msg (const char *msg, int err); void bail (const char *msg, int err) throw (std::runtime_error); diff --git a/gr-audio-portaudio/src/audio_portaudio_source.cc b/gr-audio-portaudio/src/audio_portaudio_source.cc index 29d63a8e..9e883ad8 100644 --- a/gr-audio-portaudio/src/audio_portaudio_source.cc +++ b/gr-audio-portaudio/src/audio_portaudio_source.cc @@ -35,7 +35,7 @@ #include #include -#define LOGGING 0 // define to 0 or 1 +//#define LOGGING 0 // define to 0 or 1 #define SAMPLE_FORMAT paFloat32 typedef float sample_t; @@ -84,8 +84,8 @@ portaudio_source_callback (const void *inputBuffer, int nframes_room = self->d_writer->space_available() / nchan; if (nframes_to_copy <= nframes_room){ // We've got room for the data .. - if (LOGGING) - self->d_log->printf("PAsrc cb: f/b = %4ld\n", framesPerBuffer); + //if (LOGGING) + // self->d_log->printf("PAsrc cb: f/b = %4ld\n", framesPerBuffer); // copy from input buffer to ringbuffer memcpy(self->d_writer->write_pointer(), @@ -99,8 +99,8 @@ portaudio_source_callback (const void *inputBuffer, } else { // overrun - if (LOGGING) - self->d_log->printf("PAsrc cb: f/b = %4ld OVERRUN\n", framesPerBuffer); + //if (LOGGING) + // self->d_log->printf("PAsrc cb: f/b = %4ld OVERRUN\n", framesPerBuffer); self->d_noverruns++; ::write(2, "aO", 2); // FIXME change to non-blocking call @@ -144,8 +144,8 @@ audio_portaudio_source::audio_portaudio_source(int sampling_rate, d_noverruns(0) { memset(&d_input_parameters, 0, sizeof(d_input_parameters)); - if (LOGGING) - d_log = gri_logger::singleton(); + //if (LOGGING) + // d_log = gri_logger::singleton(); PaError err; int i, numDevices; diff --git a/gr-audio-portaudio/src/audio_portaudio_source.h b/gr-audio-portaudio/src/audio_portaudio_source.h index d14fe805..3102db73 100644 --- a/gr-audio-portaudio/src/audio_portaudio_source.h +++ b/gr-audio-portaudio/src/audio_portaudio_source.h @@ -28,7 +28,7 @@ #include #include #include -#include +//#include class audio_portaudio_source; typedef boost::shared_ptr audio_portaudio_source_sptr; @@ -78,7 +78,7 @@ class audio_portaudio_source : public gr_sync_block { // random stats int d_noverruns; // count of overruns - gri_logger_sptr d_log; // handle to non-blocking logging instance + //gri_logger_sptr d_log; // handle to non-blocking logging instance void output_error_msg (const char *msg, int err); void bail (const char *msg, int err) throw (std::runtime_error); diff --git a/gruel/src/include/gruel/Makefile.am b/gruel/src/include/gruel/Makefile.am index d7354b87..622fbc2d 100644 --- a/gruel/src/include/gruel/Makefile.am +++ b/gruel/src/include/gruel/Makefile.am @@ -34,4 +34,5 @@ gruelinclude_HEADERS = \ realtime.h \ sys_pri.h \ thread_body_wrapper.h \ - thread_group.h + thread_group.h \ + thread.h diff --git a/gruel/src/include/gruel/thread.h b/gruel/src/include/gruel/thread.h new file mode 100644 index 00000000..0e7acaa8 --- /dev/null +++ b/gruel/src/include/gruel/thread.h @@ -0,0 +1,34 @@ +/* -*- c++ -*- */ +/* + * Copyright 2009 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ +#ifndef INCLUDED_THREAD_H +#define INCLUDED_THREAD_H + +#include + +namespace gruel { + + typedef boost::mutex mutex; + typedef boost::unique_lock scoped_lock; + typedef boost::condition_variable condition_variable; + +} /* namespace gruel */ + +#endif /* INCLUDED_THREAD_H */ diff --git a/gruel/src/include/gruel/thread_body_wrapper.h b/gruel/src/include/gruel/thread_body_wrapper.h index 27dbbf7b..b024bfda 100644 --- a/gruel/src/include/gruel/thread_body_wrapper.h +++ b/gruel/src/include/gruel/thread_body_wrapper.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2008 Free Software Foundation, Inc. + * Copyright 2008,2009 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -21,7 +21,7 @@ #ifndef INCLUDED_THREAD_BODY_WRAPPER_H #define INCLUDED_THREAD_BODY_WRAPPER_H -#include +#include #include #include diff --git a/gruel/src/include/gruel/thread_group.h b/gruel/src/include/gruel/thread_group.h index ae9a4250..0270746e 100644 --- a/gruel/src/include/gruel/thread_group.h +++ b/gruel/src/include/gruel/thread_group.h @@ -2,7 +2,7 @@ /* * Copyright (C) 2001-2003 William E. Kempf * Copyright (C) 2007 Anthony Williams - * Copyright 2008 Free Software Foundation, Inc. + * Copyright 2008,2009 Free Software Foundation, Inc. * * Distributed under the Boost Software License, Version 1.0. (See accompanying * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -15,8 +15,8 @@ #ifndef INCLUDED_GRUEL_THREAD_GROUP_H #define INCLUDED_GRUEL_THREAD_GROUP_H +#include #include -#include #include #include -- 2.30.2