Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

buffer.cpp

Go to the documentation of this file.
00001 /********************************************************************
00002 Description:
00003 part of the 3Dsia project
00004 created: StonedBones, 31.1.2000
00005 
00006 History:
00007     date,   name,       changes,                    in funtion
00008     200400  StonedBones changed dynamic list to STL queue
00009     110400  xandi       changed all mallocs to new and all NULL to 0
00010     310100  StonedBones created source from scratch
00011 
00012 ********************************************************************/
00013 
00014 #include "buffer.h"
00015 
00016 #include <unistd.h>
00017 #include <pthread.h>
00018 
00019 #include <stdio.h>
00020 
00021 /*...................................................................
00022 Description: Constructor
00023 Args: <none>
00024 Returns: <none>
00025 Created: StonedBones, 31.1.2000
00026 [ToDo:]
00027 [Comments:]
00028 Changes:
00029 -------------------------------------------------------------------*/
00030 
00031 Buffer::Buffer ( int cS) {
00032     checkSleep = cS;
00033 };
00034 
00035 /*...................................................................
00036 Description: Destructor
00037 Args: <none>
00038 Returns: <none>
00039 Created: StonedBones, 31.1.2000
00040 [ToDo:]
00041 [Comments:]
00042 Changes:
00043 -------------------------------------------------------------------*/
00044 
00045 Buffer::~Buffer () {
00046     while (!intBuffer.empty ()) intBuffer.pop ();
00047 };
00048 
00049 /*...................................................................
00050 Description: Insert packet in packet-buffer
00051 Args: packet* pac: packet to insert
00052 Returns: <none>
00053 Created: StonedBones, 31.1.2000
00054 [ToDo:]
00055 [Comments:]
00056 Changes:
00057     Made the thing threadsafe, xandi, 270300
00058 -------------------------------------------------------------------*/
00059 
00060 void Buffer::write (packet* pak)
00061     {
00062     pthread_mutex_lock ( &buf_lock );
00063 
00064     intBuffer.push (pak);
00065 
00066     pthread_mutex_unlock ( &buf_lock );
00067     };
00068 
00069 /*...................................................................
00070 Description: Reads last packet and deletes it from stack
00071 Args: <none>
00072 Returns: packet*
00073 Created: StonedBones, 31.1.2000
00074 [ToDo:]
00075 - free memory ?
00076 [Comments:]
00077 Changes:
00078 -------------------------------------------------------------------*/
00079 
00080 packet* Buffer::read () {
00081     packet* tmp;
00082 
00083     pthread_mutex_lock ( &buf_lock );
00084 
00085     if ( intBuffer.empty () )
00086         {
00087         tmp = 0;
00088         }
00089     else
00090         {
00091         tmp = intBuffer.front ();
00092         intBuffer.pop ();
00093         }
00094 
00095     pthread_mutex_unlock ( &buf_lock );
00096 
00097     return tmp;
00098 };
00099 
00100 
00101 /*...................................................................
00102 Description: checks if buffer is empty
00103 Args: <none>
00104 Returns: bool
00105 Created: StonedBones, 31.1.2000
00106 [ToDo:]
00107 [Comments:]
00108 Changes:
00109 -------------------------------------------------------------------*/
00110 
00111 bool Buffer::isEmpty ()
00112     {
00113     if (intBuffer.empty ())
00114         {
00115         usleep ( checkSleep );
00116         return true;
00117         }
00118     else
00119         {
00120         return false;
00121         };
00122     };

Generated at Sat May 13 13:50:17 2000 for 3Dsia by doxygen 1.1.2 written by Dimitri van Heesch, © 1997-2000