diff --git a/.hgignore b/.hgignore new file mode 100644 index 0000000..dfd2cff --- /dev/null +++ b/.hgignore @@ -0,0 +1 @@ +QtC-pvData.creator.user diff --git a/pvDataApp/Makefile b/pvDataApp/Makefile index 89e3d6d..8b5bc4b 100644 --- a/pvDataApp/Makefile +++ b/pvDataApp/Makefile @@ -41,6 +41,7 @@ LIBSRCS += timeFunction.cpp LIBSRCS += timer.cpp LIBSRCS += queueVoid.cpp LIBSRCS += messageQueue.cpp +LIBSRCS += StatusCreateFactory.cpp SRC_DIRS += $(PVDATA)/pv @@ -83,7 +84,6 @@ LIBSRCS += PVDataCreateFactory.cpp LIBSRCS += Convert.cpp LIBSRCS += StandardField.cpp LIBSRCS += StandardPVField.cpp -LIBSRCS += StatusCreateFactory.cpp SRC_DIRS += $(PVDATA)/property diff --git a/pvDataApp/factory/StatusCreateFactory.cpp b/pvDataApp/misc/StatusCreateFactory.cpp similarity index 91% rename from pvDataApp/factory/StatusCreateFactory.cpp rename to pvDataApp/misc/StatusCreateFactory.cpp index f18a0f9..5e308d3 100644 --- a/pvDataApp/factory/StatusCreateFactory.cpp +++ b/pvDataApp/misc/StatusCreateFactory.cpp @@ -8,7 +8,7 @@ #include #include #include -#include +#include "lock.h" #include "factory.h" #include "byteBuffer.h" #include "showConstructDestruct.h" @@ -53,6 +53,13 @@ class StatusImpl : public Status { public: + StatusImpl(StatusType type, String message) : + m_type(type), m_message(message) + { + Lock xx(globalMutex); + totalConstruct++; + } + StatusImpl(StatusType type, String message, String stackDump) : m_type(type), m_message(message), m_stackDump(stackDump) { @@ -60,7 +67,7 @@ class StatusImpl : public Status totalConstruct++; } - ~StatusImpl() { + virtual ~StatusImpl() { Lock xx(globalMutex); totalDestruct++; } @@ -112,6 +119,13 @@ class StatusImpl : public Status throw new std::runtime_error("use getStatusCreate()->deserialize()"); } + virtual String toString() + { + String str; + toString(&str, 0); + return str; + } + virtual void toString(StringBuilder buffer, int indentLevel) { *buffer += "StatusImpl [type="; @@ -150,13 +164,18 @@ class StatusCreateImpl : public StatusCreate { m_ok = createStatus(STATUSTYPE_OK, "OK", 0); } + ~StatusCreateImpl() + { + delete m_ok; + } + virtual Status* getStatusOK() { return m_ok; } virtual Status* createStatus(StatusType type, String message, BaseException* cause) { if (cause == 0) - return new StatusImpl(type, message, ""); + return new StatusImpl(type, message); else { std::string stackDump; diff --git a/pvDataApp/misc/bitSet.cpp b/pvDataApp/misc/bitSet.cpp index 0948c55..dec41dc 100644 --- a/pvDataApp/misc/bitSet.cpp +++ b/pvDataApp/misc/bitSet.cpp @@ -7,19 +7,63 @@ #include "string.h" #include "stdio.h" #include "bitSet.h" +#include "lock.h" namespace epics { namespace pvData { + //static DebugLevel debugLevel = lowDebug; + + static volatile int64 totalConstruct = 0; + static volatile int64 totalDestruct = 0; + static Mutex *globalMutex = 0; + + static int64 getTotalConstruct() + { + Lock xx(globalMutex); + return totalConstruct; + } + + static int64 getTotalDestruct() + { + Lock xx(globalMutex); + return totalDestruct; + } + + static ConstructDestructCallback *pConstructDestructCallback; + + static void init() + { + static Mutex mutex = Mutex(); + Lock xx(&mutex); + if(globalMutex==0) { + globalMutex = new Mutex(); + pConstructDestructCallback = new ConstructDestructCallback( + String("bitSet"), + getTotalConstruct,getTotalDestruct,0); + } + } + BitSet::BitSet() : words(0), wordsLength(0), wordsInUse(0) { initWords(BITS_PER_WORD); + + init(); + Lock xx(globalMutex); + totalConstruct++; } BitSet::BitSet(uint32 nbits) : words(0), wordsLength(0), wordsInUse(0) { initWords(nbits); + + init(); + Lock xx(globalMutex); + totalConstruct++; } BitSet::~BitSet() { delete words; + + Lock xx(globalMutex); + totalDestruct++; } void BitSet::initWords(uint32 nbits) { @@ -315,8 +359,6 @@ namespace epics { namespace pvData { return !(*this == set); } - void BitSet::toString(StringBuilder buffer) { toString(buffer, 0); } - void BitSet::toString(StringBuilder buffer, int indentLevel) const { *buffer += '{'; diff --git a/pvDataApp/misc/bitSet.h b/pvDataApp/misc/bitSet.h index f477e1c..982f5f3 100644 --- a/pvDataApp/misc/bitSet.h +++ b/pvDataApp/misc/bitSet.h @@ -8,6 +8,8 @@ #define BITSET_H #include #include +#include "factory.h" +#include "showConstructDestruct.h" //#include "byteBuffer.h" //#include "serialize.h" namespace epics { namespace pvData { @@ -213,9 +215,7 @@ namespace epics { namespace pvData { bool operator!=(const BitSet &set) const; - void toString(StringBuilder buffer); - - void toString(StringBuilder buffer, int indentLevel) const; + void toString(StringBuilder buffer, int indentLevel = 0) const; private: diff --git a/pvDataApp/misc/destroyable.h b/pvDataApp/misc/destroyable.h index 0f5b7ed..e709e67 100644 --- a/pvDataApp/misc/destroyable.h +++ b/pvDataApp/misc/destroyable.h @@ -20,11 +20,11 @@ namespace epics { namespace pvData { */ virtual void destroy() = 0; - private: + protected: /** - * Do not allow delete on this instance. + * Do not allow delete on this instance and derived classes, destroy() must be used instead. */ - //~Destroyable() {}; + virtual ~Destroyable() {}; }; }} diff --git a/pvDataApp/misc/status.h b/pvDataApp/misc/status.h index 5e9b38b..f496f9c 100644 --- a/pvDataApp/misc/status.h +++ b/pvDataApp/misc/status.h @@ -35,7 +35,8 @@ namespace epics { namespace pvData { */ class Status : public epics::pvData::Serializable { public: - + virtual ~Status() {}; + /** * Get status type. * @return status type, non-null. @@ -69,7 +70,7 @@ namespace epics { namespace pvData { */ virtual bool isSuccess() = 0; - + virtual String toString() = 0; virtual void toString(StringBuilder buffer, int indentLevel = 0) = 0; }; @@ -95,7 +96,7 @@ namespace epics { namespace pvData { * @param cause exception that caused an error. Optional. * @return status instance. */ - virtual Status* createStatus(StatusType type, String message, BaseException* cause) = 0; + virtual Status* createStatus(StatusType type, String message, BaseException* cause = 0) = 0; /** * Deserialize status. diff --git a/test/testLinkedListAux b/test/testLinkedListAux index 57d6cb6..2feefcc 100644 --- a/test/testLinkedListAux +++ b/test/testLinkedListAux @@ -1,20 +1,20 @@ Time test -diff 30.476650 milliSeconds -time per iteration 30.476650 microseconds -time per addTail/removeHead 0.015238 microseconds +diff 28.744510 milliSeconds +time per iteration 28.744510 microseconds +time per addTail/removeHead 0.014372 microseconds Time test locked -diff 182.684171 milliSeconds -time per iteration 182.684171 microseconds -time per addTail/removeHead 0.091342 microseconds +diff 187.872582 milliSeconds +time per iteration 187.872582 microseconds +time per addTail/removeHead 0.093936 microseconds Time std::list test -diff 649.338813 milliSeconds -time per iteration 649.338813 microseconds -time per addTail/removeHead 0.324669 microseconds +diff 682.009561 milliSeconds +time per iteration 682.009561 microseconds +time per addTail/removeHead 0.341005 microseconds Time std::list test locked -diff 803.852839 milliSeconds -time per iteration 803.852839 microseconds -time per addTail/removeHead 0.401926 microseconds +diff 817.248344 milliSeconds +time per iteration 817.248344 microseconds +time per addTail/removeHead 0.408624 microseconds diff --git a/test/testThreadAux b/test/testThreadAux index 9328418..ef103fe 100644 --- a/test/testThreadAux +++ b/test/testThreadAux @@ -1 +1 @@ -time per call 9.434397 microseconds +time per call 38.080599 microseconds diff --git a/test/testTimeStampAux b/test/testTimeStampAux index 72a5429..0ccd9f8 100644 --- a/test/testTimeStampAux +++ b/test/testTimeStampAux @@ -1,5 +1,5 @@ -current 1292845147 903990741 milliSec 1292845147903 -2010.12.20 06:39:07 903990741 nanoSeconds isDst false +current 1293027467 787274811 milliSec 1293027467787 +2010.12.22 09:17:47 787274811 nanoSeconds isDst false fromTime_t -current 1292845147 0 milliSec 1292845147000 -2010.12.20 06:39:07 0 nanoSeconds isDst false +current 1293027467 0 milliSec 1293027467000 +2010.12.22 09:17:47 0 nanoSeconds isDst false diff --git a/test/testTimerAux b/test/testTimerAux index 3238f0f..b6a7606 100644 --- a/test/testTimerAux +++ b/test/testTimerAux @@ -1,6 +1,6 @@ -one requested 0.400000 diff 0.400215 seconds -two requested 0.200000 diff 0.200168 seconds -one requested 0.200000 diff 0.200188 seconds -two requested 0.400000 diff 0.400392 seconds -one requested 0.000000 diff 0.000068 seconds -two requested 0.000000 diff 0.000091 seconds +one requested 0.400000 diff 0.400192 seconds +two requested 0.200000 diff 0.200170 seconds +one requested 0.200000 diff 0.200340 seconds +two requested 0.400000 diff 0.400313 seconds +one requested 0.000000 diff 0.000046 seconds +two requested 0.000000 diff 0.000068 seconds diff --git a/testApp/misc/testBitSet.cpp b/testApp/misc/testBitSet.cpp index 15eda03..82c3067 100644 --- a/testApp/misc/testBitSet.cpp +++ b/testApp/misc/testBitSet.cpp @@ -11,8 +11,8 @@ #include #include #include -#include "bitSet.h" - +#include +#include #include @@ -143,6 +143,7 @@ int main(int argc,char *argv[]) { testGetSetClearFlip(); testOperators(); + //getShowConstructDestruct()->constuctDestructTotals(stdout); return(0); }