Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

OSGDgramQueue.cpp

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002  *                                OpenSG                                     *
00003  *                                                                           *
00004  *                                                                           *
00005  *             Copyright (C) 2000-2002 by the OpenSG Forum                   *
00006  *                                                                           *
00007  *                            www.opensg.org                                 *
00008  *                                                                           *
00009  *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          *
00010  *                                                                           *
00011 \*---------------------------------------------------------------------------*/
00012 /*---------------------------------------------------------------------------*\
00013  *                                License                                    *
00014  *                                                                           *
00015  * This library is free software; you can redistribute it and/or modify it   *
00016  * under the terms of the GNU Library General Public License as published    *
00017  * by the Free Software Foundation, version 2.                               *
00018  *                                                                           *
00019  * This library is distributed in the hope that it will be useful, but       *
00020  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00022  * Library General Public License for more details.                          *
00023  *                                                                           *
00024  * You should have received a copy of the GNU Library General Public         *
00025  * License along with this library; if not, write to the Free Software       *
00026  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
00027  *                                                                           *
00028 \*---------------------------------------------------------------------------*/
00029 /*---------------------------------------------------------------------------*\
00030  *                                Changes                                    *
00031  *                                                                           *
00032  *                                                                           *
00033  *                                                                           *
00034  *                                                                           *
00035  *                                                                           *
00036  *                                                                           *
00037 \*---------------------------------------------------------------------------*/
00038 
00039 #include <stdlib.h>
00040 #include <stdio.h>
00041 
00042 #include <vector>
00043 #include <algorithm>
00044 #include <set>
00045 
00046 #include "OSGConfig.h"
00047 #include "OSGBaseThread.h"
00048 #include "OSGThreadManager.h"
00049 #include "OSGSocketSelection.h"
00050 #include "OSGDgramQueue.h"
00051 
00052 OSG_USING_NAMESPACE
00053 
00060 /*-------------------------------------------------------------------------*/
00061 /*                            constructor destructor                       */
00062 
00067 DgramQueue::DgramQueue():
00068     _queue(),
00069     _waiting(false)
00070 {
00071     char barrierName[256];
00072     sprintf(barrierName,"DgramQueue%p",this);
00073 
00074     // create barrier
00075     _barrier = Barrier::get(barrierName);
00076 }
00077 
00080 DgramQueue::~DgramQueue()
00081 {
00082 }
00083 
00084 /*-------------------------------------------------------------------------*/
00085 /*                           put / get                                     */
00086 
00089 void DgramQueue::put( Dgram *dgram )
00090 {
00091     _queue.push_back(dgram);
00092     if(_waiting)
00093     {
00094         _waiting = false;
00095         _barrier->enter(2);
00096     }
00097 }
00098 
00101 Dgram *DgramQueue::get( Lock *lock )
00102 {
00103     Dgram *result;
00104 
00105     if(_queue.empty())
00106     {
00107         _waiting = true;
00108         lock->release();
00109         _barrier->enter(2);
00110         lock->aquire();
00111     }
00112     result = _queue.front();
00113     _queue.pop_front();
00114 
00115     return result;
00116 }
00117 
00120 void DgramQueue::wait( Lock *lock )
00121 {
00122     if(_queue.empty())
00123     {
00124         _waiting = true;
00125         lock->release();
00126         _barrier->enter(2);
00127         lock->aquire();
00128     }
00129 }
00130 
00133 bool DgramQueue::waiting(void)
00134 {
00135     return _waiting;
00136 }
00137 
00138 bool DgramQueue::empty(void)
00139 {
00140     return _queue.empty();
00141 }
00142 
00143 /*-------------------------------------------------------------------------*/
00144 /*                              cvs id's                                   */
00145 
00146 #ifdef __sgi
00147 #pragma set woff 1174
00148 #endif
00149 
00150 #ifdef OSG_LINUX_ICC
00151 #pragma warning( disable : 177 )
00152 #endif
00153 
00154 namespace 
00155 {
00156     static Char8 cvsid_cpp[] = "@(#)$Id:$";
00157     static Char8 cvsid_hpp[] = OSG_DGRAMQUEUEHEADER_CVSID;
00158 }

Generated on Thu Aug 25 04:02:47 2005 for OpenSG by  doxygen 1.4.3