From 657ab82cf00ef6d877e6a42728fad5f058c77c94 Mon Sep 17 00:00:00 2001 From: Gasper Jansa Date: Fri, 4 Feb 2011 13:50:04 +0100 Subject: [PATCH] small fixies --- pvAccessApp/remote/channelSearchManager.cpp | 4 +- pvAccessApp/utils/inetAddressUtil.h | 14 ++--- pvAccessApp/utils/transportRegistry.h | 2 +- testApp/utils/namedLockPatternTest.cpp | 68 ++++++++++++--------- 4 files changed, 49 insertions(+), 39 deletions(-) diff --git a/pvAccessApp/remote/channelSearchManager.cpp b/pvAccessApp/remote/channelSearchManager.cpp index 708c0a1..bcadc80 100644 --- a/pvAccessApp/remote/channelSearchManager.cpp +++ b/pvAccessApp/remote/channelSearchManager.cpp @@ -19,7 +19,7 @@ void BaseSearchInstance::unsetListOwnership() void BaseSearchInstance::addAndSetListOwnership(ArrayFIFO* newOwner, Mutex* ownerMutex, int32 index) { - if(ownerMutex == NULL) throw BaseException("Null owner mutex", __FILE__,__LINE__); + if(ownerMutex == NULL) THROW_BASE_EXCEPTION("Null owner mutex"); _ownerMutex = ownerMutex; Lock ownerGuard(_ownerMutex); @@ -33,7 +33,7 @@ void BaseSearchInstance::removeAndUnsetListOwnership() { if(_owner == NULL) return; - if(_ownerMutex == NULL) throw BaseException("Null owner mutex", __FILE__,__LINE__); + if(_ownerMutex == NULL) THROW_BASE_EXCEPTION("Null owner mutex"); Lock ownerGuard(_ownerMutex); Lock guard(&_mutex); if(_owner != NULL) diff --git a/pvAccessApp/utils/inetAddressUtil.h b/pvAccessApp/utils/inetAddressUtil.h index 8e1107b..06aa2d2 100644 --- a/pvAccessApp/utils/inetAddressUtil.h +++ b/pvAccessApp/utils/inetAddressUtil.h @@ -106,13 +106,13 @@ namespace epics { //TODO if unordered map is used instead of map we can use sockAddrAreIdentical routine from osiSock.h struct comp_osiSockAddr { - bool operator()(osiSockAddr const *a, osiSockAddr const *b) { - if(a->sa.sa_familysa.sa_family) return true; - if((a->sa.sa_family==b->sa.sa_family)&&(a->ia.sin_addr.s_addr - ia.sin_addr.s_addr)) return true; - if((a->sa.sa_family==b->sa.sa_family)&&(a->ia.sin_addr.s_addr - ==b->ia.sin_addr.s_addr)&&(a->ia.sin_port - ia.sin_port)) return true; + bool operator()(osiSockAddr const a, osiSockAddr const b) { + if(a.sa.sa_family prioritiesMap_t; -typedef std::map transportsMap_t; +typedef std::map transportsMap_t; typedef std::vector allTransports_t; class TransportRegistry { diff --git a/testApp/utils/namedLockPatternTest.cpp b/testApp/utils/namedLockPatternTest.cpp index 0fa36b4..3b8ee08 100644 --- a/testApp/utils/namedLockPatternTest.cpp +++ b/testApp/utils/namedLockPatternTest.cpp @@ -4,14 +4,18 @@ */ #include "namedLockPattern.h" +#include "inetAddressUtil.h" +#include "status.h" #include "CDRMonitor.h" + #include #include -#include - #include +#include +#include + using namespace epics::pvData; using namespace epics::pvAccess; using namespace std; @@ -66,17 +70,6 @@ void testCharPtrLockPattern() namedLockPattern.releaseSynchronizationObject(name2.c_str()); } -struct comp_osiSockAddrPtr -{ - bool operator()(osiSockAddr const *a, osiSockAddr const *b) - { - if (a->sa.sa_family < b->sa.sa_family) return true; - if ((a->sa.sa_family == b->sa.sa_family) && (a->ia.sin_addr.s_addr < b->ia.sin_addr.s_addr )) return true; - if ((a->sa.sa_family == b->sa.sa_family) && (a->ia.sin_addr.s_addr == b->ia.sin_addr.s_addr ) && ( a->ia.sin_port < b->ia.sin_port )) return true; - return false; - } -}; - void testOsiSockAddrLockPattern() { int64 timeout = 10000; @@ -88,27 +81,43 @@ void testOsiSockAddrLockPattern() assert(namedLockPattern.acquireSynchronizationObject(&name1,timeout)); assert(namedLockPattern.acquireSynchronizationObject(&name1,timeout)); - namedLockPattern.releaseSynchronizationObject(&name1); - namedLockPattern.releaseSynchronizationObject(&name1); + osiSockAddr name2; name2.ia.sin_addr.s_addr = 1; name2.ia.sin_port = 1; name2.ia.sin_family = AF_INET; + assert(namedLockPattern.acquireSynchronizationObject(&name2,timeout)); + assert(namedLockPattern.acquireSynchronizationObject(&name2,timeout)); + + + namedLockPattern.releaseSynchronizationObject(&name1); + namedLockPattern.releaseSynchronizationObject(&name1); + namedLockPattern.releaseSynchronizationObject(&name2); + namedLockPattern.releaseSynchronizationObject(&name2); + + osiSockAddr name3; + name3.ia.sin_addr.s_addr = 1; + name3.ia.sin_port = 1; + name3.ia.sin_family = AF_INET; NamedLock namedGuard(&namedLockPattern); - assert(namedGuard.acquireSynchronizationObject(&name1,timeout)); + assert(namedGuard.acquireSynchronizationObject(&name3,timeout)); } -struct comp_osiSockAddr +void testOsiSockAddrWithPtrKeyLockPattern() { - bool operator()(osiSockAddr const a, osiSockAddr const b) - { - if (a.sa.sa_family < b.sa.sa_family) return true; - if ((a.sa.sa_family == b.sa.sa_family) && (a.ia.sin_addr.s_addr < b.ia.sin_addr.s_addr )) return true; - if ((a.sa.sa_family == b.sa.sa_family) && (a.ia.sin_addr.s_addr == b.ia.sin_addr.s_addr ) && ( a.ia.sin_port < b.ia.sin_port )) return true; - return false; - } -}; + int64 timeout = 10000; + NamedLockPattern namedLockPattern; + osiSockAddr* name1 = new osiSockAddr; + name1->ia.sin_addr.s_addr = 1; + name1->ia.sin_port = 1; + name1->ia.sin_family = AF_INET; + assert(namedLockPattern.acquireSynchronizationObject(name1,timeout)); + assert(namedLockPattern.acquireSynchronizationObject(name1,timeout)); + namedLockPattern.releaseSynchronizationObject(name1); + namedLockPattern.releaseSynchronizationObject(name1); + delete name1; +} void* testWorker1(void* p) { @@ -167,7 +176,7 @@ void* testWorker2(void* p) addr.ia.sin_port = 1; addr.ia.sin_family = AF_INET; NamedLock namedGuard(namedLockPattern); - //TODO swap next two lines this if timed lock used + //TODO swap next two lines if timed lock used //assert(!namedGuard.acquireSynchronizationObject(addr,timeout)); assert(namedGuard.acquireSynchronizationObject(addr,timeout)); } @@ -181,7 +190,7 @@ int main(int argc, char *argv[]) testIntPtrLockPattern(); testCharPtrLockPattern(); testOsiSockAddrLockPattern(); - + testOsiSockAddrWithPtrKeyLockPattern(); pthread_t _worker1Id; pthread_t _worker2Id; @@ -213,8 +222,9 @@ int main(int argc, char *argv[]) assert(true); } - epicsExitCallAtExits(); - CDRMonitor::get().show(stdout); + epicsExitCallAtExits(); + CDRMonitor::get().show(stdout); + return 0; }