Statistics
| Branch: | Revision:

root / include / cspinlockedmsgheap.h @ 7f251033

History | View | Annotate | Download (3.14 KB)

1
//==========================================================================
2
//  CSPINLOCKEDMSGHEAP.H - part of
3
//                     Horizon/OMNeT++/OMNEST
4
//            Discrete System Simulation in C++
5
//
6
//
7
//  Declaration of the following classes:
8
//    cLockedMessageHeap : thread safe wrapper around cMessageHeap
9
//
10
//==========================================================================
11

    
12
/*--------------------------------------------------------------*
13
  Copyright (C) 1992-2005 Andras Varga
14
  Copyright (C) 2010 Georg Kunz
15

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

    
20
#ifndef __CSPINLOCKEDMSGHEAP_H
21
#define __CSPINLOCKEDMSGHEAP_H
22

    
23
#include "cobject.h"
24

    
25
#ifdef ATOMIC_OPS_DEBUG
26
    #include "catomicopsdebug.h"
27
#else
28
    #include <atomic_ops.h>
29
#endif
30

    
31
class cMessage;
32

    
33

    
34
/**
35
 * @see Iterator
36
 * @ingroup Internals
37
 */
38
class SIM_API cSpinlockedMessageHeap : public cMessageHeap
39
{
40
  private:
41
    volatile AO_t lck;
42
    void lock();
43
    void unlock();
44

    
45
  public:
46
    /** @name Constructors, destructor, assignment */
47
    //@{
48

    
49
    /**
50
     * Copy constructor.
51
     */
52
    cSpinlockedMessageHeap(const cSpinlockedMessageHeap& msgq);
53

    
54
    /**
55
     * Constructor.
56
     */
57
    cSpinlockedMessageHeap(const char *name=NULL, int size=128);
58

    
59
    /**
60
     * Assignment operator. The name member doesn't get copied;
61
     * see cObject's operator=() for more details.
62
     */
63
    cSpinlockedMessageHeap& operator=(const cSpinlockedMessageHeap& msgqueue);
64
    //@}
65

    
66
    /** @name Redefined cObject member functions. */
67
    //@{
68

    
69
    /**
70
     * Creates and returns an exact copy of this object.
71
     * See cObject for more details.
72
     */
73
    virtual cObject *dup();
74

    
75
    /**
76
     * Calls v->visit(this) for each contained object.
77
     * See cObject for more details.
78
     */
79
    virtual void forEachChild(cVisitor *v);
80

    
81
    // no netPack() and netUnpack()
82
    //@}
83

    
84
    /** @name Container functions. */
85
    //@{
86

    
87
    /**
88
     * Insert a new message into the heap.
89
     */
90
    void insert(cMessage *event);
91

    
92
    /**
93
     * Removes and return the first message in the heap (the one
94
     * with the smallest timestamp.) If the heap is empty, it returns NULL.
95
     */
96
    cMessage *removeFirst();
97

    
98
    /**
99
     * Removes and returns the given message in the heap. If the message is
100
     * not in the heap, returns NULL.
101
     */
102
    cMessage *remove(cMessage *event);
103

    
104
    /**
105
     * Returns the mth message in the heap if 0 <= m < length(), and NULL
106
     * otherwise. Note that iteration does not necessarily return messages
107
     * in increasing timestamp (arrivalTime()) order unless you called
108
     * sort() before.
109
     */
110
    cMessage *peek(int m);
111

    
112
    /**
113
     * Sorts the contents of the heap. This is only necessary if one wants
114
     * to iterate through in the FES in strict timestamp order.
115
     */
116
    void sort();
117

    
118
    /**
119
     * Deletes all messages in the heap.
120
     */
121
    void clear();
122

    
123
    /**
124
     *
125
     */
126
    virtual cMessage* peekFirst();
127

    
128
    int length();
129

    
130
    /**
131
     * Returns true if the heap is empty.
132
     */
133
    bool empty();
134
    //@}
135
};
136

    
137
#endif