Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00013 #ifndef IO_LOCK_H
00014 #define IO_LOCK_H
00015
00016 #include <boost/thread.hpp>
00017 #include <iostream>
00018
00023 template<int fd>
00024 class cout_lock {
00025 public:
00026 cout_lock() : i(0) {m_mut.lock();}
00027 ~cout_lock() {m_mut.unlock();}
00028 void incr() {i++;}
00029 bool stop() {return i < 1;}
00030 private:
00031 int i;
00032 static boost::mutex m_mut;
00033 };
00034
00035 template<int fd>
00036 boost::mutex cout_lock<fd>::m_mut;
00037
00043 #define L_COUT \
00044 for (cout_lock<1> cout_lock_instance; \
00045 cout_lock_instance.stop(); \
00046 cout_lock_instance.incr()) std::cout
00047
00051 #define L_CERR \
00052 for (cout_lock<2> cout_lock_instance; \
00053 cout_lock_instance.stop(); \
00054 cout_lock_instance.incr()) std::cerr
00055
00059 #ifdef SC_DURING_DEBUG
00060 #define D_COUT L_COUT
00061 #else
00062 #define D_COUT if (0) L_COUT
00063 #endif
00064
00065 #endif // IO_LOCK_H