diff --git a/documentation/pvDataCpp.html b/documentation/pvDataCpp.html index 5e63a47..d4c80d5 100644 --- a/documentation/pvDataCpp.html +++ b/documentation/pvDataCpp.html @@ -26,33 +26,33 @@
The following code uses introspection to get the desired information.
-void getValueAndTimeStamp(PVStructurePtr pvStructure,Stringbuffer buf) {
+void getValueAndTimeStamp(PVStructurePtr pvStructure,StringBuilder buf) {
PVField *valuePV = pvStructure->getSubField(String("value"));
if(valuePV==0) {
buf += "value field not found";
diff --git a/pvDataApp/factory/Convert.cpp b/pvDataApp/factory/Convert.cpp
index e79b672..1397e63 100644
--- a/pvDataApp/factory/Convert.cpp
+++ b/pvDataApp/factory/Convert.cpp
@@ -3667,7 +3667,7 @@ public:
Convert * getConvert() {
static Mutex mutex;
- Lock xx(&mutex);
+ Lock xx(mutex);
if(convert==0){
convert = new ConvertExt();
diff --git a/pvDataApp/factory/FieldCreateFactory.cpp b/pvDataApp/factory/FieldCreateFactory.cpp
index 5200be0..9fc22a3 100644
--- a/pvDataApp/factory/FieldCreateFactory.cpp
+++ b/pvDataApp/factory/FieldCreateFactory.cpp
@@ -55,7 +55,7 @@ Field::~Field() {
}
int Field::getReferenceCount() const {
- Lock xx(&refCountMutex);
+ Lock xx(refCountMutex);
return pImpl->referenceCount;
}
@@ -70,7 +70,7 @@ void Field::renameField(String newName)
void Field::incReferenceCount() const {
PVDATA_REFCOUNT_MONITOR_INCREF(field);
- Lock xx(&refCountMutex);
+ Lock xx(refCountMutex);
pImpl->referenceCount++;
if(pImpl->type!=structure) return;
StructureConstPtr structure = static_cast(this);
@@ -83,7 +83,7 @@ void Field::incReferenceCount() const {
void Field::decReferenceCount() const {
PVDATA_REFCOUNT_MONITOR_DECREF(field);
- Lock xx(&refCountMutex);
+ Lock xx(refCountMutex);
if(pImpl->referenceCount<=0) {
String message("logicError field ");
message += pImpl->fieldName;
@@ -406,7 +406,7 @@ FieldCreate::FieldCreate()
FieldCreate * getFieldCreate() {
static Mutex mutex;
- Lock xx(&mutex);
+ Lock xx(mutex);
if(fieldCreate==0) fieldCreate = new FieldCreate();
return fieldCreate;
diff --git a/pvDataApp/factory/PVDataCreateFactory.cpp b/pvDataApp/factory/PVDataCreateFactory.cpp
index 6f92353..5e9ce2c 100644
--- a/pvDataApp/factory/PVDataCreateFactory.cpp
+++ b/pvDataApp/factory/PVDataCreateFactory.cpp
@@ -544,7 +544,7 @@ PVStructure *PVDataCreate::createPVStructure(PVStructure *parent,
PVDataCreate * getPVDataCreate() {
static Mutex mutex;
- Lock xx(&mutex);
+ Lock xx(mutex);
if(pvDataCreate==0){
pvDataCreate = new PVDataCreate();
diff --git a/pvDataApp/misc/CDRMonitor.cpp b/pvDataApp/misc/CDRMonitor.cpp
index f6a30cf..5f1702f 100644
--- a/pvDataApp/misc/CDRMonitor.cpp
+++ b/pvDataApp/misc/CDRMonitor.cpp
@@ -79,7 +79,7 @@ CDRMonitor::show(std::ostream& out) const
void
CDRNode::show(FILE *fd)
{
- Lock x(&guard);
+ Lock x(guard);
if(!current.cons && !current.dtys && !current.refs)
return;
fprintf(fd,"%s: totalConstruct %lu totalDestruct %lu",
@@ -98,7 +98,7 @@ CDRNode::show(FILE *fd)
void
CDRNode::show(std::ostream& out) const
{
- Lock x(&guard);
+ Lock x(guard);
if(!current.cons && !current.dtys && !current.refs)
return;
out<getObject();
+ delete &node->getObject();
}
}
void ExecutorPvt::run()
{
- unique_lock xx(mutex);
+ Lock xx(mutex);
while(true) {
ExecutorListNode * executorListNode = 0;
while(runList.isEmpty()) {
@@ -106,13 +106,13 @@ void ExecutorPvt::run()
executorListNode = runList.removeHead();
if(!executorListNode) continue;
- Command *cmd=executorListNode->getObject()->command;
+ Command *cmd=executorListNode->getObject().command;
if(cmd==shutdown) break;
xx.unlock();
try {
- executorListNode->getObject()->command->command();
+ executorListNode->getObject().command->command();
}catch(std::exception& e){
//TODO: feed into logging mechanism
fprintf(stderr, "Executor: Unhandled exception: %s",e.what());
@@ -128,18 +128,18 @@ void ExecutorPvt::run()
ExecutorNode * ExecutorPvt::createNode(Command *command)
{
- Lock xx(&mutex);
+ Lock xx(mutex);
ExecutorNode *executorNode = new ExecutorNode(command);
- executorList.addTail(&executorNode->node);
+ executorList.addTail(executorNode->node);
return executorNode;
}
void ExecutorPvt::execute(ExecutorNode *node)
{
- Lock xx(&mutex);
+ Lock xx(mutex);
if(node->runNode.isOnList()) return;
bool isEmpty = runList.isEmpty();
- runList.addTail(&node->runNode);
+ runList.addTail(node->runNode);
if(isEmpty) moreWork.signal();
}
diff --git a/pvDataApp/misc/linkedList.h b/pvDataApp/misc/linkedList.h
index abf41c5..1eda3ac 100644
--- a/pvDataApp/misc/linkedList.h
+++ b/pvDataApp/misc/linkedList.h
@@ -15,9 +15,9 @@ class LinkedList;
template
class LinkedListNode : private LinkedListVoidNode {
public:
- LinkedListNode(T *object) : LinkedListVoidNode(object){}
+ LinkedListNode(T &object) : LinkedListVoidNode(&object){}
~LinkedListNode() {}
- T *getObject() { return static_cast(LinkedListVoidNode::getObject());}
+ T &getObject() { return *static_cast(LinkedListVoidNode::getObject());}
bool isOnList() {return LinkedListVoidNode::isOnList();}
friend class LinkedList;
};
@@ -28,27 +28,27 @@ public:
LinkedList() : LinkedListVoid() {}
~LinkedList() {}
int getLength() {return LinkedListVoid::getLength();}
- void addTail(LinkedListNode *listNode)
+ void addTail(LinkedListNode &listNode)
{
- LinkedListVoid::addTail(static_cast(listNode));
+ LinkedListVoid::addTail(static_cast(listNode));
}
- void addHead(LinkedListNode *listNode)
+ void addHead(LinkedListNode &listNode)
{
- LinkedListVoid::addHead(static_cast(listNode));
+ LinkedListVoid::addHead(static_cast(listNode));
}
- void insertAfter(LinkedListNode *listNode,
- LinkedListNode *addNode)
+ void insertAfter(LinkedListNode &listNode,
+ LinkedListNode &addNode)
{
LinkedListVoid::insertAfter(
- static_cast(listNode),
- static_cast(addNode));
+ static_cast(listNode),
+ static_cast(addNode));
}
- void insertBefore(LinkedListNode *listNode,
- LinkedListNode *addNode)
+ void insertBefore(LinkedListNode &listNode,
+ LinkedListNode &addNode)
{
LinkedListVoid::insertBefore(
- static_cast(listNode),
- static_cast(addNode));
+ static_cast(listNode),
+ static_cast(addNode));
}
LinkedListNode *removeTail(){
return static_cast *>(LinkedListVoid::removeTail());
@@ -56,11 +56,8 @@ public:
LinkedListNode *removeHead(){
return static_cast *>(LinkedListVoid::removeHead());
}
- void remove(LinkedListNode *listNode){
- LinkedListVoid::remove(static_cast(listNode));
- }
- void remove(T *object){
- LinkedListVoid::remove(object);
+ void remove(LinkedListNode &listNode){
+ LinkedListVoid::remove(static_cast(listNode));
}
LinkedListNode *getHead(){
return static_cast *>(LinkedListVoid::getHead());
@@ -68,16 +65,15 @@ public:
LinkedListNode *getTail(){
return static_cast *>(LinkedListVoid::getTail());
}
- LinkedListNode *getNext(LinkedListNode *listNode){
+ LinkedListNode *getNext(LinkedListNode &listNode){
return static_cast *>(LinkedListVoid::getNext(
- static_cast(listNode)));
+ static_cast(listNode)));
}
- LinkedListNode *getPrev(LinkedListNode *listNode){
+ LinkedListNode *getPrev(LinkedListNode &listNode){
return static_cast *>(LinkedListVoid::getPrev(
- static_cast(listNode)));
+ static_cast(listNode)));
}
bool isEmpty() { return LinkedListVoid::isEmpty();}
- bool contains(T *object) { return LinkedListVoid::contains(object);}
};
diff --git a/pvDataApp/misc/linkedListVoid.cpp b/pvDataApp/misc/linkedListVoid.cpp
index a94c6b8..14f2b5e 100644
--- a/pvDataApp/misc/linkedListVoid.cpp
+++ b/pvDataApp/misc/linkedListVoid.cpp
@@ -68,44 +68,44 @@ int LinkedListVoid::getLength()
return length;
}
-void LinkedListVoid::addTail(LinkedListVoidNode *node)
+void LinkedListVoid::addTail(LinkedListVoidNode &node)
{
- if(node->before!=0 || node->after!=0) {
+ if(node.before!=0 || node.after!=0) {
throw std::logic_error(alreadyOnList);
}
- node->linkedListVoid = this;
- node->before = head->before;
- node->after = head;
- head->before->after = node;
- head->before = node;
+ node.linkedListVoid = this;
+ node.before = head->before;
+ node.after = head;
+ head->before->after = &node;
+ head->before = &node;
++length;
}
-void LinkedListVoid::addHead(LinkedListVoidNode *node)
+void LinkedListVoid::addHead(LinkedListVoidNode &node)
{
- if(node->before!=0 || node->after!=0) {
+ if(node.before!=0 || node.after!=0) {
throw std::logic_error(alreadyOnList);
}
- node->linkedListVoid = this;
- node->after = head->after;
- node->before = head;
- head->after->before = node;
- head->after = node;
+ node.linkedListVoid = this;
+ node.after = head->after;
+ node.before = head;
+ head->after->before = &node;
+ head->after = &node;
++length;
}
-void LinkedListVoid::insertAfter(LinkedListVoidNode *node,
- LinkedListVoidNode *addNode)
+void LinkedListVoid::insertAfter(LinkedListVoidNode &node,
+ LinkedListVoidNode &addNode)
{
- LinkedListVoidNode *existingNode = node;
- LinkedListVoidNode *newNode = addNode;
+ LinkedListVoidNode *existingNode = &node;
+ LinkedListVoidNode *newNode = &addNode;
if(existingNode->after==0 || existingNode->before==0) {
throw std::logic_error(String("listNode not on list"));
}
if(newNode->before!=0 || newNode->after!=0) {
throw std::logic_error(alreadyOnList);
}
- if(node->linkedListVoid!=this) {
+ if(node.linkedListVoid!=this) {
throw std::logic_error(String("node not on this list"));
}
newNode->linkedListVoid = this;
@@ -116,18 +116,18 @@ void LinkedListVoid::insertAfter(LinkedListVoidNode *node,
++length;
}
-void LinkedListVoid::insertBefore(LinkedListVoidNode *node,
- LinkedListVoidNode *addNode)
+void LinkedListVoid::insertBefore(LinkedListVoidNode &node,
+ LinkedListVoidNode &addNode)
{
- LinkedListVoidNode *existingNode = node;
- LinkedListVoidNode *newNode = addNode;
+ LinkedListVoidNode *existingNode = &node;
+ LinkedListVoidNode *newNode = &addNode;
if(existingNode->after==0 || existingNode->before==0) {
throw std::logic_error(String("listNode not on list"));
}
if(newNode->before!=0 || newNode->after!=0) {
throw std::logic_error(alreadyOnList);
}
- if(node->linkedListVoid!=this) {
+ if(node.linkedListVoid!=this) {
throw std::logic_error(String("node not on this list"));
}
newNode->linkedListVoid = this;
@@ -142,7 +142,7 @@ LinkedListVoidNode *LinkedListVoid::removeTail()
{
if(head->after==head) return 0;
LinkedListVoidNode *node = head->before;
- remove(head->before);
+ remove(*head->before);
return node;
}
@@ -150,40 +150,27 @@ LinkedListVoidNode *LinkedListVoid::removeHead()
{
if(head->after==head) return 0;
LinkedListVoidNode *node = head->after;
- remove(head->after);
+ remove(*head->after);
return node;
}
-void LinkedListVoid::remove(LinkedListVoidNode *node)
+void LinkedListVoid::remove(LinkedListVoidNode &node)
{
- if(node->before==0 || node->after==0) {
+ if(node.before==0 || node.after==0) {
throw std::logic_error(String("node not on list"));
}
- if(node->linkedListVoid!=this) {
+ if(node.linkedListVoid!=this) {
throw std::logic_error(String("node not on this list"));
}
- node->linkedListVoid = 0;
- LinkedListVoidNode *prev = node->before;
- LinkedListVoidNode *next = node->after;
- node->after = node->before = 0;
+ node.linkedListVoid = 0;
+ LinkedListVoidNode *prev = node.before;
+ LinkedListVoidNode *next = node.after;
+ node.after = node.before = 0;
prev->after = next;
next->before = prev;
length--;
}
-void LinkedListVoid::remove(void * object)
-{
- LinkedListVoidNode *node = getHead();
- while(node!=0) {
- if(node->getObject()==object) {
- remove(node);
- return;
- }
- node = getNext(node);
- }
- throw std::logic_error(String("object not on this list"));
-}
-
LinkedListVoidNode *LinkedListVoid::getHead()
{
if(head->after==head) return 0;
@@ -196,22 +183,22 @@ LinkedListVoidNode *LinkedListVoid::getTail()
return head->before;
}
-LinkedListVoidNode *LinkedListVoid::getNext(LinkedListVoidNode *listNode)
+LinkedListVoidNode *LinkedListVoid::getNext(LinkedListVoidNode &listNode)
{
- if(listNode->linkedListVoid!=this) {
+ if(listNode.linkedListVoid!=this) {
throw std::logic_error(String("node not on this list"));
}
- if(listNode->after==head) return 0;
- return listNode->after;
+ if(listNode.after==head) return 0;
+ return listNode.after;
}
-LinkedListVoidNode *LinkedListVoid::getPrev(LinkedListVoidNode *listNode)
+LinkedListVoidNode *LinkedListVoid::getPrev(LinkedListVoidNode &listNode)
{
- if(listNode->linkedListVoid!=this) {
+ if(listNode.linkedListVoid!=this) {
throw std::logic_error(String("node not on this list"));
}
- if(listNode->before==head) return 0;
- return listNode->before;
+ if(listNode.before==head) return 0;
+ return listNode.before;
}
bool LinkedListVoid::isEmpty()
@@ -220,16 +207,4 @@ bool LinkedListVoid::isEmpty()
return false;
}
-bool LinkedListVoid::contains(void * object)
-{
- LinkedListVoidNode *node = getHead();
- while(node!=0) {
- if(node->getObject()==object) {
- return true;
- }
- node = getNext(node);
- }
- return false;
-}
-
}}
diff --git a/pvDataApp/misc/linkedListVoid.h b/pvDataApp/misc/linkedListVoid.h
index fa7d34c..781d8de 100644
--- a/pvDataApp/misc/linkedListVoid.h
+++ b/pvDataApp/misc/linkedListVoid.h
@@ -36,22 +36,20 @@ class LinkedListVoid {
public:
~LinkedListVoid();
int getLength();
- void addTail(LinkedListVoidNode *listNode);
- void addHead(LinkedListVoidNode *listNode);
- void insertAfter(LinkedListVoidNode *listNode,
- LinkedListVoidNode *addNode);
- void insertBefore(LinkedListVoidNode *listNode,
- LinkedListVoidNode *addNode);
+ void addTail(LinkedListVoidNode &listNode);
+ void addHead(LinkedListVoidNode &listNode);
+ void insertAfter(LinkedListVoidNode &listNode,
+ LinkedListVoidNode &addNode);
+ void insertBefore(LinkedListVoidNode &listNode,
+ LinkedListVoidNode &addNode);
LinkedListVoidNode *removeTail();
LinkedListVoidNode *removeHead();
- void remove(LinkedListVoidNode *listNode);
- void remove(void * object);
+ void remove(LinkedListVoidNode &listNode);
LinkedListVoidNode *getHead();
LinkedListVoidNode *getTail();
- LinkedListVoidNode *getNext(LinkedListVoidNode *listNode);
- LinkedListVoidNode *getPrev(LinkedListVoidNode *listNode);
+ LinkedListVoidNode *getNext(LinkedListVoidNode &listNode);
+ LinkedListVoidNode *getPrev(LinkedListVoidNode &listNode);
bool isEmpty();
- bool contains(void * object);
protected:
LinkedListVoid();
private:
diff --git a/pvDataApp/misc/lock.h b/pvDataApp/misc/lock.h
index ded52f9..149bcd7 100644
--- a/pvDataApp/misc/lock.h
+++ b/pvDataApp/misc/lock.h
@@ -15,86 +15,8 @@
namespace epics { namespace pvData {
-typedef epicsMutexId native_handle_type;
-
-/** @brief Acquires and holds a mutex until destructed
- *
- * Partial implementation of boost::lock_guard<>
- */
-template
-class lock_guard : private NoDefaultMethods {
-public:
- typedef Lockable mutex_type;
- explicit lock_guard(Lockable &m)
- : mutex(m)
- {mutex.lock();}
- explicit lock_guard(Lockable *pm)
- : mutex(*pm)
- {mutex.lock();}
- ~lock_guard(){mutex.unlock();}
-private:
- Lockable& mutex;
-};
-
-/* Lock action tags.
- * Used to select construction behaviour of locks
- */
-struct defer_lock_t{};
-//struct adopt_lock_t{};
-
-const defer_lock_t defer_lock={};
-//const adopt_lock_t adopt_lock={};
-
-/** @brief Acquires a mutex. Always releases destructed
- *
- * May release and re-acquire.
- * Partial implementation of boost::unique_lock<>
- */
-template
-class unique_lock : private NoDefaultMethods {
-public:
- typedef Lockable mutex_type;
- explicit unique_lock(Lockable &m)
- : mutexPtr(&m), locked(true)
- {mutexPtr->lock();}
- unique_lock(Lockable &m, defer_lock_t)
- : mutexPtr(m), locked(false)
- {}
- ~unique_lock(){unlock();}
- void swap(unique_lock& O)
- {
- Lockable *t=O.mutexPtr;
- bool tl=O.locked;
- O.mutexPtr=mutexPtr;
- O.locked=locked;
- mutexPtr=t;
- locked=tl;
- }
- void lock()
- {
- if(!locked)
- mutexPtr->lock();
- locked=true;
- }
- void unlock()
- {
- if(locked)
- mutexPtr->unlock();
- locked=false;
- }
- bool owns_lock() const{return locked;}
-
- Lockable* mutex() const{return mutex;}
- Lockable* release(){locked=false; return mutex;}
-
-private:
- Lockable *mutexPtr;
- bool locked;
-};
-
class Mutex {
public:
- typedef unique_lock scoped_lock;
Mutex() : id(epicsMutexCreate())
{if(!id) throw std::bad_alloc();}
~Mutex() { epicsMutexDestroy(id) ;}
@@ -103,13 +25,32 @@ public:
throw std::logic_error("Failed to acquire Mutex");
}
void unlock(){epicsMutexUnlock(id);}
-
- native_handle_type native_handle(){return id;}
private:
epicsMutexId id;
};
-typedef lock_guard Lock;
+class Lock : private NoDefaultMethods {
+public:
+ explicit Lock(Mutex &m)
+ : mutexPtr(m), locked(true)
+ { mutexPtr.lock();}
+ ~Lock(){unlock();}
+ void lock()
+ {
+ if(!locked) mutexPtr.lock();
+ locked = true;
+ }
+ void unlock()
+ {
+ if(locked)
+ mutexPtr.unlock();
+ locked=false;
+ }
+ bool ownsLock() const{return locked;}
+private:
+ Mutex &mutexPtr;
+ bool locked;
+};
}}
diff --git a/pvDataApp/misc/thread.cpp b/pvDataApp/misc/thread.cpp
index 3959f9b..be08e06 100644
--- a/pvDataApp/misc/thread.cpp
+++ b/pvDataApp/misc/thread.cpp
@@ -101,7 +101,7 @@ Thread::ThreadPvt::ThreadPvt(Thread *thread,String name,
: name(name),priority(priority),
runnable(runnable),
isReady(false),
- threadNode(thread),
+ threadNode(*thread),
waitDone(),
id(epicsThreadCreate(
name.c_str(),
@@ -115,8 +115,8 @@ Thread::ThreadPvt::ThreadPvt(Thread *thread,String name,
epicsThreadOnce(&initOnce, &init, 0);
assert(threadList);
PVDATA_REFCOUNT_MONITOR_CONSTRUCT(thread);
- Lock x(&listGuard);
- threadList->addTail(&threadNode);
+ Lock x(listGuard);
+ threadList->addTail(threadNode);
}
Thread::ThreadPvt::~ThreadPvt()
@@ -135,8 +135,8 @@ Thread::ThreadPvt::~ThreadPvt()
message += " is not on threadlist";
throw std::logic_error(message);
}
- Lock x(&listGuard);
- threadList->remove(&threadNode);
+ Lock x(listGuard);
+ threadList->remove(threadNode);
PVDATA_REFCOUNT_MONITOR_DESTRUCT(thread);
}
@@ -165,15 +165,15 @@ ThreadPriority Thread::getPriority()
void Thread::showThreads(StringBuilder buf)
{
- Lock x(&listGuard);
+ Lock x(listGuard);
ThreadListNode *node = threadList->getHead();
while(node!=0) {
- Thread *thread = node->getObject();
- *buf += thread->getName();
+ Thread &thread = node->getObject();
+ *buf += thread.getName();
*buf += " ";
- *buf += threadPriorityNames[thread->getPriority()];
+ *buf += threadPriorityNames[thread.getPriority()];
*buf += "\n";
- node = threadList->getNext(node);
+ node = threadList->getNext(*node);
}
}
diff --git a/pvDataApp/misc/timer.cpp b/pvDataApp/misc/timer.cpp
index 083cbf8..1ee0eab 100644
--- a/pvDataApp/misc/timer.cpp
+++ b/pvDataApp/misc/timer.cpp
@@ -37,12 +37,14 @@ public:
TimeStamp timeToRun;
Timer::Pvt *timerPvt;
double period;
- Pvt(TimerNode *timerNode,TimerCallback *callback);
+ Pvt(TimerNode &timerNode,TimerCallback &callback);
+ ~Pvt(){}
+private:
};
-TimerNode::Pvt::Pvt(TimerNode *timerNode,TimerCallback *callback)
-: timerNode(timerNode),callback(callback),
- timerListNode(this),timeToRun(),
+TimerNode::Pvt::Pvt(TimerNode &timerNode,TimerCallback &callback)
+: timerNode(&timerNode),callback(&callback),
+ timerListNode(*this),timeToRun(),
timerPvt(0), period(0.0)
{}
@@ -57,8 +59,7 @@ public: // only used by this source module
Event waitForDone;
volatile bool alive;
Thread thread;
-
- void addElement(TimerNode::Pvt *node);
+ void addElement(TimerNode::Pvt &node);
};
Timer::Pvt::Pvt(String threadName,ThreadPriority priority)
@@ -70,30 +71,30 @@ Timer::Pvt::Pvt(String threadName,ThreadPriority priority)
thread(threadName,priority,this)
{}
-void Timer::Pvt::addElement(TimerNode::Pvt *node)
+void Timer::Pvt::addElement(TimerNode::Pvt &node)
{
TimerListNode *nextNode = timerList.getHead();
if(nextNode==0) {
- timerList.addTail(&node->timerListNode);
+ timerList.addTail(node.timerListNode);
return;
}
while(true) {
- TimerNode::Pvt *timerListNode = nextNode->getObject();
- if((node->timeToRun)<(timerListNode->timeToRun)) {
- timerList.insertBefore(&timerListNode->timerListNode,&node->timerListNode);
+ TimerNode::Pvt &timerListNode = nextNode->getObject();
+ if((node.timeToRun)<(timerListNode.timeToRun)) {
+ timerList.insertBefore(timerListNode.timerListNode,node.timerListNode);
return;
}
- nextNode = timerList.getNext(&timerListNode->timerListNode);
+ nextNode = timerList.getNext(timerListNode.timerListNode);
if(nextNode==0) {
- timerList.addTail(&node->timerListNode);
+ timerList.addTail(node.timerListNode);
return;
}
}
}
-TimerNode::TimerNode(TimerCallback *callback)
-: pImpl(new Pvt(this,callback))
+TimerNode::TimerNode(TimerCallback &callback)
+: pImpl(new Pvt(*this,callback))
{
PVDATA_REFCOUNT_MONITOR_CONSTRUCT(timerNode);
}
@@ -109,9 +110,9 @@ void TimerNode::cancel()
{
Timer::Pvt *timerPvt = pImpl->timerPvt;
if(timerPvt==0) return;
- Lock xx(&timerPvt->mutex);
+ Lock xx(timerPvt->mutex);
if(pImpl->timerPvt==0) return;
- pImpl->timerPvt->timerList.remove(pImpl.get());
+ pImpl->timerPvt->timerList.remove(pImpl->timerListNode);
pImpl->timerPvt = 0;
}
@@ -119,7 +120,7 @@ bool TimerNode::isScheduled()
{
Timer::Pvt *pvt = pImpl->timerPvt;
if(pvt==0) return false;
- Lock xx(&pvt->mutex);
+ Lock xx(pvt->mutex);
return pImpl->timerListNode.isOnList();
}
@@ -133,10 +134,10 @@ void Timer::Pvt::run()
double period = 0.0;
TimerNode::Pvt *nodeToCall = 0;
{
- Lock xx(&mutex);
+ Lock xx(mutex);
TimerListNode *timerListNode = timerList.getHead();
if(timerListNode!=0) {
- TimerNode::Pvt *timerNodePvt = timerListNode->getObject();
+ TimerNode::Pvt *timerNodePvt = &timerListNode->getObject();
timeToRun = &timerNodePvt->timeToRun;
double diff = TimeStamp::diff(
*timeToRun,currentTime);
@@ -146,13 +147,13 @@ void Timer::Pvt::run()
period = timerNodePvt->period;
if(period>0.0) {
timerNodePvt->timeToRun += period;
- addElement(timerNodePvt);
+ addElement(*timerNodePvt);
} else {
timerNodePvt->timerPvt = 0;
}
timerListNode = timerList.getHead();
if(timerListNode!=0) {
- timerNodePvt = timerListNode->getObject();
+ timerNodePvt = &timerListNode->getObject();
timeToRun = &timerNodePvt->timeToRun;
} else {
timeToRun = 0;
@@ -182,25 +183,25 @@ Timer::Timer(String threadName, ThreadPriority priority)
Timer::~Timer() {
{
- Lock xx(&pImpl->mutex);
+ Lock xx(pImpl->mutex);
pImpl->alive = false;
}
pImpl->waitForWork.signal();
pImpl->waitForDone.wait();
TimerListNode *node = 0;
while((node = pImpl->timerList.removeHead())!=0) {
- node->getObject()->callback->timerStopped();
+ node->getObject().callback->timerStopped();
}
PVDATA_REFCOUNT_MONITOR_DESTRUCT(timer);
}
-void Timer::scheduleAfterDelay(TimerNode *timerNode,double delay)
+void Timer::scheduleAfterDelay(TimerNode &timerNode,double delay)
{
schedulePeriodic(timerNode,delay,0.0);
}
-void Timer::schedulePeriodic(TimerNode *timerNode,double delay,double period)
+void Timer::schedulePeriodic(TimerNode &timerNode,double delay,double period)
{
- TimerNode::Pvt *timerNodePvt = timerNode->pImpl.get();
+ TimerNode::Pvt *timerNodePvt = timerNode.pImpl.get();
if(timerNodePvt->timerListNode.isOnList()) {
throw std::logic_error(String("already queued"));
}
@@ -214,10 +215,10 @@ void Timer::schedulePeriodic(TimerNode *timerNode,double delay,double period)
timerNodePvt->period = period;
bool isFirst = false;
{
- Lock xx(&pImpl->mutex);
+ Lock xx(pImpl->mutex);
timerNodePvt->timerPvt = pImpl.get();
- pImpl->addElement(timerNodePvt);
- TimerNode::Pvt *first = pImpl->timerList.getHead()->getObject();
+ pImpl->addElement(*timerNodePvt);
+ TimerNode::Pvt *first = &pImpl->timerList.getHead()->getObject();
if(first==timerNodePvt) isFirst = true;
}
if(isFirst) pImpl->waitForWork.signal();
diff --git a/pvDataApp/misc/timer.h b/pvDataApp/misc/timer.h
index 63aa495..84b39da 100644
--- a/pvDataApp/misc/timer.h
+++ b/pvDataApp/misc/timer.h
@@ -27,13 +27,12 @@ public:
virtual void timerStopped() = 0;
};
-class TimerNode : private NoDefaultMethods {
+class TimerNode {
public:
- TimerNode(TimerCallback *timerCallback);
+ TimerNode(TimerCallback &timerCallback);
~TimerNode();
void cancel();
bool isScheduled();
-
class Pvt;
private:
std::auto_ptr pImpl;
@@ -44,8 +43,8 @@ class Timer : private NoDefaultMethods {
public:
Timer(String threadName, ThreadPriority priority);
~Timer();
- void scheduleAfterDelay(TimerNode *timerNode,double delay);
- void schedulePeriodic(TimerNode *timerNode,double delay,double period);
+ void scheduleAfterDelay(TimerNode &timerNode,double delay);
+ void schedulePeriodic(TimerNode &timerNode,double delay,double period);
class Pvt;
private:
diff --git a/testApp/misc/testLinkedList.cpp b/testApp/misc/testLinkedList.cpp
index 5f9e00e..5cc87bc 100644
--- a/testApp/misc/testLinkedList.cpp
+++ b/testApp/misc/testLinkedList.cpp
@@ -35,243 +35,241 @@ typedef LinkedList BasicList;
class Basic {
public:
- Basic(int i): index(i),node(new BasicListNode(this)) {}
- ~Basic() { delete node;}
+ Basic(int i): index(i),node(*this) {}
+ ~Basic() { }
int index;
- BasicListNode*node;
+ BasicListNode node;
};
static void testBasic(FILE * fd ) {
- LinkedList *basicList = new BasicList();
+ LinkedList basicList;
Basic *basics[numNodes];
for(int i=0; iaddTail(basics[i]->node);
- assert(basicList->getLength()==i+1);
+ basicList.addTail(basics[i]->node);
+ assert(basicList.getLength()==i+1);
}
- BasicListNode *basicNode = basicList->getHead();
+ BasicListNode *basicNode = basicList.getHead();
fprintf(fd,"basic addTail");
while(basicNode!=0) {
- fprintf(fd," %d",basicNode->getObject()->index);
- basicNode = basicList->getNext(basicNode);
+ fprintf(fd," %d",basicNode->getObject().index);
+ basicNode = basicList.getNext(*basicNode);
}
- assert(basicList->isEmpty()==false);
- basicNode = basicList->getTail();
+ assert(basicList.isEmpty()==false);
+ basicNode = basicList.getTail();
while(basicNode!=0) {
- fprintf(fd," %d",basicNode->getObject()->index);
- assert(basicList->contains(basicNode->getObject()));
- basicNode = basicList->getPrev(basicNode);
+ fprintf(fd," %d",basicNode->getObject().index);
+ assert(basicNode->isOnList());
+ basicNode = basicList.getPrev(*basicNode);
}
fprintf(fd,"\n");
for(int i=0; igetHead()->getObject();
- assert(basic->index==i);
- assert(basics[i]->node->isOnList()==true);
- basicList->remove(basics[i]);
- assert(basics[i]->node->isOnList()==false);
- int length = basicList->getLength();
+ basicNode = basicList.getHead();
+ assert(basicNode!=0);
+ Basic &basic = basicNode->getObject();
+ assert(basic.index==i);
+ assert(basics[i]->node.isOnList()==true);
+ basicList.remove(basics[i]->node);
+ assert(basics[i]->node.isOnList()==false);
+ int length = basicList.getLength();
assert(length==(numNodes-i-1));
}
- assert(basicList->isEmpty());
+ assert(basicList.isEmpty());
for(int i=numNodes-1; i>=0; i--) {
- basicList->addHead(basics[i]->node);
- assert(basicList->getLength()==numNodes-i);
+ basicList.addHead(basics[i]->node);
+ assert(basicList.getLength()==numNodes-i);
}
- basicNode = basicList->getHead();
+ basicNode = basicList.getHead();
fprintf(fd,"basic addHead");
while(basicNode!=0) {
- fprintf(fd," %d",basicNode->getObject()->index);
- basicNode = basicList->getNext(basicNode);
+ fprintf(fd," %d",basicNode->getObject().index);
+ basicNode = basicList.getNext(*basicNode);
}
fprintf(fd,"\n");
for(int i=0; igetHead()->getObject();
- assert(basic->index==i);
- basicList->removeHead();
- assert(basic->node->isOnList()==false);
- int length = basicList->getLength();
+ basicNode = basicList.getHead();
+ assert(basicNode!=0);
+ Basic &basic = basicNode->getObject();
+ assert(basic.index==i);
+ basicList.removeHead();
+ assert(basic.node.isOnList()==false);
+ int length = basicList.getLength();
assert(length==(numNodes-i-1));
}
- assert(basicList->isEmpty());
- basicList->addTail(basics[0]->node);
- basicNode = basicList->getTail();
- assert(basicNode->getObject()->index==0);
+ assert(basicList.isEmpty());
+ basicList.addTail(basics[0]->node);
+ basicNode = basicList.getTail();
+ assert(basicNode->getObject().index==0);
for(int i=1;iinsertAfter(basicNode,basics[i]->node);
- basicNode = basicList->getTail();
- assert(basicList->getLength()==i+1);
+ basicList.insertAfter(*basicNode,basics[i]->node);
+ basicNode = basicList.getTail();
+ assert(basicList.getLength()==i+1);
}
fprintf(fd,"basic addTail insertAfter");
- basicNode = basicList->getHead();
+ basicNode = basicList.getHead();
while(basicNode!=0) {
- fprintf(fd," %d",basicNode->getObject()->index);
- basicNode = basicList->getNext(basicNode);
+ fprintf(fd," %d",basicNode->getObject().index);
+ basicNode = basicList.getNext(*basicNode);
}
fprintf(fd,"\n");
for(int i=numNodes-1; i>=0; i--) {
- Basic *basic = basicList->getTail()->getObject();
- assert(basic->index==i);
- basicList->removeTail();
- assert(basic->node->isOnList()==false);
- int length = basicList->getLength();
+ Basic &basic = basicList.getTail()->getObject();
+ assert(basic.index==i);
+ basicList.removeTail();
+ assert(basic.node.isOnList()==false);
+ int length = basicList.getLength();
assert(length==i);
}
- assert(basicList->isEmpty());
- basicList->addHead(basics[numNodes-1]->node);
- basicNode = basicList->getHead();
- assert(basicNode->getObject()->index==4);
+ assert(basicList.isEmpty());
+ basicList.addHead(basics[numNodes-1]->node);
+ basicNode = basicList.getHead();
+ assert(basicNode->getObject().index==4);
for(int i=numNodes-2; i>=0; i--) {
- basicList->insertBefore(basicNode,basics[i]->node);
- basicNode = basicList->getHead();
- assert(basicList->getLength()==numNodes-i);
+ basicList.insertBefore(*basicNode,basics[i]->node);
+ basicNode = basicList.getHead();
+ assert(basicList.getLength()==numNodes-i);
}
fprintf(fd,"basic addTail insertBefore");
- basicNode = basicList->getHead();
+ basicNode = basicList.getHead();
while(basicNode!=0) {
- fprintf(fd," %d",basicNode->getObject()->index);
- basicNode = basicList->getNext(basicNode);
+ fprintf(fd," %d",basicNode->getObject().index);
+ basicNode = basicList.getNext(*basicNode);
}
fprintf(fd,"\n");
for(int i=numNodes-1; i>=0; i--) {
- Basic *basic = basicList->getTail()->getObject();
- assert(basic->index==i);
- basicList->remove(basic);
- assert(basic->node->isOnList()==false);
- int length = basicList->getLength();
+ Basic &basic = basicList.getTail()->getObject();
+ assert(basic.index==i);
+ basicList.remove(basic.node);
+ assert(basic.node.isOnList()==false);
+ int length = basicList.getLength();
assert(length==i);
}
- assert(basicList->isEmpty());
- delete basicList;
+ assert(basicList.isEmpty());
for(int i=0; i *basicList = new BasicList();
+ LinkedList basicList;
Basic *basics[numNodes];
for(int i=0; iaddTail(basics[i]->node);
- assert(basicList->getLength()==i+1);
+ basicList.addTail(basics[i]->node);
+ assert(basicList.getLength()==i+1);
}
- BasicListNode *basicNode = basicList->removeHead();
- while(basicNode!=0) basicNode = basicList->removeHead();
- for(int i=0;iaddTail(basics[i]->node);
- basicNode = basicList->removeHead();
+ BasicListNode *basicNode = basicList.removeHead();
+ while(basicNode!=0) basicNode = basicList.removeHead();
+ for(int i=0;inode);
+ basicNode = basicList.removeHead();
fprintf(fd,"queue");
while(basicNode!=0) {
- fprintf(fd," %d",basicNode->getObject()->index);
- basicNode = basicList->removeHead();
+ fprintf(fd," %d",basicNode->getObject().index);
+ basicNode = basicList.removeHead();
}
fprintf(fd,"\n");
- assert(basicList->isEmpty());
- delete basicList;
+ assert(basicList.isEmpty());
for(int i=0; i *basicList = new BasicList();
+ LinkedList basicList;
Basic *basics[numNodes];
for(int i=0; iaddHead(basics[i]->node);
- assert(basicList->getLength()==i+1);
+ basicList.addHead(basics[i]->node);
+ assert(basicList.getLength()==i+1);
}
- BasicListNode *basicNode = basicList->removeHead();
- while(basicNode!=0) basicNode = basicList->removeHead();
- for(int i=0;iaddHead(basics[i]->node);
- basicNode = basicList->removeHead();
+ BasicListNode *basicNode = basicList.removeHead();
+ while(basicNode!=0) basicNode = basicList.removeHead();
+ for(int i=0;inode);
+ basicNode = basicList.removeHead();
fprintf(fd,"stack");
while(basicNode!=0) {
- fprintf(fd," %d",basicNode->getObject()->index);
- basicNode = basicList->removeHead();
+ fprintf(fd," %d",basicNode->getObject().index);
+ basicNode = basicList.removeHead();
}
fprintf(fd,"\n");
- assert(basicList->isEmpty());
- delete basicList;
+ assert(basicList.isEmpty());
for(int i=0; i *basicList = new BasicList();
+ LinkedList basicList;
Basic *basics[numNodes];
for(int i=0; iaddTail(basics[i]->node);
+ for(int i=0;inode);
fprintf(fd,"list");
- BasicListNode *basicNode = basicList->removeHead();
+ BasicListNode *basicNode = basicList.removeHead();
while(basicNode!=0) {
- fprintf(fd," %d",basicNode->getObject()->index);
- basicNode = basicList->removeHead();
+ fprintf(fd," %d",basicNode->getObject().index);
+ basicNode = basicList.removeHead();
}
fprintf(fd,"\n");
- assert(basicList->isEmpty());
- delete basicList;
+ assert(basicList.isEmpty());
for(int i=0; i *basicList = new BasicList();
+ LinkedList basicList;
Basic *basics[numNodes];
for(int i=0; iaddHead(basics[4]->node);
- basicList->insertAfter(basics[4]->node,basics[3]->node);
- basicList->insertAfter(basics[3]->node,basics[2]->node);
- basicList->addTail(basics[1]->node);
- basicList->addTail(basics[0]->node);
- BasicListNode *basicNode = basicList->removeHead();
+ basicList.addHead(basics[4]->node);
+ basicList.insertAfter(basics[4]->node,basics[3]->node);
+ basicList.insertAfter(basics[3]->node,basics[2]->node);
+ basicList.addTail(basics[1]->node);
+ basicList.addTail(basics[0]->node);
+ BasicListNode *basicNode = basicList.removeHead();
fprintf(fd,"stack");
while(basicNode!=0) {
- fprintf(fd," %d",basicNode->getObject()->index);
- basicNode = basicList->removeHead();
+ fprintf(fd," %d",basicNode->getObject().index);
+ basicNode = basicList.removeHead();
}
fprintf(fd,"\n");
- assert(basicList->isEmpty());
- delete basicList;
+ assert(basicList.isEmpty());
for(int i=0; i *basicList = new BasicList();
+ LinkedList basicList;
Basic *basics[numNodes];
for(int i=0; iaddHead(basics[2]->node);
+ basicList.addHead(basics[2]->node);
for(int i=0;icontains(basics[i]->node->getObject())) continue;
- basicNode = basicList->getHead();
+ if(basics[i]->node.isOnList()) continue;
+ basicNode = basicList.getHead();
while(basicNode!=0) {
- if(basicNode->getObject()->index>=basics[i]->index) {
- basicList->insertBefore(basicNode,basics[i]->node);
+ if(basicNode->getObject().index>=basics[i]->index) {
+ basicList.insertBefore(*basicNode,basics[i]->node);
break;
}
- basicNode = basicList->getNext(basicNode);
+ basicNode = basicList.getNext(*basicNode);
}
- if(basicList->contains(basics[i]->node->getObject())) continue;
- basicList->addTail(basics[i]->node);
+ if(basics[i]->node.isOnList()) continue;
+ basicList.addTail(basics[i]->node);
}
fprintf(fd,"list");
- basicNode = basicList->removeHead();
+ basicNode = basicList.removeHead();
while(basicNode!=0) {
- fprintf(fd," %d",basicNode->getObject()->index);
- basicNode = basicList->removeHead();
+ fprintf(fd," %d",basicNode->getObject().index);
+ basicNode = basicList.removeHead();
}
fprintf(fd,"\n");
- assert(basicList->isEmpty());
- delete basicList;
+ assert(basicList.isEmpty());
for(int i=0; i *basicList = new BasicList();
+ LinkedList basicList;
Basic *basics[numNodes];
for(int i=0; iaddTail(basics[j]->node);
- BasicListNode *basicNode = basicList->removeHead();
- while(basicNode!=0) basicNode = basicList->removeHead();
+ for(int j=0;jnode);
+ BasicListNode *basicNode = basicList.removeHead();
+ while(basicNode!=0) basicNode = basicList.removeHead();
}
endTime.getCurrent();
double diff = TimeStamp::diff(endTime,startTime);
@@ -303,18 +301,17 @@ static void testTime(FILE *auxFd) {
fprintf(auxFd,"time per iteration %f microseconds\n",diff);
diff = diff/(numNodes*2); // convert to per addTail/removeHead
fprintf(auxFd,"time per addTail/removeHead %f microseconds\n",diff);
- assert(basicList->isEmpty());
- delete basicList;
+ assert(basicList.isEmpty());
for(int i=0; i *basicList = new BasicList();
+ LinkedList basicList;
Basic *basics[numNodes];
for(int i=0; iaddTail(basics[j]->node);
+ basicList.addTail(basics[j]->node);
}
BasicListNode *basicNode = 0;
{
Lock xx(mutex);
- basicNode = basicList->removeHead();
+ basicNode = basicList.removeHead();
}
while(basicNode!=0) {
Lock xx(mutex);
- basicNode = basicList->removeHead();
+ basicNode = basicList.removeHead();
}
}
endTime.getCurrent();
@@ -347,10 +344,8 @@ static void testTimeLocked(FILE *auxFd) {
fprintf(auxFd,"time per iteration %f microseconds\n",diff);
diff = diff/(numNodes*2); // convert to per addTail/removeHead
fprintf(auxFd,"time per addTail/removeHead %f microseconds\n",diff);
- assert(basicList->isEmpty());
- delete basicList;
+ assert(basicList.isEmpty());
for(int i=0; i stdList;
@@ -391,7 +386,7 @@ static void testStdListTimeLocked(FILE *auxFd) {
TimeStamp startTime;
TimeStamp endTime;
int numNodes = 1000;
- Mutex *mutex = new Mutex();
+ Mutex mutex;
stdList basicList;
Basic *basics[numNodes];
@@ -423,7 +418,6 @@ static void testStdListTimeLocked(FILE *auxFd) {
diff = diff/(numNodes*2); // convert to per addTail/removeHead
fprintf(auxFd,"time per addTail/removeHead %f microseconds\n",diff);
for(int i=0; i
-#include "requester.h"
#include "pvIntrospect.h"
#include "pvData.h"
#include "convert.h"
@@ -34,46 +33,21 @@ static String alarmTimeStamp("alarm,timeStamp");
static String alarmTimeStampValueAlarm("alarm,timeStamp,valueAlarm");
static String allProperties("alarm,timeStamp,display,control,valueAlarm");
-static void testAppend(FILE * fd)
+static void temp()
{
- FieldConstPtrArray fields = new FieldConstPtr[0];
- PVStructure *pvParent = pvDataCreate->createPVStructure(
- 0,String("request"),0,fields);
- PVString* pvStringField = static_cast(
- pvDataCreate->createPVScalar(pvParent, "fieldList", pvString));
- pvStringField->put(String("value,timeStamp"));
- pvParent->appendPVField(pvStringField);
- builder.clear();
- pvParent->toString(&builder);
- fprintf(fd,"%s\n",builder.c_str());
- pvStringField = static_cast(
- pvDataCreate->createPVScalar(pvParent, "extra", pvString));
- pvStringField->put(String("junk"));
- pvParent->appendPVField(pvStringField);
- builder.clear();
- pvParent->toString(&builder);
- fprintf(fd,"%s\n",builder.c_str());
- delete pvParent;
- PVStructure* pvStructure = pvDataCreate->createPVStructure(
- 0,"parent", 0);
- PVStructure* pvChild1 = pvDataCreate->createPVStructure(
- pvStructure, "child1", 0);
- pvStringField = static_cast(
- pvDataCreate->createPVScalar(pvChild1,"value", pvString));
- pvStringField->put("bla");
- pvChild1->appendPVField(pvStringField);
- pvStructure->appendPVField(pvChild1);
- PVStructure* pvChild2 = pvDataCreate->createPVStructure(
- pvStructure, "child2", 0);
- pvStringField = static_cast(
- pvDataCreate->createPVScalar(pvChild2,"value", pvString));
- pvStringField->put("bla");
- pvChild2->appendPVField(pvStringField);
- pvStructure->appendPVField(pvChild2);
- builder.clear();
- pvStructure->toString(&builder);
- fprintf(fd,"%s\n",builder.c_str());
- delete pvStructure;
+ int32 slow = 0xffffffff;
+ int32 shigh = 1;
+ int64 stemp = slow;
+ int64 sresult = slow&0xffffffff;
+ stemp = shigh;
+ sresult += stemp<<32;
+ printf("signed %lld\n",sresult);
+ uint32 ulow = 0xffffffff;
+ uint32 uhigh = 1;
+ uint64 uresult = ulow;
+ uint64 utemp = uhigh;
+ uresult += utemp<<32;
+ printf("unsigned %lld\n",uresult);
}
int main(int argc,char *argv[])
@@ -89,8 +63,7 @@ int main(int argc,char *argv[])
standardField = getStandardField();
standardPVField = getStandardPVField();
convert = getConvert();
- testAppend(fd);
- getShowConstructDestruct()->showDeleteStaticExit(fd);
+ temp();
return(0);
}