Equalizer
1.2.1
|
00001 00002 /* Copyright (c) 2006-2011, Stefan Eilemann <eile@equalizergraphics.com> 00003 * 2011, Cedric Stalder <cedric.stalder@gmail.com> 00004 * 00005 * This library is free software; you can redistribute it and/or modify it under 00006 * the terms of the GNU Lesser General Public License version 2.1 as published 00007 * by the Free Software Foundation. 00008 * 00009 * This library is distributed in the hope that it will be useful, but WITHOUT 00010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00011 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00012 * details. 00013 * 00014 * You should have received a copy of the GNU Lesser General Public License 00015 * along with this library; if not, write to the Free Software Foundation, Inc., 00016 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00017 */ 00018 00019 #ifndef CO_BARRIER_H 00020 #define CO_BARRIER_H 00021 00022 #include <co/object.h> // base class 00023 #include <co/types.h> 00024 #include <co/base/monitor.h> // member 00025 00026 #include <map> 00027 00028 namespace co 00029 { 00030 struct BarrierEnterReplyPacket; 00032 class Barrier : public Object 00033 { 00034 public: 00046 CO_API Barrier( NodePtr master, const uint32_t height = 0 ); 00047 00049 CO_API Barrier(); 00050 00052 CO_API virtual ~Barrier(); 00053 00062 void setHeight( const uint32_t height ) { _height = height; } 00063 00065 void increase() { ++_height; } 00066 00068 uint32_t getHeight() const { return _height; } 00070 00080 CO_API void enter( const uint32_t timeout = EQ_TIMEOUT_INDEFINITE ); 00082 00083 protected: 00084 virtual void attach( const base::UUID& id, 00085 const uint32_t instanceID ); 00086 00087 virtual ChangeType getChangeType() const { return DELTA; } 00088 00089 virtual void getInstanceData( DataOStream& os ); 00090 virtual void applyInstanceData( DataIStream& is ); 00091 virtual void pack( DataOStream& os ); 00092 virtual void unpack( DataIStream& is ); 00093 00094 private: 00096 NodeID _masterID; 00097 00099 uint32_t _height; 00100 00102 NodePtr _master; 00103 00104 struct Request 00105 { 00106 Request() 00107 : time( 0 ) 00108 , timeout( EQ_TIMEOUT_INDEFINITE ) 00109 , incarnation( 0 ){} 00110 uint64_t time; 00111 uint32_t timeout; 00112 uint32_t incarnation; 00113 Nodes nodes; 00114 }; 00115 00117 std::map< uint128_t, Request > _enteredNodes; 00118 00120 base::Monitor< uint32_t > _leaveNotify; 00121 00122 void _cleanup( const uint64_t time ); 00123 void _sendNotify( const uint128_t& version, NodePtr node ); 00124 00125 /* The command handlers. */ 00126 bool _cmdEnter( Command& command ); 00127 bool _cmdEnterReply( Command& command ); 00128 00129 EQ_TS_VAR( _thread ); 00130 }; 00131 } 00132 00133 #endif // CO_BARRIER_H 00134