fixed: gcc8 compile issues
[opensg.git] / Source / Base / Network / Socket / OSGDgramQueue.cpp
blob792bbc4a11264dfa4b997c23102710211543f9f5
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
10 * *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13 * License *
14 * *
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
18 * *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
23 * *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
27 * *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
30 * Changes *
31 * *
32 * *
33 * *
34 * *
35 * *
36 * *
37 \*---------------------------------------------------------------------------*/
39 #include <cstdlib>
40 #include <cstdio>
42 #include <vector>
43 #include <algorithm>
44 #include <set>
46 #include "OSGConfig.h"
47 #include "OSGBaseThread.h"
48 #include "OSGThreadManager.h"
49 #include "OSGSocketSelection.h"
50 #include "OSGDgramQueue.h"
52 OSG_USING_NAMESPACE
54 /** \class OSG::DgramQueue
55 * \brief Stream socket connection
57 **/
59 /*-------------------------------------------------------------------------*/
60 /* constructor destructor */
62 /*! Constructor
63 * size must be 2^x
66 DgramQueue::DgramQueue():
67 _barrier(NULL ),
68 _queue ( ),
69 _waiting(false)
71 char barrierName[256];
72 sprintf(barrierName,"DgramQueue%p", static_cast<void *>(this));
74 // create barrier
75 _barrier = Barrier::get(barrierName, false);
78 /*! Destructor
80 DgramQueue::~DgramQueue()
82 _barrier = NULL;
85 /*-------------------------------------------------------------------------*/
86 /* put / get */
88 /*! put a dgram to the queue.
90 void DgramQueue::put( Dgram *dgram )
92 _queue.push_back(dgram);
93 if(_waiting)
95 _waiting = false;
96 _barrier->enter(2);
100 /*! get a dgram from the queue. Block if queue is empty
102 Dgram *DgramQueue::get( Lock *lock )
104 Dgram *result;
106 if(_queue.empty())
108 _waiting = true;
109 lock->release();
110 _barrier->enter(2);
111 lock->acquire();
113 result = _queue.front();
114 _queue.pop_front();
116 return result;
119 /*! wait for a dgram but dont read
121 void DgramQueue::wait( Lock *lock )
123 if(_queue.empty())
125 _waiting = true;
126 lock->release();
127 _barrier->enter(2);
128 lock->acquire();
132 /*! true, if reader is waiting
134 bool DgramQueue::waiting(void)
136 return _waiting;
139 bool DgramQueue::empty(void)
141 return _queue.empty();