00001 /* 00002 * Copyright (C) 2006, Jose Renato Santos. 00003 * 00004 * This file may be distributed under the terms of the Q Public License 00005 * as defined by Trolltech AS of Norway and appearing in the file 00006 * LICENSE.QPL included in the packaging of this file. 00007 * 00008 * THIS FILE IS PROVIDED AS IS WITH NO WARRANTY OF ANY KIND, INCLUDING 00009 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00010 * PURPOSE. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, 00011 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING 00012 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, 00013 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION 00014 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 00015 * 00016 */ 00017 00018 /////////////////////////////////////////////////////////////////////////////// 00019 // rioqueue.h -- singely linked fifo queue primitives for pthreads 00020 /////////////////////////////////////////////////////////////////////////////// 00021 00022 // Get() and Test() only called from a single thread, 00023 // Put can be called from any thread. 00024 00025 // RioQueueEle is just a single forward link, 00026 // any real use would have more structure after this... 00027 00028 // (Could write a cover class for type safety for a specific element 00029 // (type... 00030 00031 00032 #ifndef __RIOQUEUE_H_ 00033 #define __RIOQUEUE_H_ 00034 00035 #include <vsicondition.h> 00036 00037 // queue element structure 00038 00039 struct RioQueueEle 00040 { 00041 RioQueueEle *linkf; 00042 }; 00043 00044 /////////////////////////////////////////////////////////////////////////////// 00045 00046 class RioQueue 00047 { 00048 public: 00049 RioQueue(); 00050 ~RioQueue(); 00051 void Put(RioQueueEle *ep); // add element to end of queue 00052 00053 RioQueueEle *Get(); // Wait for element available on 00054 // queue and get first one when 00055 // available 00056 void Signal(); // If there is a thread waiting 00057 // for an element unblock thread 00058 // making Get() return NULL 00059 // ### how do you shut this down (?) [use Test?] 00060 bool Test(); // any elements available? 00061 00062 private: 00063 CvsiCondition m_cond; 00064 int m_waitflag; 00065 int m_Signal; 00066 RioQueueEle *m_first, *m_last, *m_sync; 00067 }; 00068 00069 #endif //__RIOQUEUE_H_ 00070