Statistics
| Branch: | Revision:

root / include / clockedmsgheap.h @ 01873262

History | View | Annotate | Download (3.12 KB)

1
//==========================================================================
2
//  CLOCKEDMSGHEAP.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 __CLOCKEDMSGHEAP_H
21
#define __CLOCKEDMSGHEAP_H
22

    
23
#include "cobject.h"
24
#include <pthread.h>
25

    
26
class cMessage;
27

    
28

    
29
/**
30
 * Stores the future event set. The underlying data structure is heap;
31
 * the array used to store the heap expands as needed.
32
 *
33
 * @see Iterator
34
 * @ingroup Internals
35
 */
36
class SIM_API cLockedMessageHeap : public cMessageHeap
37
{
38
  private:
39
    pthread_mutex_t mutex;      // the lock
40

    
41
  public:
42
    /** @name Constructors, destructor, assignment */
43
    //@{
44

    
45
    /**
46
     * Copy constructor.
47
     */
48
  cLockedMessageHeap(const cLockedMessageHeap& msgq);
49

    
50
    /**
51
     * Constructor.
52
     */
53
  cLockedMessageHeap(const char *name=NULL, int size=128);
54

    
55
    /**
56
     * Destructor.
57
     */
58
    virtual ~cLockedMessageHeap();
59

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

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

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

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

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

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

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

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

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

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

    
113
    /*
114
     * See peek(1)
115
     */
116
    cMessage *peekFirst();
117

    
118
    /**
119
     * Sorts the contents of the heap. This is only necessary if one wants
120
     * to iterate through in the FES in strict timestamp order.
121
     */
122
    void sort();
123

    
124
    /**
125
     * Deletes all messages in the heap.
126
     */
127
    void clear();
128
    //@}
129
};
130

    
131
#endif
132