commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] [gnuradio] 02/05: pmt: moves the rest of the PMT const


From: git
Subject: [Commit-gnuradio] [gnuradio] 02/05: pmt: moves the rest of the PMT constants from static globals to using get_ functions.
Date: Wed, 4 Mar 2015 15:29:26 +0000 (UTC)

This is an automated email from the git hooks/post-receive script.

jcorgan pushed a commit to branch master
in repository gnuradio.

commit e5646398bd8d05f6bbffd0f18710f5d8e53df4b4
Author: Tom Rondeau <address@hidden>
Date:   Thu Feb 26 14:35:26 2015 -0500

    pmt: moves the rest of the PMT constants from static globals to using get_ 
functions.
---
 gnuradio-runtime/include/pmt/pmt.h      | 25 +++++++++----
 gnuradio-runtime/lib/pmt/pmt.cc         | 62 ++++++++++++++++++++++++---------
 gnuradio-runtime/python/pmt/__init__.py |  3 ++
 gnuradio-runtime/swig/pmt_swig.i        | 12 ++++---
 4 files changed, 75 insertions(+), 27 deletions(-)

diff --git a/gnuradio-runtime/include/pmt/pmt.h 
b/gnuradio-runtime/include/pmt/pmt.h
index cb6fdf4..f601c85 100644
--- a/gnuradio-runtime/include/pmt/pmt.h
+++ b/gnuradio-runtime/include/pmt/pmt.h
@@ -88,6 +88,25 @@ public:
   notimplemented(const std::string &msg, pmt_t obj);
 };
 
+
+/*
+ * ------------------------------------------------------------------------
+ * Constants
+ * ------------------------------------------------------------------------
+ */
+
+PMT_API pmt_t get_PMT_NIL();
+PMT_API pmt_t get_PMT_T();
+PMT_API pmt_t get_PMT_F();
+PMT_API pmt_t get_PMT_EOF();
+
+#define PMT_NIL get_PMT_NIL()
+#define PMT_T get_PMT_T()
+#define PMT_F get_PMT_F()
+#define PMT_EOF get_PMT_EOF()
+
+
+
 /*
  * ------------------------------------------------------------------------
  * Booleans.  Two constants, #t and #f.
@@ -96,8 +115,6 @@ public:
  * I.e., there is a single false value, #f.
  * ------------------------------------------------------------------------
  */
-extern PMT_API const pmt_t PMT_T;      //< \#t : boolean true constant
-extern PMT_API const pmt_t PMT_F;      //< \#f : boolean false constant
 
 //! Return true if obj is \#t or \#f, else return false.
 PMT_API bool is_bool(pmt_t obj);
@@ -259,9 +276,6 @@ PMT_API std::complex<double> to_complex(pmt_t z);
  * ------------------------------------------------------------------------
  */
 
-#define PMT_NIL get_PMT_NIL()
-PMT_API pmt_t get_PMT_NIL();
-
 //! Return true if \p x is the empty list, otherwise return false.
 PMT_API bool is_null(const pmt_t& x);
 
@@ -815,7 +829,6 @@ PMT_API bool list_has(pmt_t list, const pmt_t& item);
  *                          read / write
  * ------------------------------------------------------------------------
  */
-extern PMT_API const pmt_t PMT_EOF;    //< The end of file object
 
 //! return true if obj is the EOF object, otherwise return false.
 PMT_API bool is_eof_object(pmt_t obj);
diff --git a/gnuradio-runtime/lib/pmt/pmt.cc b/gnuradio-runtime/lib/pmt/pmt.cc
index da830e1..51fb86e 100644
--- a/gnuradio-runtime/lib/pmt/pmt.cc
+++ b/gnuradio-runtime/lib/pmt/pmt.cc
@@ -34,11 +34,16 @@
 
 namespace pmt {
 
-static const int CACHE_LINE_SIZE = 64;         // good guess
-
 # if (PMT_LOCAL_ALLOCATOR)
 
-static pmt_pool global_pmt_pool(sizeof(pmt_pair), CACHE_LINE_SIZE);
+static const int
+get_cache_line_size()
+{
+  static const int CACHE_LINE_SIZE = 64;               // good guess
+  return CACHE_LINE_SIZE;
+}
+
+static pmt_pool global_pmt_pool(sizeof(pmt_pair), get_cache_line_size());
 
 void *
 pmt_base::operator new(size_t size)
@@ -46,7 +51,7 @@ pmt_base::operator new(size_t size)
   void *p = global_pmt_pool.malloc();
 
   // fprintf(stderr, "pmt_base::new p = %p\n", p);
-  assert((reinterpret_cast<intptr_t>(p) & (CACHE_LINE_SIZE - 1)) == 0);
+  assert((reinterpret_cast<intptr_t>(p) & (get_cache_line_size() - 1)) == 0);
   return p;
 }
 
@@ -158,14 +163,28 @@ _any(pmt_t x)
 //                           Globals
 ////////////////////////////////////////////////////////////////////////////
 
-const pmt_t PMT_T = pmt_t(new pmt_bool());     // singleton
-const pmt_t PMT_F = pmt_t(new pmt_bool());     // singleton
-const pmt_t PMT_EOF = cons(PMT_NIL, PMT_NIL);           // singleton
-
 pmt_t get_PMT_NIL()
 {
-  static pmt_t NIL = pmt_t(new pmt_null());
-  return NIL;
+  static pmt_t _NIL = pmt_t(new pmt_null());
+  return _NIL;
+}
+
+pmt_t get_PMT_T()
+{
+  static const pmt_t _T = pmt_t(new pmt_bool());
+  return _T;
+}
+
+pmt_t get_PMT_F()
+{
+  static const pmt_t _F = pmt_t(new pmt_bool());
+  return _F;
+}
+
+pmt_t get_PMT_EOF()
+{
+  static const pmt_t _EOF = cons(get_PMT_NIL(), get_PMT_NIL());
+  return _EOF;
 }
 
 ////////////////////////////////////////////////////////////////////////////
@@ -212,8 +231,19 @@ to_bool(pmt_t val)
 //                             Symbols
 ////////////////////////////////////////////////////////////////////////////
 
-static const unsigned int SYMBOL_HASH_TABLE_SIZE = 701;
-static std::vector<pmt_t> s_symbol_hash_table(SYMBOL_HASH_TABLE_SIZE);
+static const unsigned int
+get_symbol_hash_table_size()
+{
+  static const unsigned int SYMBOL_HASH_TABLE_SIZE = 701;
+  return SYMBOL_HASH_TABLE_SIZE;
+}
+
+static std::vector<pmt_t>*
+get_symbol_hash_table()
+{
+  static std::vector<pmt_t> s_symbol_hash_table(get_symbol_hash_table_size());
+  return &s_symbol_hash_table;
+}
 
 pmt_symbol::pmt_symbol(const std::string &name) : d_name(name){}
 
@@ -244,18 +274,18 @@ is_symbol(const pmt_t& obj)
 pmt_t
 string_to_symbol(const std::string &name)
 {
-  unsigned hash = hash_string(name) % SYMBOL_HASH_TABLE_SIZE;
+  unsigned hash = hash_string(name) % get_symbol_hash_table_size();
 
   // Does a symbol with this name already exist?
-  for (pmt_t sym = s_symbol_hash_table[hash]; sym; sym = _symbol(sym)->next()){
+  for (pmt_t sym = (*get_symbol_hash_table())[hash]; sym; sym = 
_symbol(sym)->next()){
     if (name == _symbol(sym)->name())
       return sym;              // Yes.  Return it
   }
 
   // Nope.  Make a new one.
   pmt_t sym = pmt_t(new pmt_symbol(name));
-  _symbol(sym)->set_next(s_symbol_hash_table[hash]);
-  s_symbol_hash_table[hash] = sym;
+  _symbol(sym)->set_next((*get_symbol_hash_table())[hash]);
+  (*get_symbol_hash_table())[hash] = sym;
   return sym;
 }
 
diff --git a/gnuradio-runtime/python/pmt/__init__.py 
b/gnuradio-runtime/python/pmt/__init__.py
index 1c7db73..399fae8 100644
--- a/gnuradio-runtime/python/pmt/__init__.py
+++ b/gnuradio-runtime/python/pmt/__init__.py
@@ -51,6 +51,9 @@ except ImportError:
 # due to changes in the PMT_NIL singleton for static builds, we force
 # this into Python here.
 PMT_NIL = get_PMT_NIL()
+PMT_T = get_PMT_T()
+PMT_F = get_PMT_F()
+PMT_EOF = get_PMT_EOF()
 
 from pmt_to_python import pmt_to_python as to_python
 from pmt_to_python import python_to_pmt as to_pmt
diff --git a/gnuradio-runtime/swig/pmt_swig.i b/gnuradio-runtime/swig/pmt_swig.i
index c4b6782..2063a5c 100644
--- a/gnuradio-runtime/swig/pmt_swig.i
+++ b/gnuradio-runtime/swig/pmt_swig.i
@@ -80,13 +80,15 @@ namespace pmt{
     swig_int_ptr.__repr__ = lambda self: write_string(self)
   %}
 
-
-  extern const pmt_t PMT_T;
-  extern const pmt_t PMT_F;
-  extern const pmt_t PMT_EOF;
-
   pmt_t get_PMT_NIL();
+  pmt_t get_PMT_T();
+  pmt_t get_PMT_F();
+  pmt_t get_PMT_EOF();
+
   #define PMT_NIL get_PMT_NIL()
+  #define PMT_T get_PMT_T()
+  #define PMT_F get_PMT_F()
+  #define PMT_EOF get_PMT_EOF()
 
   bool is_bool(pmt_t obj);
   bool is_true(pmt_t obj);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]