|
UniSet
2.6.0
|
00001 /* 00002 * Copyright (c) 2015 Pavel Vainerman. 00003 * 00004 * This program is free software: you can redistribute it and/or modify 00005 * it under the terms of the GNU Lesser General Public License as 00006 * published by the Free Software Foundation, version 2.1. 00007 * 00008 * This program is distributed in the hope that it will be useful, but 00009 * WITHOUT ANY WARRANTY; without even the implied warranty of 00010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 * Lesser General Lesser Public License for more details. 00012 * 00013 * You should have received a copy of the GNU Lesser General Public License 00014 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00015 */ 00016 // -------------------------------------------------------------------------- 00017 #ifndef MQMutex_H_ 00018 #define MQMutex_H_ 00019 //-------------------------------------------------------------------------- 00020 #include <deque> 00021 #include <list> 00022 #include <memory> 00023 #include "Mutex.h" 00024 #include "MessageType.h" 00025 //-------------------------------------------------------------------------- 00026 namespace uniset 00027 { 00028 //-------------------------------------------------------------------------- 00029 typedef std::shared_ptr<uniset::VoidMessage> VoidMessagePtr; 00030 //-------------------------------------------------------------------------- 00031 00043 class MQMutex 00044 { 00045 public: 00046 MQMutex( size_t qsize = 2000 ); 00047 00049 void push( const VoidMessagePtr& msg ); 00050 00054 VoidMessagePtr top() noexcept; 00055 00056 size_t size(); 00057 bool empty(); 00058 00059 // ----- Настройки ----- 00060 // неявно подразумевается, что всё настраивается до первого использования 00061 // ---------------------- 00062 void setMaxSizeOfMessageQueue( size_t s ) noexcept; 00063 size_t getMaxSizeOfMessageQueue() const noexcept; 00064 00066 enum LostStrategy 00067 { 00068 lostOldData, // default 00069 lostNewData 00070 }; 00071 00072 void setLostStrategy( LostStrategy s ) noexcept; 00073 00074 // ---- Статистика ---- 00076 inline size_t getMaxQueueMessages() const noexcept 00077 { 00078 return stMaxQueueMessages; 00079 } 00080 00082 inline size_t getCountOfLostMessages() const noexcept 00083 { 00084 return stCountOfLostMessages; 00085 } 00086 00087 protected: 00088 00089 private: 00090 00091 //typedef std::queue<VoidMessagePtr> MQueue; 00092 typedef std::deque<VoidMessagePtr> MQueue; 00093 00094 MQueue mqueue; 00095 std::mutex qmutex; 00096 00097 LostStrategy lostStrategy = { lostOldData }; 00098 00100 size_t SizeOfMessageQueue = { 2000 }; 00101 00102 // статистическая информация 00103 size_t stMaxQueueMessages = { 0 }; 00104 size_t stCountOfLostMessages = { 0 }; 00105 }; 00106 // ------------------------------------------------------------------------- 00107 } // end of uniset namespace 00108 //--------------------------------------------------------------------------- 00109 #endif 00110 //---------------------------------------------------------------------------
1.7.6.1