Updated license from GPL version 2 or later to GPL version 3 or later.
[debian/gnuradio] / mblock / src / lib / mb_message.cc
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2006 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 <mb_message.h>
26 #include <stdio.h>
27 #include <pmt_pool.h>
28
29 static const int CACHE_LINE_SIZE = 64;          // good guess
30
31
32 #if MB_MESSAGE_LOCAL_ALLOCATOR
33
34 static pmt_pool global_msg_pool(sizeof(mb_message), CACHE_LINE_SIZE);
35
36 void *
37 mb_message::operator new(size_t size)
38 {
39   void *p = global_msg_pool.malloc();
40
41   // fprintf(stderr, "mb_message::new p = %p\n", p);
42   assert((reinterpret_cast<intptr_t>(p) & (CACHE_LINE_SIZE - 1)) == 0);
43   return p;
44 }
45
46 void
47 mb_message::operator delete(void *p, size_t size)
48 {
49   global_msg_pool.free(p);
50 }
51
52 #endif
53
54
55 mb_message_sptr
56 mb_make_message(pmt_t signal, pmt_t data, pmt_t metadata, mb_pri_t priority)
57 {
58   return mb_message_sptr(new mb_message(signal, data, metadata, priority));
59 }
60
61 mb_message::mb_message(pmt_t signal, pmt_t data, pmt_t metadata, mb_pri_t priority)
62   : d_signal(signal), d_data(data), d_metadata(metadata), d_priority(priority),
63     d_port_id(PMT_NIL)
64 {
65 }
66
67 mb_message::~mb_message()
68 {
69   // NOP
70 }
71
72 std::ostream& 
73 operator<<(std::ostream& os, const mb_message &msg)
74 {
75   os << "<msg: signal=" << msg.signal()
76      << " port_id=" << msg.port_id()
77      << " data=" << msg.data()
78      << " metadata=" << msg.metadata()
79      << " pri=" << msg.priority()
80      << ">";
81   
82   return os;
83 }