[beast: 34/95] BSE: bsecore: new files for public BSE API, introduce TaskRegistry



commit 1527449a347b0205407877ad4ce17588587947b0
Author: Tim Janik <timj gnu org>
Date:   Mon Mar 18 21:23:40 2013 +0100

    BSE: bsecore: new files for public BSE API, introduce TaskRegistry

 bse/Makefile.am |    4 ++--
 bse/bse.hh      |    4 ++++
 bse/bsecore.cc  |   48 ++++++++++++++++++++++++++++++++++++++++++++++++
 bse/bsecore.hh  |   24 ++++++++++++++++++++++++
 4 files changed, 78 insertions(+), 2 deletions(-)
---
diff --git a/bse/Makefile.am b/bse/Makefile.am
index 7e9a07b..8139a90 100644
--- a/bse/Makefile.am
+++ b/bse/Makefile.am
@@ -30,7 +30,7 @@ bse_public_headers = $(strip \
        \
        bse.hh  bsedefs.hh      bseexports.hh   bseconfig.h     bsegenclosures.hh \
        bseincluder.hh  ladspa.hh       bseenginenode.hh bseieee754.hh \
-       \
+       bsecore.hh              \
        bseengine.hh            bseenginemaster.hh      bseengineschedule.hh            bseengineutils.hh \
        bsebus.hh               bsecategories.hh        \
        bsefilter.hh                    bsebiquadfilter.hh      \
@@ -63,7 +63,7 @@ bse_sources = $(strip \
        gsldatahandle-vorbis.cc gslvorbis-enc.cc        gsldatacache.cc gslvorbis-cutter.cc \
        gsldatahandle-mad.cc                    gslfilehash.cc  gsldatautils.cc \
        gslwaveosc.cc           gslosctable.cc  gslmagic.cc                      \
-       \
+       bsecore.cc              \
        bseengine.cc            bseenginemaster.cc      bseengineschedule.cc            bseengineutils.cc \
        bsebus.cc               bsecategories.cc        \
        bsefilter.cc            bsebiquadfilter.cc      bsefilter-ellf.cc       \
diff --git a/bse/bse.hh b/bse/bse.hh
index 9ea06d2..36402c3 100644
--- a/bse/bse.hh
+++ b/bse/bse.hh
@@ -1,8 +1,11 @@
 // Licensed GNU LGPL v2.1 or later: http://www.gnu.org/licenses/lgpl.html
 #ifndef __BSE_H__
 #define __BSE_H__
+
 #include <sfi/sfi.hh>
 #include <bse/bseconfig.h>
+#include <bse/bsecore.hh>
+
 G_BEGIN_DECLS
 /* initialize BSE and start the core thread */
 void           bse_init_async          (gint            *argc,
@@ -22,4 +25,5 @@ const char*          bse_check_version        (guint           required_major,
                                         guint           required_minor,
                                         guint           required_micro);
 G_END_DECLS
+
 #endif /* __BSE_H__ */
diff --git a/bse/bsecore.cc b/bse/bsecore.cc
new file mode 100644
index 0000000..61fb96b
--- /dev/null
+++ b/bse/bsecore.cc
@@ -0,0 +1,48 @@
+// Licensed GNU LGPL v2.1 or later: http://www.gnu.org/licenses/lgpl.html
+#include "bsecore.hh"
+
+namespace Bse {
+
+// == TaskRegistry ==
+static Rapicorn::Mutex    task_registry_mutex_;
+static TaskRegistry::List task_registry_tasks_;
+
+void
+TaskRegistry::add (const std::string &name, int pid, int tid)
+{
+  Rapicorn::TaskStatus task (pid, tid);
+  task.name = name;
+  task.update();
+  Rapicorn::ScopedLock<Rapicorn::Mutex> locker (task_registry_mutex_);
+  task_registry_tasks_.push_back (task);
+}
+
+bool
+TaskRegistry::remove (int tid)
+{
+  Rapicorn::ScopedLock<Rapicorn::Mutex> locker (task_registry_mutex_);
+  for (auto it = task_registry_tasks_.begin(); it != task_registry_tasks_.end(); it++)
+    if (it->task_id == tid)
+      {
+        task_registry_tasks_.erase (it);
+        return true;
+      }
+  return false;
+}
+
+void
+TaskRegistry::update ()
+{
+  Rapicorn::ScopedLock<Rapicorn::Mutex> locker (task_registry_mutex_);
+  for (auto &task : task_registry_tasks_)
+    task.update();
+}
+
+TaskRegistry::List
+TaskRegistry::list ()
+{
+  Rapicorn::ScopedLock<Rapicorn::Mutex> locker (task_registry_mutex_);
+  return task_registry_tasks_;
+}
+
+} // Bse
diff --git a/bse/bsecore.hh b/bse/bsecore.hh
new file mode 100644
index 0000000..b3aa99e
--- /dev/null
+++ b/bse/bsecore.hh
@@ -0,0 +1,24 @@
+// Licensed GNU LGPL v2.1 or later: http://www.gnu.org/licenses/lgpl.html
+#ifndef __BSE_CORE_HH__
+#define __BSE_CORE_HH__
+
+#include <bse/bse.hh>
+
+/// The Bse namespace contains all functions of the synthesis engine.
+namespace Bse {
+using namespace Birnet;         // FIXME: using Rapicorn
+
+/// The task registry keeps track of runtime threads for profiling and statistical purposes.
+class TaskRegistry {            // FIXME: move this to IDL
+public:
+  typedef std::vector<Rapicorn::TaskStatus> List;
+  static void  add     (const std::string &name, int pid,
+                        int tid = -1);  ///< Add process/thread to registry for runtime profiling.
+  static bool  remove  (int tid);       ///< Remove process/thread based on thread_id.
+  static void  update  ();              ///< Issue TaskStatus.update on all tasks in registry.
+  static List  list    ();              ///< Retrieve a copy to the list of all tasks in registry.
+};
+
+} // Bse
+
+#endif /* __BSE_CORE_HH__ */


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