vtable_example.cpp

00001 /*<std-header orig-src='shore'>
00002 
00003  $Id: vtable_example.cpp,v 1.3 2010/09/21 14:26:28 nhall Exp $
00004 
00005 SHORE -- Scalable Heterogeneous Object REpository
00006 
00007 Copyright (c) 1994-99 Computer Sciences Department, University of
00008                       Wisconsin -- Madison
00009 All Rights Reserved.
00010 
00011 Permission to use, copy, modify and distribute this software and its
00012 documentation is hereby granted, provided that both the copyright
00013 notice and this permission notice appear in all copies of the
00014 software, derivative works or modified versions, and any portions
00015 thereof, and that both notices appear in supporting documentation.
00016 
00017 THE AUTHORS AND THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY
00018 OF WISCONSIN - MADISON ALLOW FREE USE OF THIS SOFTWARE IN ITS
00019 "AS IS" CONDITION, AND THEY DISCLAIM ANY LIABILITY OF ANY KIND
00020 FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
00021 
00022 This software was developed with support by the Advanced Research
00023 Project Agency, ARPA order number 018 (formerly 8230), monitored by
00024 the U.S. Army Research Laboratory under contract DAAB07-91-C-Q518.
00025 Further funding for this work was provided by DARPA through
00026 Rome Research Laboratory Contract No. F30602-97-2-0247.
00027 
00028 */
00029 
00030 #include "w_defines.h"
00031 
00032 /*  -- do not edit anything above this line --   </std-header>*/
00033 
00034 #define SUBSTITUTE_MAIN
00035 #include "create_rec.cpp"
00036 
00037 class smthread_user_t : public smthread_driver_t
00038 {
00039     rc_t do_work();
00040 
00041 public:
00042     smthread_user_t(int ac, char **av) 
00043                 : smthread_driver_t(ac, av) {}
00044 
00045     virtual ~smthread_user_t()  { }
00046     w_rc_t vtable_locks() const;
00047     w_rc_t vtable_threads() const;
00048     w_rc_t vtable_xcts() const;
00049 };
00050 
00051 rc_t 
00052 smthread_user_t::do_work()
00053 {
00054     if (_initialize_device) W_DO(do_init());
00055     else  W_DO(no_init());
00056 
00057     /* instead of printing the sm statistics, 
00058      * use the virtual tables and print what they show.
00059      * This won't show much if used when there are
00060      * no transactions, 
00061      * but the threads table will show the checkpoint
00062      * and cleaner threads, and this will at least
00063      * show how to populate the virtual tables.
00064      */
00065 
00066     W_DO(vtable_locks());
00067     W_DO(vtable_xcts());
00068     W_DO(vtable_threads());
00069     return RCOK;
00070 }
00071 
00072 w_rc_t
00073 smthread_user_t::vtable_locks()  const
00074 {
00075     vtable_t vt;
00076     W_DO(ss_m::lock_collect(vt));
00077     w_ostrstream o;
00078     vt.operator<<(o);
00079     fprintf(stderr, "Locks %s\n", o.c_str());
00080     return RCOK;
00081 }
00082 
00083 w_rc_t
00084 smthread_user_t::vtable_xcts()  const
00085 {
00086     vtable_t vt;
00087     W_DO(ss_m::xct_collect(vt));
00088     w_ostrstream o;
00089     vt.operator<<(o);
00090     fprintf(stderr, "Transactions %s\n", o.c_str());
00091     return RCOK;
00092 }
00093 
00094 w_rc_t
00095 smthread_user_t::vtable_threads()  const
00096 {
00097     vtable_t vt;
00098     W_DO(ss_m::thread_collect(vt));
00099     w_ostrstream o;
00100     vt.operator<<(o);
00101     fprintf(stderr, "Transactions %s\n", o.c_str());
00102     return RCOK;
00103 }
00104 
00105 int
00106 main(int argc, char* argv[])
00107 {
00108     argv0 = argv[0];
00109 
00110     smthread_user_t *smtu = new smthread_user_t(argc, argv);
00111     if (!smtu)
00112             W_FATAL(fcOUTOFMEMORY);
00113 
00114     w_rc_t e = smtu->fork();
00115     if(e.is_error()) {
00116         cerr << "error forking thread: " << e <<endl;
00117         return 1;
00118     }
00119     e = smtu->join();
00120     if(e.is_error()) {
00121         cerr << "error forking thread: " << e <<endl;
00122         return 1;
00123     }
00124 
00125     int        rv = smtu->return_value();
00126     delete smtu;
00127 
00128     return rv;
00129 }
00130 

Generated on Thu Dec 9 08:42:26 2010 for Shore Storage Manager by  doxygen 1.4.7