00001 /* 00002 * Copyright (C) 2009, Edmundo Albuquerque de Souza e Silva. 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 * Thanks: Jose Renato Santos 00017 * 00018 */ 00019 00020 /////////////////////////////////////////////////////////////////// 00021 // RioQueue.h: singely linked fifo queue primitives for pthreads 00022 /////////////////////////////////////////////////////////////////// 00023 00024 #ifndef __RIOQUEUE_H_ 00025 #define __RIOQUEUE_H_ 00026 00027 #ifdef WINDOWS 00028 // Windows implementation 00029 #else 00030 // Linux implementation 00031 #include <pthread.h> 00032 #endif 00033 00034 /* queue element structure */ 00035 00036 struct RioQueueEle 00037 { 00038 RioQueueEle *linkf; 00039 }; 00040 00041 ///////////////////////////////////////////////////////////////////////////// 00042 00043 class RioQueue 00044 { 00045 // don't allow copying a RioQueue class object... 00046 private: 00047 RioQueue( const RioQueue &x ); /* not implemented */ 00048 RioQueue &operator=( const RioQueue &x ); /* not implemented */ 00049 00050 public: 00051 pthread_mutex_t m_mutex; 00052 pthread_cond_t m_cond; 00053 int m_waitflag; 00054 int m_waitcnt; 00055 int m_getcnt; 00056 RioQueueEle *m_top; 00057 RioQueueEle *m_bot; 00058 RioQueueEle *m_sync; 00059 00060 RioQueue(); 00061 ~RioQueue(); 00062 void Put( RioQueueEle *ep ); /* add element to queue */ 00063 RioQueueEle *Get(); /* get top element */ 00064 // Nova funcao para remover um elemento da fila sem bloquear. Se nao 00065 // existir um elemento, a funcao retorna NULL. Esta funcao atualmente 00066 // e usada pela classe EventQueue do servidor para limpar toda a fila 00067 // com os eventos. 00068 RioQueueEle *Remove(); /* remove top element */ 00069 }; 00070 #endif //_RIOQUEUE_H__