Statistics
| Branch: | Tag: | Revision:

root / mblock / src / include / mblock / msg_queue.h @ c48f42b5

History | View | Annotate | Download (2.4 kB)

1 a6db1d09 eb
/* -*- c++ -*- */
2 a6db1d09 eb
/*
3 66dca696 jcorgan
 * Copyright 2007,2008 Free Software Foundation, Inc.
4 a6db1d09 eb
 * 
5 a6db1d09 eb
 * This file is part of GNU Radio
6 a6db1d09 eb
 * 
7 a6db1d09 eb
 * GNU Radio is free software; you can redistribute it and/or modify
8 a6db1d09 eb
 * it under the terms of the GNU General Public License as published by
9 937b719d eb
 * the Free Software Foundation; either version 3, or (at your option)
10 a6db1d09 eb
 * any later version.
11 a6db1d09 eb
 * 
12 a6db1d09 eb
 * GNU Radio is distributed in the hope that it will be useful,
13 a6db1d09 eb
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 a6db1d09 eb
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 a6db1d09 eb
 * GNU General Public License for more details.
16 a6db1d09 eb
 * 
17 a6db1d09 eb
 * You should have received a copy of the GNU General Public License along
18 a6db1d09 eb
 * with this program; if not, write to the Free Software Foundation, Inc.,
19 a6db1d09 eb
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 a6db1d09 eb
 */
21 a6db1d09 eb
#ifndef INCLUDED_MB_MSG_QUEUE_H
22 a6db1d09 eb
#define INCLUDED_MB_MSG_QUEUE_H
23 a6db1d09 eb
24 66dca696 jcorgan
#include <mblock/common.h>
25 c48f42b5 jcorgan
#include <gnuradio/omnithread.h>
26 66dca696 jcorgan
#include <mblock/time.h>
27 a6db1d09 eb
28 a6db1d09 eb
/*!
29 a6db1d09 eb
 * \brief priority queue for mblock messages
30 a6db1d09 eb
 */
31 a6db1d09 eb
class mb_msg_queue : boost::noncopyable
32 a6db1d09 eb
{
33 a6db1d09 eb
  // When empty both head and tail are zero.
34 a6db1d09 eb
  struct subq {
35 a6db1d09 eb
    mb_message_sptr        head;
36 a6db1d09 eb
    mb_message_sptr        tail;
37 a6db1d09 eb
38 a6db1d09 eb
    bool empty_p() const { return head == 0; }
39 a6db1d09 eb
  };
40 a6db1d09 eb
41 7833f98e eb
  omni_mutex         d_mutex;
42 7833f98e eb
  omni_condition d_not_empty;        // reader waits on this
43 a6db1d09 eb
44 a6db1d09 eb
  // FIXME add bitmap to indicate which queues are non-empty.
45 7833f98e eb
  subq                 d_queue[MB_NPRI];
46 7833f98e eb
47 7833f98e eb
  mb_message_sptr get_highest_pri_msg_helper();
48 a6db1d09 eb
49 a6db1d09 eb
public:
50 a6db1d09 eb
  mb_msg_queue();
51 a6db1d09 eb
  ~mb_msg_queue();
52 a6db1d09 eb
53 a6db1d09 eb
  //! Insert \p msg into priority queue.
54 a6db1d09 eb
  void insert(mb_message_sptr msg);
55 a6db1d09 eb
56 a6db1d09 eb
  /*
57 a6db1d09 eb
   * \brief Delete highest pri message from the queue and return it.
58 a6db1d09 eb
   * Returns equivalent of zero pointer if queue is empty.
59 a6db1d09 eb
   */
60 7833f98e eb
  mb_message_sptr get_highest_pri_msg_nowait();
61 7833f98e eb
62 7833f98e eb
  /*
63 7833f98e eb
   * \brief Delete highest pri message from the queue and return it.
64 7833f98e eb
   * If the queue is empty, this call blocks until it can return a message.
65 7833f98e eb
   */
66 a6db1d09 eb
  mb_message_sptr get_highest_pri_msg();
67 0bf2128a eb
68 0bf2128a eb
  /*
69 0bf2128a eb
   * \brief Delete highest pri message from the queue and return it.
70 0bf2128a eb
   * If the queue is empty, this call blocks until it can return a message
71 0bf2128a eb
   * or real-time exceeds the absolute time, abs_time.
72 0bf2128a eb
   *
73 0bf2128a eb
   * \param abs_time specifies the latest absolute time to wait until.
74 0bf2128a eb
   * \sa mb_time::time
75 0bf2128a eb
   *
76 0bf2128a eb
   * \returns a valid mb_message_sptr, or the equivalent of a zero pointer
77 0bf2128a eb
   * if the call timed out while waiting.
78 0bf2128a eb
   */
79 0bf2128a eb
  mb_message_sptr get_highest_pri_msg_timedwait(const mb_time &abs_time);
80 a6db1d09 eb
};
81 a6db1d09 eb
82 a6db1d09 eb
#endif /* INCLUDED_MB_MSG_QUEUE_H */