Statistics
| Branch: | Revision:

root / src / sim / clockeddefaultlist.cc @ b781545c

History | View | Annotate | Download (3.72 KB)

1
//=========================================================================
2
//  CLOCKEDDEFAULTLIST.CC - part of
3
//
4
//                  Horizon/OMNeT++/OMNEST
5
//           Discrete System Simulation in C++
6
//
7
//   Member functions of
8
//    cLockedDefaultList : stores a set of cOwnedObjects in a thread-safe manner
9
//
10
//  Author: Georg Kunz
11
//
12
//=========================================================================
13

    
14
/*--------------------------------------------------------------*
15
  Copyright (C) 1992-2005 Andras Varga
16
  Copyright (C) 2009      Georg Kunz
17

18
  This file is distributed WITHOUT ANY WARRANTY. See the file
19
  `license' for details on this and other legal matters.
20
*--------------------------------------------------------------*/
21

    
22
#include <stdio.h>           // sprintf
23
#include <string.h>          // memcpy
24
#include <assert.h>
25
#include "regmacros.h"
26
#include "errmsg.h"
27
#include "carray.h"
28
#include "cexception.h"
29
#include "clockeddefaultlist.h"
30
#include "cwatch.h"
31
#include "cthreadpool.h"
32
#include "globals.h"
33
#ifdef WITH_PARSIM
34
#include "ccommbuffer.h"
35
#endif
36

    
37
USING_NAMESPACE
38
//TODO: HORIZON fix me
39
//Register_Class(cLockedDefaultList);
40

    
41
template<class T>
42
cLockedDefaultList<T>::cLockedDefaultList(const char *name) :
43
  cDefaultList(name),
44
  lock()
45
{
46
}
47

    
48
template<class T>
49
cLockedDefaultList<T>::cLockedDefaultList(const cLockedDefaultList& list)
50
{
51
    // should never be called due to exception in cDefaultList(list)
52
    copyNotSupported();
53
}
54

    
55
template<class T>
56
cLockedDefaultList<T>::~cLockedDefaultList()
57
{
58
    delete lock;
59
}
60

    
61
template<class T>
62
void cLockedDefaultList<T>::doInsert(cOwnedObject *obj)
63
{
64
    /*
65
    TODO: check if this is needed
66
    if (cStaticFlag::isSet())
67
    {
68
        pthread_mutex_init(&mutex, NULL);
69
    }
70
    */
71
    lock->lock();
72
    cDefaultList::doInsert(obj);
73
    lock->unlock();
74
}
75

    
76
template<class T>
77
void cLockedDefaultList<T>::ownedObjectDeleted(cOwnedObject *obj)
78
{
79
        lock->lock();
80
    cDefaultList::ownedObjectDeleted(obj);
81
    lock->unlock();
82
}
83

    
84
template<class T>
85
void cLockedDefaultList<T>::yieldOwnership(cOwnedObject *obj, cObject *newowner)
86
{
87
        lock->lock();
88
    cDefaultList::yieldOwnership(obj, newowner);
89
    lock->unlock();
90
}
91

    
92
template<class T>
93
void cLockedDefaultList<T>::takeAllObjectsFrom(cLockedDefaultList& other)
94
{
95
    while (other.defaultListItems()>0)
96
        take(other.defaultListGet(0));
97
}
98

    
99
template<class T>
100
cLockedDefaultList<T>& cLockedDefaultList<T>::operator=(const cLockedDefaultList& list)
101
{
102
    copyNotSupported();
103
    return *this;
104
}
105

    
106
template<class T>
107
std::string cLockedDefaultList<T>::info()
108
{
109
        lock->lock();
110
    std::string str = cDefaultList::info();
111
    lock->unlock();
112
    return str;
113
}
114

    
115
template<class T>
116
void cLockedDefaultList<T>::forEachChild(cVisitor *v)
117
{
118
        lock->lock();
119
    cDefaultList::forEachChild(v);
120
    lock->unlock();
121
}
122

    
123
template<class T>
124
void cLockedDefaultList<T>::parsimPack(cCommBuffer *buffer)
125
{
126
        lock->lock();
127
    cDefaultList::parsimPack(buffer);
128
    lock->unlock();
129
}
130

    
131
template<class T>
132
void cLockedDefaultList<T>::parsimUnpack(cCommBuffer *buffer)
133
{
134
        lock->lock();
135
    cDefaultList::parsimUnpack(buffer);
136
    lock->unlock();
137
}
138

    
139
template<class T>
140
void cLockedDefaultList<T>::take(cOwnedObject *obj)
141
{
142
        lock->lock();
143
    cDefaultList::take(obj);
144
    lock->unlock();
145
}
146

    
147
template<class T>
148
void cLockedDefaultList<T>::drop(cOwnedObject *obj)
149
{
150
        lock->lock();
151
    cDefaultList::drop(obj);
152
    lock->unlock();
153
}
154

    
155
template<class T>
156
cOwnedObject *cLockedDefaultList<T>::defaultListGet(int k)
157
{
158
        lock->lock();
159
    cOwnedObject* obj = cDefaultList::defaultListGet(k);
160
    lock->unlock();
161
    return obj;
162
}
163

    
164
template<class T>
165
bool cLockedDefaultList<T>::defaultListContains(cOwnedObject *obj)
166
{
167
        lock->lock();
168
    bool result = cDefaultList::defaultListContains(obj);
169
    lock->unlock();
170
    return result;
171
}