Fixing up GUI windows to better scale with gtgui sinks.
[debian/gnuradio] / mblock / src / lib / mb_message.cc
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2006,2008,2009 Free Software Foundation, Inc.
4  * 
5  * This file is part of GNU Radio
6  * 
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  * 
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25 #include <mblock/message.h>
26 #include <stdio.h>
27 #include <gruel/pmt_pool.h>
28
29 using namespace pmt;
30
31 static const int CACHE_LINE_SIZE = 64;  // good guess
32 static const int MAX_MESSAGES =  1024;  // KLUDGE max number of messages in sys
33                                         //   0 -> no limit
34 #if MB_MESSAGE_LOCAL_ALLOCATOR
35
36 static pmt_pool 
37 global_msg_pool(sizeof(mb_message), CACHE_LINE_SIZE, 16*1024, MAX_MESSAGES);
38
39 void *
40 mb_message::operator new(size_t size)
41 {
42   void *p = global_msg_pool.malloc();
43
44   // fprintf(stderr, "mb_message::new p = %p\n", p);
45   assert((reinterpret_cast<intptr_t>(p) & (CACHE_LINE_SIZE - 1)) == 0);
46   return p;
47 }
48
49 void
50 mb_message::operator delete(void *p, size_t size)
51 {
52   global_msg_pool.free(p);
53 }
54
55 #endif
56
57
58 mb_message_sptr
59 mb_make_message(pmt_t signal, pmt_t data, pmt_t metadata, mb_pri_t priority)
60 {
61   return mb_message_sptr(new mb_message(signal, data, metadata, priority));
62 }
63
64 mb_message::mb_message(pmt_t signal, pmt_t data, pmt_t metadata, mb_pri_t priority)
65   : d_signal(signal), d_data(data), d_metadata(metadata), d_priority(priority),
66     d_port_id(PMT_NIL)
67 {
68 }
69
70 mb_message::~mb_message()
71 {
72   // NOP
73 }
74
75 std::ostream& 
76 operator<<(std::ostream& os, const mb_message &msg)
77 {
78   os << "<msg: signal=" << msg.signal()
79      << " port_id=" << msg.port_id()
80      << " data=" << msg.data()
81      << " metadata=" << msg.metadata()
82      << " pri=" << msg.priority()
83      << ">";
84   
85   return os;
86 }