X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=gr-audio-osx%2Fsrc%2Fmld_threads.h;h=d2fb4ea7c0d68c50b84ebc87b097a2bc1cd7f93b;hb=ea29b08aeb54227e6628f655ccfdb96fe4d8c378;hp=185f95c12b8639435b2192cb3f224c1315c10dcc;hpb=18a684bf3dc144c48fc4cc6cc72f5070febd8074;p=debian%2Fgnuradio diff --git a/gr-audio-osx/src/mld_threads.h b/gr-audio-osx/src/mld_threads.h index 185f95c1..d2fb4ea7 100644 --- a/gr-audio-osx/src/mld_threads.h +++ b/gr-audio-osx/src/mld_threads.h @@ -4,9 +4,11 @@ * * This file is part of GNU Radio. * + * Primary Author: Michael Dickens, NCIP Lab, University of Notre Dame + * * 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 2, or (at your option) + * 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, @@ -25,8 +27,9 @@ /* classes which allow for either pthreads or omni_threads */ +#define __macos__ #ifdef _USE_OMNI_THREADS_ -#include +#include #else #include #endif @@ -34,6 +37,13 @@ #include #define __INLINE__ inline +#define DO_DEBUG 0 + +#if DO_DEBUG +#define DEBUG(X) do{X} while(0); +#else +#define DEBUG(X) do{} while(0); +#endif class mld_condition_t; @@ -130,12 +140,17 @@ class mld_condition_t { private: l_condition_ptr d_condition; mld_mutex_ptr d_mutex; - bool d_waiting; + bool d_i_own_mutex; public: - __INLINE__ mld_condition_t () { - d_waiting = false; - d_mutex = new mld_mutex (); + __INLINE__ mld_condition_t (mld_mutex_ptr mutex = NULL) { + if (mutex) { + d_i_own_mutex = false; + d_mutex = mutex; + } else { + d_i_own_mutex = true; + d_mutex = new mld_mutex (); + } #ifdef _USE_OMNI_THREADS_ d_condition = new omni_condition (d_mutex->mutex ()); #else @@ -159,38 +174,40 @@ public: #endif delete d_condition; d_condition = NULL; - delete d_mutex; + if (d_i_own_mutex) + delete d_mutex; d_mutex = NULL; }; + __INLINE__ mld_mutex_ptr mutex () {return (d_mutex);}; + __INLINE__ void signal () { - if (d_waiting == true) { + DEBUG (fprintf (stderr, "a ")); + #ifdef _USE_OMNI_THREADS_ - d_condition->signal (); + d_condition->signal (); #else - int l_ret = pthread_cond_signal (d_condition); - if (l_ret != 0) { - fprintf (stderr, "mld_condition_t::signal(): " - "Error %d.\n", l_ret); - } -#endif - d_waiting = false; + int l_ret = pthread_cond_signal (d_condition); + if (l_ret != 0) { + fprintf (stderr, "mld_condition_t::signal(): " + "Error %d.\n", l_ret); } +#endif + DEBUG (fprintf (stderr, "b ")); }; __INLINE__ void wait () { - if (d_waiting == false) { - d_waiting = true; + DEBUG (fprintf (stderr, "c ")); #ifdef _USE_OMNI_THREADS_ - d_condition->wait (); + d_condition->wait (); #else - int l_ret = pthread_cond_wait (d_condition, d_mutex->mutex ()); - if (l_ret != 0) { - fprintf (stderr, "mld_condition_t::wait(): " - "Error %d.\n", l_ret); - } -#endif + int l_ret = pthread_cond_wait (d_condition, d_mutex->mutex ()); + if (l_ret != 0) { + fprintf (stderr, "mld_condition_t::wait(): " + "Error %d.\n", l_ret); } +#endif + DEBUG (printf (stderr, "d ")); }; };