use & instead of * in misc.
Simplify lock.h
This commit is contained in:
@@ -26,33 +26,33 @@
|
||||
<div class="toc">
|
||||
<ul>
|
||||
<li><a href="#L48">Introduction</a></li>
|
||||
<li><a href="#L145">PVData Meta Language</a>
|
||||
<li><a href="#L145">PVData Meta Language</a>
|
||||
<ul>
|
||||
<li><a href="#L151">Definition</a></li>
|
||||
<li><a href="#L350">Example</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="#L362">PV - User Description</a>
|
||||
<li><a href="#L362">PV - User Description</a>
|
||||
<ul>
|
||||
<li><a href="#L366">Overview</a></li>
|
||||
<li><a href="#L407">pvType</a></li>
|
||||
<li><a href="#L443">Process Variable Reflection</a>
|
||||
<li><a href="#L443">Process Variable Reflection</a>
|
||||
<ul>
|
||||
<li><a href="#L451">Type Description</a></li>
|
||||
<li><a href="#L571">Reflection Description</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="#L786">Standard Fields</a></li>
|
||||
<li><a href="#L870">PVField - Data Interfaces</a>
|
||||
<li><a href="#L870">PVField - Data Interfaces</a>
|
||||
<ul>
|
||||
<li><a href="#L874">PVField</a></li>
|
||||
<li><a href="#L986">PVAuxInfo</a></li>
|
||||
<li><a href="#L1020">PVScalar and extensions</a>
|
||||
<li><a href="#L1020">PVScalar and extensions</a>
|
||||
<ul>
|
||||
<li><a href="#L1024">Primitive PVField types</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="#L1030">PVArray and Extensions</a>
|
||||
<li><a href="#L1030">PVArray and Extensions</a>
|
||||
<ul>
|
||||
<li><a href="#L1069">PVArray Extensions</a></li>
|
||||
<li><a href="#L1113">Complete set of PVArray Extensions</a></li>
|
||||
@@ -67,11 +67,11 @@
|
||||
<li><a href="#L1298">Convert</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="#L1368">Namespace, Typedefs, and Memory Management</a>
|
||||
<li><a href="#L1368">Namespace, Typedefs, and Memory Management</a>
|
||||
<ul>
|
||||
<li><a href="#L1372">Namespace</a></li>
|
||||
<li><a href="#L1378">typedefs</a></li>
|
||||
<li><a href="#L1425">Memory Managemment</a>
|
||||
<li><a href="#L1425">Memory Managemment</a>
|
||||
<ul>
|
||||
<li><a href="#L1427">NoDefaultMethods</a></li>
|
||||
</ul>
|
||||
@@ -81,36 +81,36 @@
|
||||
<li><a href="#L1443">Other code in this project</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="#L1451">Examples</a>
|
||||
<li><a href="#L1451">Examples</a>
|
||||
<ul>
|
||||
<li><a href="#L1455">Accessing PVData</a></li>
|
||||
<li><a href="#L1474">Creating PVData</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="#L1494">Property</a>
|
||||
<li><a href="#L1494">Property</a>
|
||||
<ul>
|
||||
<li><a href="#L1498">Definition of Property</a></li>
|
||||
<li><a href="#L1510">Standard Properties</a></li>
|
||||
<li><a href="#L1591">Overview of Property Support</a></li>
|
||||
<li><a href="#L1611">timeStamp</a>
|
||||
<li><a href="#L1611">timeStamp</a>
|
||||
<ul>
|
||||
<li><a href="#L1635">timeStamp.h</a></li>
|
||||
<li><a href="#L1739">pvTimeStamp.h</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="#L1779">alarm</a>
|
||||
<li><a href="#L1779">alarm</a>
|
||||
<ul>
|
||||
<li><a href="#L1806">alarm.h</a></li>
|
||||
<li><a href="#L1853">pvAlarm.h</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="#L1893">control</a>
|
||||
<li><a href="#L1893">control</a>
|
||||
<ul>
|
||||
<li><a href="#L1915">control.h</a></li>
|
||||
<li><a href="#L1947">pvControl.h</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="#L1987">display</a>
|
||||
<li><a href="#L1987">display</a>
|
||||
<ul>
|
||||
<li><a href="#L2009">display.h</a></li>
|
||||
<li><a href="#L2071">pvDisplay.h</a></li>
|
||||
@@ -120,7 +120,7 @@
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="#L2187">PVData Factories</a></li>
|
||||
<li><a href="#L2220">Miscellanous Classes</a>
|
||||
<li><a href="#L2220">Miscellanous Classes</a>
|
||||
<ul>
|
||||
<li><a href="#L2224">Overview</a></li>
|
||||
<li><a href="#L2316">BitSet</a></li>
|
||||
@@ -130,7 +130,7 @@
|
||||
<li><a href="#L2485">Executor</a></li>
|
||||
<li><a href="#L2516">Linked List</a></li>
|
||||
<li><a href="#L2630">Lock and Mutex</a></li>
|
||||
<li><a href="#L2646">Message Queue</a>
|
||||
<li><a href="#L2646">Message Queue</a>
|
||||
<ul>
|
||||
<li><a href="#L2648">Definitions</a></li>
|
||||
<li><a href="#L2652">MessageQueue</a></li>
|
||||
@@ -141,7 +141,7 @@
|
||||
<li><a href="#L2757">Serialize</a></li>
|
||||
<li><a href="#L2797">Show Constructors and Destructors</a></li>
|
||||
<li><a href="#L2851">Status</a></li>
|
||||
<li><a href="#L2896">Thread</a>
|
||||
<li><a href="#L2896">Thread</a>
|
||||
<ul>
|
||||
<li><a href="#L2898">ThreadPriority</a></li>
|
||||
<li><a href="#L2902">Thread</a></li>
|
||||
@@ -152,7 +152,7 @@
|
||||
<li><a href="#L3042">Queue</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="#L3105">pvMisc</a>
|
||||
<li><a href="#L3105">pvMisc</a>
|
||||
<ul>
|
||||
<li><a href="#L3109">BitSetUtil</a></li>
|
||||
<li><a href="#L3139">MultiChoice</a></li>
|
||||
@@ -2123,7 +2123,7 @@ be extended. Thus they can only be created via "new" and must be destroyed via
|
||||
</dl>
|
||||
|
||||
<p>The following code uses introspection to get the desired information.</p>
|
||||
<pre>void getValueAndTimeStamp(PVStructurePtr pvStructure,Stringbuffer buf) {
|
||||
<pre>void getValueAndTimeStamp(PVStructurePtr pvStructure,StringBuilder buf) {
|
||||
PVField *valuePV = pvStructure->getSubField(String("value"));
|
||||
if(valuePV==0) {
|
||||
buf += "value field not found";
|
||||
|
||||
@@ -3667,7 +3667,7 @@ public:
|
||||
|
||||
Convert * getConvert() {
|
||||
static Mutex mutex;
|
||||
Lock xx(&mutex);
|
||||
Lock xx(mutex);
|
||||
|
||||
if(convert==0){
|
||||
convert = new ConvertExt();
|
||||
|
||||
@@ -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<StructureConstPtr>(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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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<<nodeName<<" totalConstruct "<<current.cons
|
||||
|
||||
@@ -69,14 +69,14 @@ public:
|
||||
,guard()
|
||||
,nextNode(CDRMonitor::get().addNode(*this))
|
||||
{}
|
||||
void construct(){Lock x(&guard); current.cons++;}
|
||||
void destruct(){Lock x(&guard); current.dtys++;}
|
||||
void incRef(){Lock x(&guard); current.refs++;}
|
||||
void decRef(){Lock x(&guard); current.refs--;}
|
||||
void construct(){Lock x(guard); current.cons++;}
|
||||
void destruct(){Lock x(guard); current.dtys++;}
|
||||
void incRef(){Lock x(guard); current.refs++;}
|
||||
void decRef(){Lock x(guard); current.refs--;}
|
||||
|
||||
CDRNode* next() const{return nextNode;}
|
||||
|
||||
CDRCount get() const{Lock x(&guard); return current;}
|
||||
CDRCount get() const{Lock x(guard); return current;}
|
||||
|
||||
void show(FILE*);
|
||||
void show(std::ostream&) const;
|
||||
|
||||
@@ -46,8 +46,8 @@ public:
|
||||
|
||||
ExecutorNode::ExecutorNode(Command *command)
|
||||
: command(command),
|
||||
node(this),
|
||||
runNode(this)
|
||||
node(*this),
|
||||
runNode(*this)
|
||||
{}
|
||||
|
||||
class ExecutorPvt : public Runnable{
|
||||
@@ -89,13 +89,13 @@ ExecutorPvt::~ExecutorPvt()
|
||||
|
||||
ExecutorListNode *node;
|
||||
while((node=executorList.removeHead())!=0) {
|
||||
delete node->getObject();
|
||||
delete &node->getObject();
|
||||
}
|
||||
}
|
||||
|
||||
void ExecutorPvt::run()
|
||||
{
|
||||
unique_lock<Mutex> 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();
|
||||
}
|
||||
|
||||
|
||||
@@ -15,9 +15,9 @@ class LinkedList;
|
||||
template <typename T>
|
||||
class LinkedListNode : private LinkedListVoidNode {
|
||||
public:
|
||||
LinkedListNode(T *object) : LinkedListVoidNode(object){}
|
||||
LinkedListNode(T &object) : LinkedListVoidNode(&object){}
|
||||
~LinkedListNode() {}
|
||||
T *getObject() { return static_cast<T *>(LinkedListVoidNode::getObject());}
|
||||
T &getObject() { return *static_cast<T *>(LinkedListVoidNode::getObject());}
|
||||
bool isOnList() {return LinkedListVoidNode::isOnList();}
|
||||
friend class LinkedList<T>;
|
||||
};
|
||||
@@ -28,27 +28,27 @@ public:
|
||||
LinkedList() : LinkedListVoid() {}
|
||||
~LinkedList() {}
|
||||
int getLength() {return LinkedListVoid::getLength();}
|
||||
void addTail(LinkedListNode<T> *listNode)
|
||||
void addTail(LinkedListNode<T> &listNode)
|
||||
{
|
||||
LinkedListVoid::addTail(static_cast<LinkedListVoidNode *>(listNode));
|
||||
LinkedListVoid::addTail(static_cast<LinkedListVoidNode &>(listNode));
|
||||
}
|
||||
void addHead(LinkedListNode<T> *listNode)
|
||||
void addHead(LinkedListNode<T> &listNode)
|
||||
{
|
||||
LinkedListVoid::addHead(static_cast<LinkedListVoidNode *>(listNode));
|
||||
LinkedListVoid::addHead(static_cast<LinkedListVoidNode &>(listNode));
|
||||
}
|
||||
void insertAfter(LinkedListNode<T> *listNode,
|
||||
LinkedListNode<T> *addNode)
|
||||
void insertAfter(LinkedListNode<T> &listNode,
|
||||
LinkedListNode<T> &addNode)
|
||||
{
|
||||
LinkedListVoid::insertAfter(
|
||||
static_cast<LinkedListVoidNode *>(listNode),
|
||||
static_cast<LinkedListVoidNode *>(addNode));
|
||||
static_cast<LinkedListVoidNode &>(listNode),
|
||||
static_cast<LinkedListVoidNode &>(addNode));
|
||||
}
|
||||
void insertBefore(LinkedListNode<T> *listNode,
|
||||
LinkedListNode<T> *addNode)
|
||||
void insertBefore(LinkedListNode<T> &listNode,
|
||||
LinkedListNode<T> &addNode)
|
||||
{
|
||||
LinkedListVoid::insertBefore(
|
||||
static_cast<LinkedListVoidNode *>(listNode),
|
||||
static_cast<LinkedListVoidNode *>(addNode));
|
||||
static_cast<LinkedListVoidNode &>(listNode),
|
||||
static_cast<LinkedListVoidNode &>(addNode));
|
||||
}
|
||||
LinkedListNode<T> *removeTail(){
|
||||
return static_cast<LinkedListNode<T> *>(LinkedListVoid::removeTail());
|
||||
@@ -56,11 +56,8 @@ public:
|
||||
LinkedListNode<T> *removeHead(){
|
||||
return static_cast<LinkedListNode<T> *>(LinkedListVoid::removeHead());
|
||||
}
|
||||
void remove(LinkedListNode<T> *listNode){
|
||||
LinkedListVoid::remove(static_cast<LinkedListVoidNode *>(listNode));
|
||||
}
|
||||
void remove(T *object){
|
||||
LinkedListVoid::remove(object);
|
||||
void remove(LinkedListNode<T> &listNode){
|
||||
LinkedListVoid::remove(static_cast<LinkedListVoidNode &>(listNode));
|
||||
}
|
||||
LinkedListNode<T> *getHead(){
|
||||
return static_cast<LinkedListNode<T> *>(LinkedListVoid::getHead());
|
||||
@@ -68,16 +65,15 @@ public:
|
||||
LinkedListNode<T> *getTail(){
|
||||
return static_cast<LinkedListNode<T> *>(LinkedListVoid::getTail());
|
||||
}
|
||||
LinkedListNode<T> *getNext(LinkedListNode<T> *listNode){
|
||||
LinkedListNode<T> *getNext(LinkedListNode<T> &listNode){
|
||||
return static_cast<LinkedListNode<T> *>(LinkedListVoid::getNext(
|
||||
static_cast<LinkedListVoidNode *>(listNode)));
|
||||
static_cast<LinkedListVoidNode &>(listNode)));
|
||||
}
|
||||
LinkedListNode<T> *getPrev(LinkedListNode<T> *listNode){
|
||||
LinkedListNode<T> *getPrev(LinkedListNode<T> &listNode){
|
||||
return static_cast<LinkedListNode<T> *>(LinkedListVoid::getPrev(
|
||||
static_cast<LinkedListVoidNode *>(listNode)));
|
||||
static_cast<LinkedListVoidNode &>(listNode)));
|
||||
}
|
||||
bool isEmpty() { return LinkedListVoid::isEmpty();}
|
||||
bool contains(T *object) { return LinkedListVoid::contains(object);}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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<typename Lockable>
|
||||
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<typename Lockable>
|
||||
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<Mutex> 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<Mutex> 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;
|
||||
};
|
||||
|
||||
|
||||
}}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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<Pvt> 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:
|
||||
|
||||
@@ -35,243 +35,241 @@ typedef LinkedList<Basic> 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<Basic> *basicList = new BasicList();
|
||||
LinkedList<Basic> basicList;
|
||||
Basic *basics[numNodes];
|
||||
for(int i=0; i<numNodes; i++) {
|
||||
basics[i] = new Basic(i);
|
||||
basicList->addTail(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; i<numNodes; i++) {
|
||||
Basic *basic = basicList->getHead()->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; i<numNodes; i++) {
|
||||
Basic *basic = basicList->getHead()->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;i<numNodes;i++) {
|
||||
basicList->insertAfter(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<numNodes; i++) delete basics[i];
|
||||
}
|
||||
|
||||
static void testQueue(FILE * fd ) {
|
||||
LinkedList<Basic> *basicList = new BasicList();
|
||||
LinkedList<Basic> basicList;
|
||||
Basic *basics[numNodes];
|
||||
for(int i=0; i<numNodes; i++) {
|
||||
basics[i] = new Basic(i);
|
||||
}
|
||||
fprintf(fd,"\nQueue test\n");
|
||||
for(int i=0;i<numNodes;i++) {
|
||||
basicList->addTail(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;i<numNodes;i++) basicList->addTail(basics[i]->node);
|
||||
basicNode = basicList->removeHead();
|
||||
BasicListNode *basicNode = basicList.removeHead();
|
||||
while(basicNode!=0) basicNode = basicList.removeHead();
|
||||
for(int i=0;i<numNodes;i++) basicList.addTail(basics[i]->node);
|
||||
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<numNodes; i++) delete basics[i];
|
||||
}
|
||||
|
||||
static void testStack(FILE * fd ) {
|
||||
LinkedList<Basic> *basicList = new BasicList();
|
||||
LinkedList<Basic> basicList;
|
||||
Basic *basics[numNodes];
|
||||
for(int i=0; i<numNodes; i++) {
|
||||
basics[i] = new Basic(i);
|
||||
}
|
||||
fprintf(fd,"\nStack test\n");
|
||||
for(int i=0;i<numNodes;i++) {
|
||||
basicList->addHead(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;i<numNodes;i++) basicList->addHead(basics[i]->node);
|
||||
basicNode = basicList->removeHead();
|
||||
BasicListNode *basicNode = basicList.removeHead();
|
||||
while(basicNode!=0) basicNode = basicList.removeHead();
|
||||
for(int i=0;i<numNodes;i++) basicList.addHead(basics[i]->node);
|
||||
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<numNodes; i++) delete basics[i];
|
||||
}
|
||||
|
||||
static void testList(FILE * fd ) {
|
||||
LinkedList<Basic> *basicList = new BasicList();
|
||||
LinkedList<Basic> basicList;
|
||||
Basic *basics[numNodes];
|
||||
for(int i=0; i<numNodes; i++) {
|
||||
basics[i] = new Basic(i);
|
||||
}
|
||||
fprintf(fd,"\ntestList\n");
|
||||
for(int i=0;i<numNodes;i++) basicList->addTail(basics[i]->node);
|
||||
for(int i=0;i<numNodes;i++) basicList.addTail(basics[i]->node);
|
||||
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<numNodes; i++) delete basics[i];
|
||||
}
|
||||
|
||||
static void testRandomInsertRemove(FILE * fd ) {
|
||||
LinkedList<Basic> *basicList = new BasicList();
|
||||
LinkedList<Basic> basicList;
|
||||
Basic *basics[numNodes];
|
||||
for(int i=0; i<numNodes; i++) {
|
||||
basics[i] = new Basic(i);
|
||||
}
|
||||
fprintf(fd,"\nRandom insert/remove test\n");
|
||||
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();
|
||||
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<numNodes; i++) delete basics[i];
|
||||
}
|
||||
|
||||
static void testOrderedQueue(FILE * fd ) {
|
||||
LinkedList<Basic> *basicList = new BasicList();
|
||||
LinkedList<Basic> basicList;
|
||||
Basic *basics[numNodes];
|
||||
for(int i=0; i<numNodes; i++) {
|
||||
basics[i] = new Basic(i);
|
||||
}
|
||||
BasicListNode *basicNode = 0;
|
||||
fprintf(fd,"\nOrdered Queue test\n");
|
||||
basicList->addHead(basics[2]->node);
|
||||
basicList.addHead(basics[2]->node);
|
||||
for(int i=0;i<numNodes;i++) {
|
||||
if(basicList->contains(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<numNodes; i++) delete basics[i];
|
||||
}
|
||||
|
||||
@@ -280,7 +278,7 @@ static void testTime(FILE *auxFd) {
|
||||
TimeStamp endTime;
|
||||
int numNodes = 1000;
|
||||
|
||||
LinkedList<Basic> *basicList = new BasicList();
|
||||
LinkedList<Basic> basicList;
|
||||
Basic *basics[numNodes];
|
||||
for(int i=0; i<numNodes; i++) {
|
||||
basics[i] = new Basic(i);
|
||||
@@ -289,9 +287,9 @@ static void testTime(FILE *auxFd) {
|
||||
int ntimes = 1000;
|
||||
startTime.getCurrent();
|
||||
for(int i=0; i<ntimes; i++) {
|
||||
for(int j=0;j<numNodes;j++) basicList->addTail(basics[j]->node);
|
||||
BasicListNode *basicNode = basicList->removeHead();
|
||||
while(basicNode!=0) basicNode = basicList->removeHead();
|
||||
for(int j=0;j<numNodes;j++) basicList.addTail(basics[j]->node);
|
||||
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<numNodes; i++) delete basics[i];
|
||||
}
|
||||
|
||||
static void testTimeLocked(FILE *auxFd) {
|
||||
TimeStamp startTime;
|
||||
TimeStamp endTime;
|
||||
Mutex *mutex = new Mutex();
|
||||
Mutex mutex;
|
||||
int numNodes = 1000;
|
||||
|
||||
LinkedList<Basic> *basicList = new BasicList();
|
||||
LinkedList<Basic> basicList;
|
||||
Basic *basics[numNodes];
|
||||
for(int i=0; i<numNodes; i++) {
|
||||
basics[i] = new Basic(i);
|
||||
@@ -325,16 +322,16 @@ static void testTimeLocked(FILE *auxFd) {
|
||||
for(int i=0; i<ntimes; i++) {
|
||||
for(int j=0;j<numNodes;j++) {
|
||||
Lock xx(mutex);
|
||||
basicList->addTail(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<numNodes; i++) delete basics[i];
|
||||
delete mutex;
|
||||
}
|
||||
|
||||
typedef std::list<Basic *> 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<numNodes; i++) delete basics[i];
|
||||
delete mutex;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
@@ -33,7 +33,6 @@ using namespace epics::pvData;
|
||||
|
||||
static void testBasic(FILE * fd,FILE *auxfd ) {
|
||||
int queueSize = 3;
|
||||
int numMessages = 5;
|
||||
String messages[]= {
|
||||
String("1"),String("2"),String("3"),String("4"),String("5")
|
||||
};
|
||||
|
||||
@@ -34,12 +34,11 @@ class MyCallback : public TimerCallback {
|
||||
public:
|
||||
MyCallback(String name,FILE *fd,FILE *auxfd,Event *wait)
|
||||
: name(name),fd(fd),auxfd(auxfd),wait(wait),
|
||||
timerNode(new TimerNode(this)),timeStamp(TimeStamp())
|
||||
timerNode(*this),timeStamp(TimeStamp())
|
||||
{
|
||||
}
|
||||
~MyCallback()
|
||||
{
|
||||
delete timerNode;
|
||||
}
|
||||
virtual void callback()
|
||||
{
|
||||
@@ -50,14 +49,14 @@ public:
|
||||
{
|
||||
fprintf(fd,"timerStopped %s\n",name.c_str());
|
||||
}
|
||||
TimerNode *getTimerNode() { return timerNode;}
|
||||
TimerNode &getTimerNode() { return timerNode;}
|
||||
TimeStamp &getTimeStamp() { return timeStamp;}
|
||||
private:
|
||||
String name;
|
||||
FILE *fd;
|
||||
FILE *auxfd;
|
||||
Event *wait;
|
||||
TimerNode *timerNode;
|
||||
TimerNode timerNode;
|
||||
TimeStamp timeStamp;
|
||||
};
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
|
||||
#include <epicsAssert.h>
|
||||
|
||||
#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<PVString*>(
|
||||
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<PVString*>(
|
||||
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<PVString*>(
|
||||
pvDataCreate->createPVScalar(pvChild1,"value", pvString));
|
||||
pvStringField->put("bla");
|
||||
pvChild1->appendPVField(pvStringField);
|
||||
pvStructure->appendPVField(pvChild1);
|
||||
PVStructure* pvChild2 = pvDataCreate->createPVStructure(
|
||||
pvStructure, "child2", 0);
|
||||
pvStringField = static_cast<PVString*>(
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user