00001 /* -*- c++ -*- */ 00002 /* 00003 * Copyright 2007,2008 Free Software Foundation, Inc. 00004 * 00005 * This file is part of GNU Radio 00006 * 00007 * GNU Radio is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 3, or (at your option) 00010 * any later version. 00011 * 00012 * GNU Radio is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License along 00018 * with this program; if not, write to the Free Software Foundation, Inc., 00019 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00020 */ 00021 #ifndef INCLUDED_MB_MSG_QUEUE_H 00022 #define INCLUDED_MB_MSG_QUEUE_H 00023 00024 #include <mblock/common.h> 00025 #include <gnuradio/omnithread.h> 00026 #include <mblock/time.h> 00027 00028 /*! 00029 * \brief priority queue for mblock messages 00030 */ 00031 class mb_msg_queue : boost::noncopyable 00032 { 00033 // When empty both head and tail are zero. 00034 struct subq { 00035 mb_message_sptr head; 00036 mb_message_sptr tail; 00037 00038 bool empty_p() const { return head == 0; } 00039 }; 00040 00041 omni_mutex d_mutex; 00042 omni_condition d_not_empty; // reader waits on this 00043 00044 // FIXME add bitmap to indicate which queues are non-empty. 00045 subq d_queue[MB_NPRI]; 00046 00047 mb_message_sptr get_highest_pri_msg_helper(); 00048 00049 public: 00050 mb_msg_queue(); 00051 ~mb_msg_queue(); 00052 00053 //! Insert \p msg into priority queue. 00054 void insert(mb_message_sptr msg); 00055 00056 /* 00057 * \brief Delete highest pri message from the queue and return it. 00058 * Returns equivalent of zero pointer if queue is empty. 00059 */ 00060 mb_message_sptr get_highest_pri_msg_nowait(); 00061 00062 /* 00063 * \brief Delete highest pri message from the queue and return it. 00064 * If the queue is empty, this call blocks until it can return a message. 00065 */ 00066 mb_message_sptr get_highest_pri_msg(); 00067 00068 /* 00069 * \brief Delete highest pri message from the queue and return it. 00070 * If the queue is empty, this call blocks until it can return a message 00071 * or real-time exceeds the absolute time, abs_time. 00072 * 00073 * \param abs_time specifies the latest absolute time to wait until. 00074 * \sa mb_time::time 00075 * 00076 * \returns a valid mb_message_sptr, or the equivalent of a zero pointer 00077 * if the call timed out while waiting. 00078 */ 00079 mb_message_sptr get_highest_pri_msg_timedwait(const mb_time &abs_time); 00080 }; 00081 00082 #endif /* INCLUDED_MB_MSG_QUEUE_H */