S3FC project page | S3FC home page |
00001 /* 00002 * Stone Three Foundation Class (s3fc) provides a number of utility classes. 00003 * Copyright (C) 2001 by Stone Three Signal Processing (Pty) Ltd. 00004 * 00005 * Authored by Stone Three Signal Processing (Pty) Ltd. 00006 * 00007 * This library is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * This library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with this library; if not, write to the Free Software 00019 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 * 00021 * Please see the file 'COPYING' in the source root directory. 00022 */ 00023 00035 #ifndef S3_FIFO_BASE_H 00036 #define S3_FIFO_BASE_H 00037 00038 #include <list> 00039 #include <s3fc/s3_semaphore.h> 00040 #include <s3fc/s3_mutex.h> 00041 00046 class s3_subscribable_fifo 00047 { 00048 typedef std::list<s3_semaphore*>::const_iterator T_ConstIterator; 00049 typedef std::list<s3_semaphore*>::const_iterator T_Iterator; 00050 protected: 00054 std::list<s3_semaphore*> producers; 00058 std::list<s3_semaphore*> consumers; 00062 s3_mutex notification_lock; 00063 public: 00074 void subscribe_producer(const s3_semaphore& sem); 00082 void unsubscribe_producer(const s3_semaphore& sem); 00087 bool is_subscribed_producer(const s3_semaphore& sem); 00098 void subscribe_consumer(const s3_semaphore& sem); 00106 void unsubscribe_consumer(const s3_semaphore& sem); 00111 bool is_subscribed_consumer(const s3_semaphore& sem); 00116 void notify_producers() const; 00121 void notify_consumers() const; 00122 }; 00123 00134 template<typename T> 00135 class s3_fifo_base : public s3_subscribable_fifo 00136 { 00137 public: 00138 00139 // Convenience typedef 00140 typedef T s3_queue_data_t; 00141 00145 virtual ~s3_fifo_base() 00146 { 00147 } 00152 virtual void push(const T& t) = 0; 00157 virtual T pop() = 0; 00161 virtual bool empty() const = 0; 00165 virtual bool full() const = 0; 00170 virtual unsigned int size() const = 0; 00171 00172 protected: 00183 static void unlock_mutex(void* p) 00184 { 00185 //cerr << "s3_fifo_base<T>::unlock_mutex(void* p)" << endl << flush; 00186 pthread_mutex_t* mp = reinterpret_cast<pthread_mutex_t*>(p); 00187 pthread_mutex_unlock(mp); 00188 } 00189 }; 00190 00191 #endif 00192
Send comments to: s3fc@stonethree.com |
|