[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r5054 - gnuradio/branches/developers/eb/ibu/mblock/src
From: |
eb |
Subject: |
[Commit-gnuradio] r5054 - gnuradio/branches/developers/eb/ibu/mblock/src/lib |
Date: |
Fri, 20 Apr 2007 15:01:31 -0600 (MDT) |
Author: eb
Date: 2007-04-20 15:01:30 -0600 (Fri, 20 Apr 2007)
New Revision: 5054
Added:
gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_timer_queue.cc
gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_timer_queue.h
Modified:
gnuradio/branches/developers/eb/ibu/mblock/src/lib/Makefile.am
gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_runtime_thread_per_block.cc
gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_runtime_thread_per_block.h
Log:
work-in-progress on mblock timeouts
Modified: gnuradio/branches/developers/eb/ibu/mblock/src/lib/Makefile.am
===================================================================
--- gnuradio/branches/developers/eb/ibu/mblock/src/lib/Makefile.am
2007-04-20 20:49:26 UTC (rev 5053)
+++ gnuradio/branches/developers/eb/ibu/mblock/src/lib/Makefile.am
2007-04-20 21:01:30 UTC (rev 5054)
@@ -58,6 +58,7 @@
mb_runtime_base.cc \
mb_runtime_nop.cc \
mb_runtime_thread_per_block.cc \
+ mb_timer_queue.cc \
mb_util.cc \
mb_worker.cc
@@ -97,6 +98,7 @@
mb_runtime_base.h \
mb_runtime_nop.h \
mb_runtime_thread_per_block.h \
+ mb_timer_queue.h \
mb_worker.h \
mbi_runtime_lock.h \
qa_mblock.h \
Modified:
gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_runtime_thread_per_block.cc
===================================================================
---
gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_runtime_thread_per_block.cc
2007-04-20 20:49:26 UTC (rev 5053)
+++
gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_runtime_thread_per_block.cc
2007-04-20 21:01:30 UTC (rev 5054)
@@ -36,10 +36,11 @@
static pmt_t s_halt = pmt_intern("%halt");
static pmt_t s_sys_port = pmt_intern("%sys-port");
static pmt_t s_shutdown = pmt_intern("%shutdown");
-static pmt_t s_shutdown_request = pmt_intern("%shutdown-request");
+static pmt_t s_request_shutdown = pmt_intern("%request-shutdown");
static pmt_t s_worker_state_changed = pmt_intern("%worker-state-changed");
static pmt_t s_timeout = pmt_intern("%timeout");
-static pmt_t s_timeout_request = pmt_intern("%timeout-request");
+static pmt_t s_request_timeout = pmt_intern("%request-timeout");
+static pmt_t s_cancel_timeout = pmt_intern("%cancel-timeout");
static void
send_sys_msg(mb_msg_queue &msgq, pmt_t signal,
@@ -71,7 +72,7 @@
void
mb_runtime_thread_per_block::request_shutdown(pmt_t result)
{
- (*accepter())(s_shutdown_request, result, PMT_F, MB_PRI_BEST);
+ (*accepter())(s_request_shutdown, result, PMT_F, MB_PRI_BEST);
}
bool
@@ -125,12 +126,12 @@
pmt_t signal = msg->signal();
if (pmt_eq(signal, s_worker_state_changed)){ // %worker-state-changed
- omni_mutex_lock l1(d_mutex);
+ omni_mutex_lock l1(d_workers_mutex);
reap_dead_workers();
if (d_workers.empty()) // no work left to do...
return;
}
- else if (pmt_eq(signal, s_shutdown_request)){ // %shutdown-request
+ else if (pmt_eq(signal, s_request_shutdown)){ // %request-shutdown
if (!d_shutdown_in_progress){
d_shutdown_in_progress = true;
d_shutdown_result = msg->data();
@@ -141,8 +142,12 @@
}
}
- //else if (pmt_eq(signal, s_timeout_request)){ // %timeout-request
- //}
+ else if (pmt_eq(signal, s_request_timeout)){ // %request-timeout
+ std::cerr << "mb_runtime_thread_per_block: unimplemented msg: " << msg
<< std::endl;
+ }
+ else if (pmt_eq(signal, s_cancel_timeout)){ //
%cancel-timeout
+ std::cerr << "mb_runtime_thread_per_block: unimplemented msg: " << msg
<< std::endl;
+ }
else {
std::cerr << "mb_runtime_thread_per_block: unhandled msg: " << msg <<
std::endl;
}
@@ -152,7 +157,8 @@
void
mb_runtime_thread_per_block::reap_dead_workers()
{
- // omni_mutex_lock l1(d_mutex);
+ // Already holding mutex
+ // omni_mutex_lock l1(d_workers_mutex);
for (worker_iter_t wi = d_workers.begin(); wi != d_workers.end(); ){
bool is_dead;
@@ -185,6 +191,8 @@
// Create the thread, then create the component in the thread.
// Return a pointer to the created mblock.
//
+// Can be invoked from any thread
+//
mb_mblock_sptr
mb_runtime_thread_per_block::create_component(const std::string &instance_name,
const std::string &class_name,
@@ -234,7 +242,7 @@
// Add w to the vector of workers, and return the mblock.
{
- omni_mutex_lock l(d_mutex);
+ omni_mutex_lock l(d_workers_mutex);
d_workers.push_back(w);
}
@@ -252,8 +260,7 @@
pmt_t metadata,
mb_pri_t priority)
{
- // Already holding lock
- // omni_mutex_lock l1(d_mutex);
+ omni_mutex_lock l1(d_workers_mutex);
for (worker_iter_t wi = d_workers.begin(); wi != d_workers.end(); ++wi){
send_sys_msg((*wi)->d_mblock->impl()->msgq(),
@@ -261,21 +268,39 @@
}
}
+//
+// Can be invoked from any thread.
+//
mb_time
-mb_runtime_thread_per_block::time(const mb_time &relative_offset)
+mb_runtime_thread_per_block::time(const mb_time &delta_t)
{
- return mb_time(); // FIXME
+ unsigned long abs_sec, abs_nsec;
+ unsigned long rel_sec = delta_t.d_sec;
+ unsigned long rel_nsec = delta_t.d_nsec;
+
+ omni_thread::get_time(&abs_sec, &abs_nsec, rel_sec, rel_nsec);
+ return mb_time(abs_sec, abs_nsec);
}
+//
+// Can be invoked from any thread.
+// Sends a message to the runtime.
+//
pmt_t
mb_runtime_thread_per_block::schedule_one_shot_timeout
(const mb_time &abs_time,
pmt_t user_data,
mb_msg_accepter_sptr accepter)
{
- return PMT_F; // FIXME
+ mb_timeout_sptr to(new mb_timeout(abs_time, user_data, accepter));
+ (*d_accepter)(s_request_timeout, pmt_make_any(to), PMT_F, MB_PRI_BEST);
+ return to->handle();
}
+//
+// Can be invoked from any thread.
+// Sends a message to the runtime.
+//
pmt_t
mb_runtime_thread_per_block::schedule_periodic_timeout
(const mb_time &first_abs_time,
@@ -283,12 +308,19 @@
pmt_t user_data,
mb_msg_accepter_sptr accepter)
{
- return PMT_F; // FIXME
+ mb_timeout_sptr to(new mb_timeout(first_abs_time, delta_time,
+ user_data, accepter));
+ (*d_accepter)(s_request_timeout, pmt_make_any(to), PMT_F, MB_PRI_BEST);
+ return to->handle();
}
+//
+// Can be invoked from any thread.
+// Sends a message to the runtime.
+//
void
mb_runtime_thread_per_block::cancel_timeout(pmt_t handle)
{
- // FIXME
+ (*d_accepter)(s_cancel_timeout, handle, PMT_F, MB_PRI_BEST);
}
Modified:
gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_runtime_thread_per_block.h
===================================================================
---
gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_runtime_thread_per_block.h
2007-04-20 20:49:26 UTC (rev 5053)
+++
gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_runtime_thread_per_block.h
2007-04-20 21:01:30 UTC (rev 5054)
@@ -24,6 +24,7 @@
#include <mb_runtime_base.h>
#include <mb_worker.h>
#include <mb_msg_queue.h>
+#include <mb_timer_queue.h>
/*!
* \brief Concrete runtime that uses a thread per mblock
@@ -34,11 +35,12 @@
class mb_runtime_thread_per_block : public mb_runtime_base
{
public:
- omni_mutex d_mutex;
+ omni_mutex d_workers_mutex; // hold while manipulating
d_workers
std::vector<mb_worker*> d_workers;
bool d_shutdown_in_progress;
pmt_t d_shutdown_result;
mb_msg_queue d_msgq;
+ mb_timer_queue d_timer_queue;
typedef std::vector<mb_worker*>::iterator worker_iter_t;
@@ -58,13 +60,6 @@
const std::string &class_name,
pmt_t user_arg);
- void reap_dead_workers();
- void run_loop();
-
- void send_all_sys_msg(pmt_t signal, pmt_t data = PMT_F,
- pmt_t metadata = PMT_F,
- mb_pri_t priority = MB_PRI_BEST);
-
mb_time
time(const mb_time &relative_offset);
@@ -80,6 +75,13 @@
void
cancel_timeout(pmt_t handle);
+private:
+ void reap_dead_workers();
+ void run_loop();
+
+ void send_all_sys_msg(pmt_t signal, pmt_t data = PMT_F,
+ pmt_t metadata = PMT_F,
+ mb_pri_t priority = MB_PRI_BEST);
};
#endif /* INCLUDED_MB_RUNTIME_THREAD_PER_BLOCK_H */
Added: gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_timer_queue.cc
===================================================================
--- gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_timer_queue.cc
(rev 0)
+++ gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_timer_queue.cc
2007-04-20 21:01:30 UTC (rev 5054)
@@ -0,0 +1,55 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <mb_timer_queue.h>
+
+static pmt_t
+make_handle()
+{
+ static long counter = 0;
+ pmt_t n = pmt_from_long(counter++);
+ return pmt_list1(n); // guaranteed to be a unique object
+}
+
+// one-shot constructor
+mb_timeout::mb_timeout(const mb_time &abs_time,
+ pmt_t user_data, mb_msg_accepter_sptr accepter)
+ : d_when(abs_time), d_is_periodic(false),
+ d_user_data(user_data), d_handle(make_handle()), d_accepter(accepter)
+{
+}
+
+// periodic constructor
+mb_timeout::mb_timeout(const mb_time &first_abs_time, const mb_time
&delta_time,
+ pmt_t user_data, mb_msg_accepter_sptr accepter)
+ : d_when(first_abs_time), d_delta(delta_time), d_is_periodic(true),
+ d_user_data(user_data), d_handle(make_handle()), d_accepter(accepter)
+{
+}
+
+void
+mb_timer_queue::cancel(pmt_t handle)
+{
+ // FIXME
+}
Added: gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_timer_queue.h
===================================================================
--- gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_timer_queue.h
(rev 0)
+++ gnuradio/branches/developers/eb/ibu/mblock/src/lib/mb_timer_queue.h
2007-04-20 21:01:30 UTC (rev 5054)
@@ -0,0 +1,74 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef INCLUDED_MB_TIMER_QUEUE_H
+#define INCLUDED_MB_TIMER_QUEUE_H
+
+#include <mb_time.h>
+#include <vector>
+#include <queue>
+#include <pmt.h>
+#include <mb_msg_accepter.h>
+
+class mb_timeout {
+public:
+ mb_time d_when; // absolute time to fire timeout
+ mb_time d_delta; // if periodic, delta_t to next timeout
+ bool d_is_periodic; // true iff this is a periodic timeout
+ pmt_t d_user_data; // data from %timeout msg
+ pmt_t d_handle; // handle for cancellation
+ mb_msg_accepter_sptr d_accepter; // where to send the message
+
+ // one-shot constructor
+ mb_timeout(const mb_time &abs_time,
+ pmt_t user_data, mb_msg_accepter_sptr accepter);
+
+ // periodic constructor
+ mb_timeout(const mb_time &first_abs_time, const mb_time &delta_time,
+ pmt_t user_data, mb_msg_accepter_sptr accepter);
+
+ pmt_t handle() const { return d_handle; }
+};
+
+typedef boost::shared_ptr<mb_timeout> mb_timeout_sptr;
+
+
+//! Sort criterion for priority_queue
+class timeout_later
+{
+public:
+ bool operator() (const mb_timeout_sptr t1, const mb_timeout_sptr t2)
+ {
+ return ((t1->d_when.d_sec > t2->d_when.d_sec)
+ || (t1->d_when.d_sec == t2->d_when.d_sec
+ && t1->d_when.d_nsec > t2->d_when.d_nsec));
+ }
+};
+
+class mb_timer_queue : public std::priority_queue<mb_timeout_sptr,
+ std::vector<mb_timeout_sptr>,
+ timeout_later>
+{
+public:
+ void cancel(pmt_t handle);
+};
+
+#endif /* INCLUDED_MB_TIMER_QUEUE_H */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r5054 - gnuradio/branches/developers/eb/ibu/mblock/src/lib,
eb <=