00001 /*MT* 00002 00003 MediaTomb - http://www.mediatomb.cc/ 00004 00005 reentrant_array.h - this file is part of MediaTomb. 00006 00007 Copyright (C) 2005 Gena Batyan <bgeradz@mediatomb.cc>, 00008 Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc> 00009 00010 Copyright (C) 2006-2010 Gena Batyan <bgeradz@mediatomb.cc>, 00011 Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>, 00012 Leonhard Wimmer <leo@mediatomb.cc> 00013 00014 MediaTomb is free software; you can redistribute it and/or modify 00015 it under the terms of the GNU General Public License version 2 00016 as published by the Free Software Foundation. 00017 00018 MediaTomb is distributed in the hope that it will be useful, 00019 but WITHOUT ANY WARRANTY; without even the implied warranty of 00020 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00021 GNU General Public License for more details. 00022 00023 You should have received a copy of the GNU General Public License 00024 version 2 along with MediaTomb; if not, write to the Free Software 00025 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. 00026 00027 $Id: reentrant_array.h 2081 2010-03-23 20:18:00Z lww $ 00028 */ 00029 00032 #ifndef __REENTRANT_ARRAY_H__ 00033 #define __REENTRANT_ARRAY_H__ 00034 00035 #include "zmmf/zmmf.h" 00036 #include "sync.h" 00037 00039 template <class T> 00040 class ReentrantArray : public zmm::Array<T> 00041 { 00042 public: 00043 ReentrantArray() : zmm::Array<T>() 00044 { 00045 mutex = zmm::Ref<Mutex>(new Mutex()); 00046 } 00047 ReentrantArray(int capacity) : zmm::Array<T>(capacity) 00048 { 00049 mutex = zmm::Ref<Mutex>(new Mutex()); 00050 } 00051 inline void append(zmm::Ref<T> el) 00052 { 00053 mutex->lock(); 00054 zmm::Array<T>::append(el); 00055 mutex->unlock(); 00056 } 00057 inline void set(zmm::Ref<T> el, int index) 00058 { 00059 mutex->lock(); 00060 zmm::Array<T>::set(el, index); 00061 mutex->unlock(); 00062 } 00063 inline zmm::Ref<T> get(int index) 00064 { 00065 zmm::Ref<T> ret; 00066 mutex->lock(); 00067 ret = zmm::Array<T>::get(index); 00068 mutex->unlock(); 00069 return ret; 00070 } 00071 inline void remove(int index, int count=1) 00072 { 00073 mutex->lock(); 00074 zmm::Array<T>::set(index, count); 00075 mutex->unlock(); 00076 } 00077 inline void removeUnordered(int index) 00078 { 00079 mutex->lock(); 00080 zmm::Array<T>::removeUnordered(index); 00081 mutex->unlock(); 00082 } 00083 inline void insert(int index, zmm::Ref<T> el) 00084 { 00085 mutex->lock(); 00086 zmm::Array<T>::insert(index, el); 00087 mutex->unlock(); 00088 } 00089 inline int size() 00090 { 00091 int size; 00092 mutex->lock(); 00093 size = zmm::Array<T>::size(); 00094 mutex->unlock(); 00095 return size; 00096 } 00097 inline void clear() 00098 { 00099 mutex->lock(); 00100 zmm::Array<T>::clear(); 00101 mutex->unlock(); 00102 } 00103 inline void optimize() 00104 { 00105 mutex->lock(); 00106 zmm::Array<T>::optimize(); 00107 mutex->unlock(); 00108 } 00109 protected: 00110 zmm::Ref<Mutex> mutex; 00111 }; 00112 00113 00114 #endif // __REENTRANT_ARRAY_H__
1.6.1