Memory.cpp

Go to the documentation of this file.
00001 /*
00002 // $Id: //open/dev/fennel/common/Memory.cpp#12 $
00003 // Fennel is a library of data storage and processing components.
00004 // Copyright (C) 2005-2009 The Eigenbase Project
00005 // Copyright (C) 2005-2009 SQLstream, Inc.
00006 // Copyright (C) 2005-2009 LucidEra, Inc.
00007 // Portions Copyright (C) 1999-2009 John V. Sichi
00008 //
00009 // This program is free software; you can redistribute it and/or modify it
00010 // under the terms of the GNU General Public License as published by the Free
00011 // Software Foundation; either version 2 of the License, or (at your option)
00012 // any later version approved by The Eigenbase Project.
00013 //
00014 // This program is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU General Public License
00020 // along with this program; if not, write to the Free Software
00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 */
00023 
00024 #include "fennel/common/CommonPreamble.h"
00025 
00026 #include <ctype.h>
00027 #include <algorithm>
00028 
00029 #include <boost/io/ios_state.hpp>
00030 #include <boost/format.hpp>
00031 
00032 #ifdef __MSVC__
00033 # include <windows.h>
00034 # include "fennel/common/AtomicCounter.h"
00035 # include "fennel/common/IntrusiveDList.h"
00036 # include "fennel/common/CompoundId.h"
00037 # include "fennel/common/AbortExcn.h"
00038 # include "fennel/common/VoidPtrHash.h"
00039 #else
00040 # include <pthread.h>
00041 #endif
00042 
00043 // NOTE jvs 26-June-2005:  I added this to squelch link errors with
00044 // the Boost filesystem library.  Yet another case where I have no
00045 // idea what's really going on.
00046 #ifdef __MSVC__
00047 void *operator new [](unsigned sz) throw (std::bad_alloc)
00048 {
00049     void *p = malloc(sz ? sz : 1);
00050     if (!p) {
00051         throw std::bad_alloc();
00052     }
00053     return p;
00054 }
00055 
00056 void operator delete [](void *p) throw ()
00057 {
00058     free(p);
00059 }
00060 #endif
00061 
00062 FENNEL_BEGIN_CPPFILE("$Id: //open/dev/fennel/common/Memory.cpp#12 $");
00063 
00064 std::logic_error constructAssertion(
00065     char const *pFilename,int lineNum,char const *condExpr)
00066 {
00067     boost::format fmt("Assertion `%1%' failed at line %2% in file %3%");
00068     return std::logic_error(
00069         (fmt % condExpr % lineNum % pFilename).str());
00070 }
00071 
00072 int getCurrentThreadId()
00073 {
00074 #ifdef __MSVC__
00075     return static_cast<int>(GetCurrentThreadId());
00076 #else
00077     return static_cast<int>(pthread_self());
00078 #endif
00079 }
00080 
00081 void hexDump(std::ostream &o,void const *v,uint cb,uint cbDone)
00082 {
00083     boost::io::ios_all_saver streamStateSaver(o);
00084 
00085     PConstBuffer b = (PConstBuffer) v;
00086     uint cbLine = 16,cbThis;
00087     o.fill('0');
00088     for (; cb; cb -= cbThis, cbDone += cbThis) {
00089         cbThis = std::min(cbLine,cb);
00090         o << std::hex;
00091         o.width(4);
00092         o << cbDone << ": ";
00093         uint i;
00094         for (i = 0; i < cbThis; i++, b++) {
00095             o.width(2);
00096             o << (uint) *b << " ";
00097         }
00098         for (i = cbThis; i < cbLine; i++) {
00099             o << "   ";
00100         }
00101         o << "| ";
00102         for (i = 0, b -= cbThis; i < cbThis; i++, b++) {
00103             if (isprint(*b)) {
00104                 o << *b;
00105             } else {
00106                 o << " ";
00107             }
00108         }
00109         o << std::endl;
00110     }
00111 }
00112 
00113 // TODO jvs 27-Feb-2009:  move this somewhere else
00114 
00115 // force references to some classes which aren't referenced elsewhere
00116 #ifdef __MSVC__
00117 class UnreferencedCommonStructs
00118 {
00119     AtomicCounter atomicCounter;
00120     IntrusiveDListNode dlistNode;
00121     CompoundId compoundId;
00122     AbortExcn abortExcn;
00123     VoidPtrHash voidPtrHash;
00124 };
00125 #endif
00126 
00127 FENNEL_END_CPPFILE("$Id: //open/dev/fennel/common/Memory.cpp#12 $");
00128 
00129 // End Memory.cpp

Generated on Mon Jun 22 04:00:18 2009 for Fennel by  doxygen 1.5.1