Skip to content

Commit

Permalink
*** empty log message ***
Browse files Browse the repository at this point in the history
  • Loading branch information
langmead committed May 8, 2009
1 parent a983891 commit cb0599f
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions log.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* log.cpp
*/

#include "log.h"

SyncLogger glog;
31 changes: 31 additions & 0 deletions log.h
Original file line number Diff line number Diff line change
@@ -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_*/
29 changes: 23 additions & 6 deletions pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
}

Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down

0 comments on commit cb0599f

Please sign in to comment.