Permalink
Browse files

*** empty log message ***

  • Loading branch information...
1 parent a983891 commit cb0599f4c4484e92b0eadf7741290783989b42bf langmead committed May 8, 2009
Showing with 62 additions and 7 deletions.
  1. +1 −1 Makefile
  2. +7 −0 log.cpp
  3. +31 −0 log.h
  4. +23 −6 pool.h
View
@@ -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)
View
@@ -0,0 +1,7 @@
+/*
+ * log.cpp
+ */
+
+#include "log.h"
+
+SyncLogger glog;
View
31 log.h
@@ -0,0 +1,31 @@
+#ifndef LOG_H_
+#define LOG_H_
+
+#include <iostream>
+#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_*/
View
29 pool.h
@@ -11,6 +11,7 @@
#include <string.h>
#include <stdlib.h>
#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,15 +238,19 @@ 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_--;
ASSERT_ONLY(memset(&pools_[curPool_][cur_], 0, sizeof(T)));
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,15 +268,19 @@ 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;
ASSERT_ONLY(memset(&pools_[curPool_][cur_], 0, num * sizeof(T)));
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();

0 comments on commit cb0599f

Please sign in to comment.