[Assorted-commits] SF.net SVN: assorted: [393] cpp-commons/trunk/src/commons
Brought to you by:
yangzhang
From: <yan...@us...> - 2008-02-12 18:01:23
|
Revision: 393 http://assorted.svn.sourceforge.net/assorted/?rev=393&view=rev Author: yangzhang Date: 2008-02-12 10:01:24 -0800 (Tue, 12 Feb 2008) Log Message: ----------- added some debug output Modified Paths: -------------- cpp-commons/trunk/src/commons/check.h cpp-commons/trunk/src/commons/region.h Modified: cpp-commons/trunk/src/commons/check.h =================================================================== --- cpp-commons/trunk/src/commons/check.h 2008-02-12 18:01:17 UTC (rev 392) +++ cpp-commons/trunk/src/commons/check.h 2008-02-12 18:01:24 UTC (rev 393) @@ -42,8 +42,19 @@ * evaluation of msg. */ #define checkmsg(cond, msg) \ - bool b = cond; \ - if (!b) _check(b, (msg), __FILE__, __LINE__) + bool b__ = cond; \ + if (!b__) _check(b__, (msg), __FILE__, __LINE__) +// TODO: half-written +#define checkmsgf(cond, msg, ...) \ + do { \ + bool b__ = cond; \ + if (!b__) { \ + char s__[4096]; \ + snprintf(s, ); \ + _check(b__, s__, __FILE__, __LINE__); \ + } \ + } while (0) + #endif Modified: cpp-commons/trunk/src/commons/region.h =================================================================== --- cpp-commons/trunk/src/commons/region.h 2008-02-12 18:01:17 UTC (rev 392) +++ cpp-commons/trunk/src/commons/region.h 2008-02-12 18:01:24 UTC (rev 393) @@ -5,6 +5,10 @@ #include <limits> +// XXX: debug +#include <set> +#include <pthread.h> + namespace commons { @@ -39,6 +43,7 @@ const size_t chunk_size; size_t top; int refcount; + set<pthread_t> threads; public: mem_region() : @@ -46,12 +51,13 @@ top(0), refcount(0) { + cout << "created " << this << endl; chunks.push_back((chunk) {chunk_size, new char[chunk_size]}); } ~mem_region() { - // cout << "deleting" << endl; + cout << "deleting" << endl; for (unsigned int i = 0; i < chunks.size(); i++) { delete [] chunks[i].data; } @@ -62,13 +68,15 @@ void *alloc_mem(size_t n) { - if (top + n > chunk_size) { - // chunks.push_back(new char[chunk_size]); - size_t sz = max(n, chunk_size); - chunks.push_back((chunk) {sz, new char[sz] }); + pthread_t t = pthread_self(); + if (threads.insert(t).second) + cout << this << " -- " << t << endl; + + if (top + n > chunks.back().size) { + size_t sz = max(n, chunk_size); + chunks.push_back((chunk) {sz, new char[sz] }); top = 0; } - // cout << "alloced" << endl; size_t old_top = top; top += n; return chunks.back().data + old_top; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |