bug-commoncpp
[Top][All Lists]
Advanced

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

Re: Piostreams! Now with new identifying thread info!


From: Federico Montesino Pouzols
Subject: Re: Piostreams! Now with new identifying thread info!
Date: Fri, 17 Jan 2003 10:05:34 +0100
User-agent: Mutt/1.4i

        It is in CVS. I have noticed a little detail: sometimes the
thread id number is formatted in hex or with a leading '+'. I do not
know if it is a bug or it is done so intentionally.

On Thu, Jan 16, 2003 at 12:35:27AM -0600, Daniel E Baumann wrote:
> Here's a patch which include the previous fixes and with new
> functionality that prints out identifying thread info.
> 
> The format is (shamelessly ripped off from gdb):
> 
> [Thread <tid> (LWP <pid>)]: my regular stream output here.
> 
> Compile and run the pio.cpp demo program to see this funky stuff in
> action. I probably should say that this was a quick hack that I
> did. Ideally it should probably not be compiled in unless you compile
> cc++ with debuggin' symbols. Also, I may want to add more to the
> "header", but it's getting late here and I want to use this
> functionality to find a deadlock in some code :-o. So enjoy :).
> 
> Dan
> -- 
> And if cynics ridicule freedom, ridicule community...if ``hard nosed 
> realists'' say that profit is the only ideal...just ignore them, and use 
> copyleft all the same.
>       -- RMS
> 
> Was I helpful?  Let others know: 
>   http://svcs.affero.net/rm.php?r=chillywilly

> ? piostreams.diff
> ? config/depcomp
> ? config/texinfo.tex
> ? demo/netdevices
> ? demo/pio
> ? demo/shadigest
> ? doc/commoncpp2.info
> ? doc/commoncpp2.info-1
> ? doc/commoncpp2.info-2
> ? doc/commoncpp2.info-3
> ? include/cc++/pfstream
> ? ssl/Makefile
> ? ssl/Makefile.in
> ? win32/CCXX2.rc
> Index: include/cc++/pios_init.h
> ===================================================================
> RCS file: /cvsroot/commoncpp/commoncpp2/include/cc++/pios_init.h,v
> retrieving revision 1.1
> diff -u -3 -p -r1.1 pios_init.h
> --- include/cc++/pios_init.h  21 Sep 2002 18:26:57 -0000      1.1
> +++ include/cc++/pios_init.h  16 Jan 2003 06:25:24 -0000
> @@ -81,7 +81,7 @@ private:
>  } // namespace ost
>  #endif
>  
> -#endif /* CCXX_PIOS_INIT_H
> +#endif // CCXX_PIOS_INIT_H 
>  /** EMACS **
>   * Local variables:
>   * mode: c++
> Index: include/cc++/pistream
> ===================================================================
> RCS file: /cvsroot/commoncpp/commoncpp2/include/cc++/pistream,v
> retrieving revision 1.1
> diff -u -3 -p -r1.1 pistream
> --- include/cc++/pistream     21 Sep 2002 18:26:57 -0000      1.1
> +++ include/cc++/pistream     16 Jan 2003 06:25:24 -0000
> @@ -126,13 +126,15 @@ public:
>       pistream_type& 
>       operator>>(unsigned long& n);
>  
> -     //#ifdef _GLIBCPP_USE_LONG_LONG
> +     /*
> +     #ifdef _GLIBCPP_USE_LONG_LONG
>       pistream_type& 
>       operator>>(long long& n);
>  
>       pistream_type& 
>       operator>>(unsigned long long& n);
> -     //#endif
> +     #endif
> +     */
>  
>       pistream_type& 
>       operator>>(float& f);
> @@ -272,8 +274,8 @@ class basic_piostream
>  {
>  public:
>       // Non-standard Types:
> -     typedef basic_pistream<charT, Traits>           pistream_type;
> -     typedef basic_postream<charT, Traits>           postream_type;
> +     typedef basic_istream<charT, Traits>            istream_type;
> +     typedef basic_ostream<charT, Traits>            ostream_type;
>       
>       explicit 
>       basic_piostream(basic_streambuf<charT, Traits>* sb)
> Index: include/cc++/postream
> ===================================================================
> RCS file: /cvsroot/commoncpp/commoncpp2/include/cc++/postream,v
> retrieving revision 1.2
> diff -u -3 -p -r1.2 postream
> --- include/cc++/postream     7 Oct 2002 22:35:26 -0000       1.2
> +++ include/cc++/postream     16 Jan 2003 06:25:24 -0000
> @@ -85,7 +85,7 @@ public:
>       explicit 
>       basic_postream(streambuf_type* sb)
>               : ostream_type(sb), currth(NULL), pid(0), tid(0), lockcnt(0),
> -               owned(false), header(false)
> +               owned(false), header(true)
>       { }
>  
>       virtual 
> @@ -145,13 +145,16 @@ public:
>       operator<<(unsigned int n)
>       { return this->operator<<(static_cast<unsigned long>(n)); }
>  
> -     //#ifdef _GLIBCPP_USE_LONG_LONG
> +     /*
> +     #ifdef _GLIBCPP_USE_LONG_LONG
>       postream_type& 
>       operator<<(long long n);
>  
>       postream_type& 
>       operator<<(unsigned long long n);
> -     //#endif
> +     #endif
> +     */
> +     
>  
>       postream_type& 
>       operator<<(double f);
> @@ -410,13 +413,10 @@ public:
>       bool owned;
>       bool header;
>  
> -     void lockStream();
> -     void unlockStream();
>       void outputHeader();
>  protected:
>       mutable Mutex lock;
>       mutable Mutex lockbuf;
> -     //mutable Mutex mtx;
>  };
>  
>  /**
> Index: include/cc++/postream.tcc
> ===================================================================
> RCS file: /cvsroot/commoncpp/commoncpp2/include/cc++/postream.tcc,v
> retrieving revision 1.2
> diff -u -3 -p -r1.2 postream.tcc
> --- include/cc++/postream.tcc 7 Oct 2002 22:35:26 -0000       1.2
> +++ include/cc++/postream.tcc 16 Jan 2003 06:25:24 -0000
> @@ -98,22 +98,6 @@ operator<<(postream_type& (*pf)(postream
>       return *this;
>  }
>  
> -/*
> -  template<typename charT, typename Traits>
> -  basic_postream<charT, Traits>& 
> -  basic_postream<charT, Traits>::
> -  operator<<(ostream_type& (*pf)(ostream_type&))
> -  {
> -  // Create a psentry object (may set error bits or throw failure)
> -  typedef basic_postream<charT, Traits> postream_type;
> -  typename postream_type::psentry opfx(*this);
> -  
> -  ostream_type::operator<<(pf);
> -  
> -  return *this;
> -  }
> -*/
> -
>  template<typename charT, typename Traits>
>  basic_postream<charT, Traits>& 
>  basic_postream<charT, Traits>::
> @@ -150,6 +134,8 @@ basic_postream<charT, Traits>::operator<
>       typedef basic_postream<charT, Traits> postream_type;
>       typename postream_type::psentry opfx(*this);
>       
> +     outputHeader();
> +
>       ostream_type::operator<<(n);
>  
>       return *this;
> @@ -163,6 +149,8 @@ basic_postream<charT, Traits>::operator<
>       typedef basic_postream<charT, Traits> postream_type;
>       typename postream_type::psentry opfx(*this);
>  
> +     outputHeader();
> +
>       ostream_type::operator<<(n);
>  
>       return *this;
> @@ -176,12 +164,15 @@ basic_postream<charT, Traits>::operator<
>       typedef basic_postream<charT, Traits> postream_type;
>       typename postream_type::psentry opfx(*this);
>  
> +     outputHeader();
> +     
>       ostream_type::operator<<(n);
>        
>       return *this;
>  }
>  
> -// TODO: #ifdef USE_LONG_LONG
> +/*
> +#ifdef USE_LONG_LONG
>  template<typename charT, typename Traits>
>  basic_postream<charT, Traits>& 
>  basic_postream<charT, Traits>::operator<<(long long n)
> @@ -201,12 +192,15 @@ basic_postream<charT, Traits>::operator<
>       // Create a psentry object (may set error bits or throw failure)
>       typedef basic_postream<charT, Traits> postream_type;
>       typename postream_type::psentry opfx(*this);
> +
> +     outputHeader();
>       
>       ostream_type::operator<<(n);
>  
>       return *this;
>  }
> -//#endif
> +#endif
> +*/
>  
>  template<typename charT, typename Traits>
>  basic_postream<charT, Traits>& 
> @@ -216,6 +210,8 @@ basic_postream<charT, Traits>::operator<
>       typedef basic_postream<charT, Traits> postream_type;
>       typename postream_type::psentry opfx(*this);
>       
> +     outputHeader();
> +
>       ostream_type::operator<<(f);
>       
>       return *this;
> @@ -229,6 +225,8 @@ basic_postream<charT, Traits>::operator<
>       typedef basic_postream<charT, Traits> postream_type;
>       typename postream_type::psentry opfx(*this);
>       
> +     outputHeader(); 
> +
>       ostream_type::operator<<(f);
>        
>       return *this;
> @@ -242,6 +240,8 @@ basic_postream<charT, Traits>::operator<
>       typedef basic_postream<charT, Traits> postream_type;
>       typename postream_type::psentry opfx(*this);
>  
> +     outputHeader();
> +
>       ostream_type::operator<<(p);
>        
>       return *this;
> @@ -255,6 +255,8 @@ basic_postream<charT, Traits>::operator<
>       typedef basic_postream<charT, Traits> postream_type;
>       typename postream_type::psentry opfx(*this);
>       
> +     outputHeader();
> +
>       ostream_type::operator<<(sbin);
>       
>       return *this;
> @@ -283,7 +285,7 @@ basic_postream<charT, Traits>::write(con
>        
>       ostream_type::write(s, n);
>  
> -     retrn *this;
> +     return *this;
>  }
>  
>  template<typename charT, typename Traits>
> @@ -296,7 +298,9 @@ basic_postream<charT, Traits>::flush()
>  
>       ostream_type::flush();
>  
> -     //this->unlockStream();
> +     header = true;
> + 
> +     return *this;
>  }
>  
>  template<typename charT, typename Traits>
> @@ -366,6 +370,8 @@ operator<<(basic_postream<charT, Traits>
>       typedef basic_postream<charT, Traits> postream_type;
>       typename postream_type::psentry opfx(out);
>  
> +     out.outputHeader();
> +
>       std::operator<<(out, c);
>       
>       return out;
> @@ -402,6 +408,25 @@ basic_postream<charT, Traits>::widen(cha
>       return ostream_type::widen(c);
>  }
>  
> +template<typename charT, typename Traits>
> +void
> +basic_postream<charT, Traits>::outputHeader()
> +{
> +     pid = static_cast<int>(getpid());
> +     tid = static_cast<int>(ost::getThread()->getThreadID());
> +     if (header)
> +             {
> +                     // Call the ostream methods so as not to have
> +                     // to worry about deadlocking
> +                     std::operator<<(*this, "[Thread ");
> +                     ostream_type::operator<<(tid);
> +                     std::operator<<(*this, " (LWP ");
> +                     ostream_type::operator<<(pid);
> +                     std::operator<<(*this, ")]: ");
> +             }
> +     header = false;
> +}
> +
>  // Specializations
>  template<typename Traits>
>  basic_postream<char, Traits>&
> @@ -410,6 +435,8 @@ operator<<(basic_postream<char, Traits>&
>       typedef basic_postream<char, Traits> postream_type;
>       typename postream_type::psentry opfx(out);
>        
> +     out.outputHeader();
> +
>       std::operator<<(out, c);
>  
>       return out;
> @@ -423,6 +450,8 @@ operator<<(basic_postream<charT, Traits>
>       typedef basic_postream<char, Traits> postream_type;
>       typename postream_type::psentry opfx(out);
>       
> +     out.outputHeader();
> +
>       std::operator<<(out, s);
>       
>       return out;
> @@ -436,7 +465,7 @@ operator<<(basic_postream<charT, Traits>
>       typedef basic_postream<char, Traits> postream_type;
>       typename postream_type::psentry opfx(out);
>       
> -     out.currth = ost::getThread();
> +     out.outputHeader();
>       
>       std::operator<<(out, s);
>  
> @@ -452,9 +481,7 @@ operator<<(basic_postream<char, Traits>&
>       typedef basic_postream<char, Traits> postream_type;
>       typename postream_type::psentry opfx(out);
>       
> -     out.currth = ost::getThread();
> -     int tid = static_cast<int>(out.currth->getThreadID());
> -     //out.operator<<(tid);
> +     out.outputHeader();
>   
>       std::operator<<(out, s);
>       
> @@ -471,10 +498,7 @@ operator<<(basic_postream<charT, Traits>
>       typedef basic_postream<charT, Traits> postream_type;
>       typename postream_type::psentry opfx(out);
>  
> -     out.currth = ost::getThread();
> -     int tid = (int)out.currth->getThreadID();
> -     //printf("PID: %d\n", getpid());
> -     //printf("TID: %d\n", tid);
> +     out.outputHeader();
>  
>       std::operator<<(out, str);
>  
> Index: include/cc++/thread.h
> ===================================================================
> RCS file: /cvsroot/commoncpp/commoncpp2/include/cc++/thread.h,v
> retrieving revision 1.20
> diff -u -3 -p -r1.20 thread.h
> --- include/cc++/thread.h     9 Jan 2003 13:53:09 -0000       1.20
> +++ include/cc++/thread.h     16 Jan 2003 06:25:24 -0000
> @@ -1066,6 +1066,7 @@ friend class PosixThread;
>  /** @internal */
>  friend class DummyThread;
>  private:
> +     friend class postream_type;
>       friend class Slog;
>  
>       Semaphore joinSem;

> _______________________________________________
> Bug-commoncpp mailing list
> address@hidden
> http://mail.gnu.org/mailman/listinfo/bug-commoncpp





reply via email to

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