Statistics
| Branch: | Revision:

root / include / ctaskring.h @ master

History | View | Annotate | Download (3.3 KB)

1 01873262 Georg Kunz
//==========================================================================
2
//  CTASKRING.H - part of
3
//                     OMNeT++/OMNEST
4
//            Discrete System Simulation in C++
5
//
6
//
7
//  Declaration of the following classes:
8
//    cTaskRing : ring buffer to store tasks for use by cThreadPool
9
//
10
//==========================================================================
11
12
/*--------------------------------------------------------------*
13
  Copyright (C) 1992-2005 Andras Varga
14
  Copyright (C) 2009 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 __CTASKRING_H
21
#define __CTASKRING_H
22
23
#include "cobject.h"
24
#include "cownedobject.h"
25
26
class cMessage;
27
28
29
/**
30
 * Stores the future event set. The underlying data structure is ring buffer;
31
 * the array used to store the ring buffer expands as needed.
32
 *
33
 * @see Iterator
34
 * @ingroup Horizon
35
 */
36
class SIM_API cTaskRing : public cOwnedObject
37
{
38
  private:
39
    cMessage **h;          // pointer to the 'ring'
40
    int front;                  // index of first free field
41
    int back;                   // index of last field in the buffer
42
                                // note: this is the first to remove according to FIFO
43
44
    int n;                      // number of elements in the heap
45
    int size;                   // size of allocated h array
46
    unsigned long insertcntr;   // counts insertions
47
48
  public:
49
    /** @name Constructors, destructor, assignment */
50
    //@{
51
52
    /**
53
     * Copy constructor.
54
     */
55
    cTaskRing(const cTaskRing& msgq);
56
57
    /**
58
     * Constructor.
59
     */
60
    cTaskRing(const char *name=NULL, int size=128);
61
62
    /**
63
     * Destructor.
64
     */
65
    virtual ~cTaskRing();
66
67
    /**
68
     * Assignment operator. The name member doesn't get copied;
69
     * see cObject's operator=() for more details.
70
     */
71
    cTaskRing& operator=(const cTaskRing& msgqueue);
72
    //@}
73
74
75
    /** @name Redefined cObject member functions. */
76
    //@{
77
78
    /**
79
     * Creates and returns an exact copy of this object.
80
     * See cObject for more details.
81
     */
82
    virtual cTaskRing *dup() const  {return new cTaskRing(*this);}
83
84
    /**
85
     * Produces a one-line description of object contents into the buffer passed as argument.
86
     * See cObject for more details.
87
     */
88
    virtual std::string info() const;
89
90
    /**
91
     * Calls v->visit(this) for each contained object.
92
     * See cObject for more details.
93
     */
94
    //virtual void forEachChild(cVisitor *v);
95
96
    // no netPack() and netUnpack()
97
    //@}
98
99
100
    /** @name Container functions. */
101
    //@{
102
103
    /**
104
     * Insert a new message into the heap.
105
     */
106
    void insert(cMessage *event);
107
108
    /**
109
     * Removes and return the first message in the heap (the one
110
     * with the smallest timestamp.) If the heap is empty, it returns NULL.
111
     */
112
    cMessage *getFirst();
113
114
    /**
115
     * Deletes all messages in the heap.
116
     */
117
    void clear();
118
119
    /**
120
     * Removes all messaged from the ring without deleting them.
121
     */
122
    void clearNoDelete();
123
124
    /**
125
     * Returns the number of messages in the heap.
126
     */
127
    int length() const {return n;}
128
129
    /**
130
     * Returns true if the heap is empty.
131
     */
132
    bool empty() const {return n==0;}
133
    //@}
134
};
135
136
#endif