commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r8227 - in gnuradio/branches/developers/eb/gcell/gcell


From: eb
Subject: [Commit-gnuradio] r8227 - in gnuradio/branches/developers/eb/gcell/gcell/src/lib: runtime wrapper
Date: Sat, 19 Apr 2008 20:34:05 -0600 (MDT)

Author: eb
Date: 2008-04-19 20:34:05 -0600 (Sat, 19 Apr 2008)
New Revision: 8227

Modified:
   gnuradio/branches/developers/eb/gcell/gcell/src/lib/runtime/gc_job_manager.cc
   gnuradio/branches/developers/eb/gcell/gcell/src/lib/runtime/gc_job_manager.h
   gnuradio/branches/developers/eb/gcell/gcell/src/lib/wrapper/gcp_fft_1d_r2.cc
   gnuradio/branches/developers/eb/gcell/gcell/src/lib/wrapper/gcp_fft_1d_r2.h
   
gnuradio/branches/developers/eb/gcell/gcell/src/lib/wrapper/qa_gcp_fft_1d_r2.cc
Log:
Added static method that returns boost::shared_ptr to gc_job_desc.
This simplifies object management and makes it easier to be exception safe.


Modified: 
gnuradio/branches/developers/eb/gcell/gcell/src/lib/runtime/gc_job_manager.cc
===================================================================
--- 
gnuradio/branches/developers/eb/gcell/gcell/src/lib/runtime/gc_job_manager.cc   
    2008-04-20 01:58:21 UTC (rev 8226)
+++ 
gnuradio/branches/developers/eb/gcell/gcell/src/lib/runtime/gc_job_manager.cc   
    2008-04-20 02:34:05 UTC (rev 8227)
@@ -31,6 +31,19 @@
 static boost::weak_ptr<gc_job_manager> s_singleton;
 
 
+// custom deleter of gc_job_desc allocated via alloc_job_desc_sptr
+class job_desc_deleter {
+  gc_job_manager_sptr  d_mgr;
+public:
+  job_desc_deleter(gc_job_manager_sptr mgr) : d_mgr(mgr) {}
+
+  void operator()(gc_job_desc *jd) {
+    d_mgr->free_job_desc(jd);
+  }
+};
+
+
+
 gc_job_manager_sptr
 gc_make_job_manager(const gc_jm_options *options)
 {
@@ -71,6 +84,19 @@
   return gc_job_manager_sptr(s_singleton);
 }
 
+gc_job_desc_sptr 
+gc_job_manager::make_jd_sptr(gc_job_manager_sptr mgr, gc_job_desc *jd)
+{
+  return gc_job_desc_sptr(jd, job_desc_deleter(mgr));
+}
+
+gc_job_desc_sptr 
+gc_job_manager::alloc_job_desc(gc_job_manager_sptr mgr)
+{
+  return make_jd_sptr(mgr, mgr->alloc_job_desc());
+}
+
+
 // ------------------------------------------------------------------------
 
 

Modified: 
gnuradio/branches/developers/eb/gcell/gcell/src/lib/runtime/gc_job_manager.h
===================================================================
--- 
gnuradio/branches/developers/eb/gcell/gcell/src/lib/runtime/gc_job_manager.h    
    2008-04-20 01:58:21 UTC (rev 8226)
+++ 
gnuradio/branches/developers/eb/gcell/gcell/src/lib/runtime/gc_job_manager.h    
    2008-04-20 02:34:05 UTC (rev 8227)
@@ -33,6 +33,7 @@
 class gc_job_manager;
 typedef boost::shared_ptr<gc_job_manager> gc_job_manager_sptr;
 typedef boost::shared_ptr<spe_program_handle_t> spe_program_handle_sptr;
+typedef boost::shared_ptr<gc_job_desc> gc_job_desc_sptr;
 
 /*!
  * \brief Return a boost::shared_ptr to an spe_program_handle_t
@@ -236,6 +237,11 @@
    */
   virtual std::vector<std::string> proc_names() = 0;
 
+  virtual void set_debug(int debug);
+  virtual int debug();
+
+  /* ----- static methods ----- */
+
   /*!
    * \brief Set the singleton gc_job_manager instance.
    * \param mgr is the job manager instance.
@@ -256,9 +262,15 @@
    */
   static gc_job_manager_sptr singleton();
 
+  /*!
+   * \brief return a boost::shared_ptr to a job descriptor.
+   */
+  static gc_job_desc_sptr make_jd_sptr(gc_job_manager_sptr mgr, gc_job_desc 
*jd);
 
-  virtual void set_debug(int debug);
-  virtual int debug();
+  /*!
+   * \brief allocate a job descriptor and return a boost::shared_ptr to it.
+   */
+  static gc_job_desc_sptr alloc_job_desc(gc_job_manager_sptr mgr);
 };
 
 

Modified: 
gnuradio/branches/developers/eb/gcell/gcell/src/lib/wrapper/gcp_fft_1d_r2.cc
===================================================================
--- 
gnuradio/branches/developers/eb/gcell/gcell/src/lib/wrapper/gcp_fft_1d_r2.cc    
    2008-04-20 01:58:21 UTC (rev 8226)
+++ 
gnuradio/branches/developers/eb/gcell/gcell/src/lib/wrapper/gcp_fft_1d_r2.cc    
    2008-04-20 02:34:05 UTC (rev 8227)
@@ -66,7 +66,7 @@
 }
 
   
-gc_job_desc *
+gc_job_desc_sptr
 gcp_fft_1d_r2_submit(gc_job_manager_sptr mgr,
                     unsigned int log2_fft_length,
                     bool forward,
@@ -96,11 +96,10 @@
     proc_name = "inv_fft_1d_r2";
 
   gc_proc_id_t fft_id = mgr->lookup_proc(proc_name);
-  gc_job_desc *jd = mgr->alloc_job_desc();
-  init_jd(jd, fft_id, log2_fft_length, shift, out, in, twiddle, window);
-  if (!mgr->submit_job(jd)){
+  gc_job_desc_sptr jd = gc_job_manager::alloc_job_desc(mgr);
+  init_jd(jd.get(), fft_id, log2_fft_length, shift, out, in, twiddle, window);
+  if (!mgr->submit_job(jd.get())){
     gc_job_status_t s = jd->status;
-    mgr->free_job_desc(jd);
     throw gc_bad_submit(proc_name, s);
   }
   return jd;

Modified: 
gnuradio/branches/developers/eb/gcell/gcell/src/lib/wrapper/gcp_fft_1d_r2.h
===================================================================
--- gnuradio/branches/developers/eb/gcell/gcell/src/lib/wrapper/gcp_fft_1d_r2.h 
2008-04-20 01:58:21 UTC (rev 8226)
+++ gnuradio/branches/developers/eb/gcell/gcell/src/lib/wrapper/gcp_fft_1d_r2.h 
2008-04-20 02:34:05 UTC (rev 8227)
@@ -37,12 +37,12 @@
  * \param window is the window to be applied to the input data.
  *    The window length must be either 0 or fft_length (must be 16-byte 
aligned).
  *
- * Returns a job descriptor which should be passed to wait_job*.
+ * Returns a shared_ptr to a job descriptor which should be passed to 
wait_job*.
  * Throws an exception in the event of a problem.
  * This uses the FFTW conventions for scaling.  That is, neither the forward 
nor inverse
  * are scaled by 1/fft_length.
  */
-gc_job_desc *
+gc_job_desc_sptr
 gcp_fft_1d_r2_submit(gc_job_manager_sptr mgr,
                     unsigned int log2_fft_length,
                     bool forward,

Modified: 
gnuradio/branches/developers/eb/gcell/gcell/src/lib/wrapper/qa_gcp_fft_1d_r2.cc
===================================================================
--- 
gnuradio/branches/developers/eb/gcell/gcell/src/lib/wrapper/qa_gcp_fft_1d_r2.cc 
    2008-04-20 01:58:21 UTC (rev 8226)
+++ 
gnuradio/branches/developers/eb/gcell/gcell/src/lib/wrapper/qa_gcp_fft_1d_r2.cc 
    2008-04-20 02:34:05 UTC (rev 8227)
@@ -180,14 +180,12 @@
 
   // ------------------------------------------------------------------------
   // compute the answer on the cell
-  gc_job_desc *jd = gcp_fft_1d_r2_submit(mgr, log2_fft_size, forward, false,
-                                        cell_out, cell_in, cell_twiddle, 0);
-  if (!mgr->wait_job(jd)){
+  gc_job_desc_sptr jd = gcp_fft_1d_r2_submit(mgr, log2_fft_size, forward, 
false,
+                                            cell_out, cell_in, cell_twiddle, 
0);
+  if (!mgr->wait_job(jd.get())){
     fprintf(stderr, "wait_job failed: %s\n", 
gc_job_status_string(jd->status).c_str());
-    mgr->free_job_desc(jd);
     CPPUNIT_ASSERT(0);
   }
-  mgr->free_job_desc(jd);
 
   // ------------------------------------------------------------------------
   // compute the maximum of the relative error





reply via email to

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