From cb0599f4c4484e92b0eadf7741290783989b42bf Mon Sep 17 00:00:00 2001 From: langmead Date: Fri, 8 May 2009 19:52:27 +0000 Subject: [PATCH] *** empty log message *** --- Makefile | 2 +- log.cpp | 7 +++++++ log.h | 31 +++++++++++++++++++++++++++++++ pool.h | 29 +++++++++++++++++++++++------ 4 files changed, 62 insertions(+), 7 deletions(-) create mode 100644 log.cpp create mode 100644 log.h diff --git a/Makefile b/Makefile index ffdcb1f..07eb960 100644 --- a/Makefile +++ b/Makefile @@ -56,7 +56,7 @@ LIBS = SEARCH_LIBS = $(PTHREAD_LIB) BUILD_LIBS = -SEARCH_CPPS = qual.cpp pat.cpp ebwt_search_util.cpp ref_aligner.cpp +SEARCH_CPPS = qual.cpp pat.cpp ebwt_search_util.cpp ref_aligner.cpp log.cpp OTHER_CPPS = ccnt_lut.cpp hit.cpp ref_read.cpp alphabet.c SEARCH_FRAGMENTS = $(wildcard search_*_phase*.c) MAQ_H = $(wildcard maq_convert/*.h) diff --git a/log.cpp b/log.cpp new file mode 100644 index 0000000..70766a8 --- /dev/null +++ b/log.cpp @@ -0,0 +1,7 @@ +/* + * log.cpp + */ + +#include "log.h" + +SyncLogger glog; diff --git a/log.h b/log.h new file mode 100644 index 0000000..7cdd87e --- /dev/null +++ b/log.h @@ -0,0 +1,31 @@ +#ifndef LOG_H_ +#define LOG_H_ + +#include +#include "threading.h" + +class SyncLogger { +public: + SyncLogger() { + MUTEX_INIT(lock_); + } + + void msg(const char *s) { + MUTEX_LOCK(lock_); + std::cout << s << std::endl; + MUTEX_UNLOCK(lock_); + } + + void msg(const std::string& s) { + MUTEX_LOCK(lock_); + std::cout << s << std::endl; + MUTEX_UNLOCK(lock_); + } + +private: + MUTEX_T lock_; +}; + +extern SyncLogger glog; + +#endif /*LOG_H_*/ diff --git a/pool.h b/pool.h index 62b8e6d..c467245 100644 --- a/pool.h +++ b/pool.h @@ -11,6 +11,7 @@ #include #include #include "bitset.h" +#include "log.h" /** * Very simple allocator for fixed-size chunks of memory. Chunk size @@ -89,7 +90,11 @@ class ChunkPool { } void * ptr = (void *)(&pool_[cur * chunkSz_]); bits_.set(cur); - if(verbose) cout << "Freeing chunk with offset: " << cur << endl; + if(verbose) { + stringstream ss; + ss << "Allocating chunk with offset: " << cur; + glog.msg(ss.str()); + } cur_ = cur; return ptr; } @@ -101,7 +106,11 @@ class ChunkPool { uint32_t off = (uint32_t)((int8_t*)ptr - pool_); assert_eq(0, off % chunkSz_); off /= chunkSz_; - if(verbose) cout << "Freeing chunk with offset: " << off << endl; + if(verbose) { + stringstream ss; + ss << "Freeing chunk with offset: " << cur_; + glog.msg(ss.str()); + } bits_.clear(off); } @@ -229,7 +238,9 @@ class AllocOnlyPool { void free(T* t) { assert(t != NULL); if(pool_->verbose) { - cout << "Freeing a " << name_ << endl; + stringstream ss; + ss << "Freeing a " << name_; + glog.msg(ss.str()); } if(cur_ > 0 && t == &pools_[curPool_][cur_-1]) { cur_--; @@ -237,7 +248,9 @@ class AllocOnlyPool { if(cur_ == 0 && curPool_ > 0) { assert_eq(curPool_+1, pools_.size()); if(pool_->verbose) { - cout << "Freeing a pool" << endl; + stringstream ss; + ss << "Freeing a " << name_ << " pool"; + glog.msg(ss.str()); } pool_->free(pools_.back()); pools_.pop_back(); @@ -255,7 +268,9 @@ class AllocOnlyPool { void free(T* t, uint32_t num) { assert(t != NULL); if(pool_->verbose) { - cout << "Freeing a " << name_ << "; num " << num << endl; + stringstream ss; + ss << "Freeing " << num << " " << name_ << "s"; + glog.msg(ss.str()); } if(num <= cur_ && t == &pools_[curPool_][cur_ - num]) { cur_ -= num; @@ -263,7 +278,9 @@ class AllocOnlyPool { if(cur_ == 0 && curPool_ > 0) { assert_eq(curPool_+1, pools_.size()); if(pool_->verbose) { - cout << "Freeing a pool" << endl; + stringstream ss; + ss << "Freeing a " << name_ << " pool"; + glog.msg(ss.str()); } pool_->free(pools_.back()); pools_.pop_back();