Collage  1.2.1
High-performance C++ library for developing object-oriented distributed applications.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
barrier.h
1 
2 /* Copyright (c) 2006-2014, Stefan Eilemann <eile@equalizergraphics.com>
3  * 2011, Cedric Stalder <cedric.stalder@gmail.com>
4  *
5  * This file is part of Collage <https://github.com/Eyescale/Collage>
6  *
7  * This library is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU Lesser General Public License version 2.1 as published
9  * by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 #ifndef CO_BARRIER_H
22 #define CO_BARRIER_H
23 
24 #include <co/object.h> // base class
25 #include <co/types.h>
26 
27 namespace co
28 {
29 namespace detail { class Barrier; }
30 
38 class Barrier : public Object
39 {
40 public:
65  CO_API Barrier( LocalNodePtr localNode,
66  const uint128_t& masterNodeID,
67  const uint32_t height = 0 );
68 
77  CO_API Barrier( LocalNodePtr localNode, const ObjectVersion& barrier );
78 
80  CO_API virtual ~Barrier();
81 
90  bool isGood() const { return isAttached(); }
91 
93  CO_API void setHeight( const uint32_t height );
94 
96  CO_API void increase();
97 
99  CO_API uint32_t getHeight() const;
101 
113  CO_API bool enter( const uint32_t timeout = LB_TIMEOUT_INDEFINITE );
115 
116 protected:
119  void attach( const uint128_t& id, const uint32_t instanceID ) override;
120  ChangeType getChangeType() const override { return DELTA; }
121 
122  void getInstanceData( DataOStream& os ) override;
123  void applyInstanceData( DataIStream& is ) override;
124  void pack( DataOStream& os ) override;
125  void unpack( DataIStream& is ) override;
127 
128 private:
129  detail::Barrier* const _impl;
130 
131  void _cleanup( const uint64_t time );
132  void _sendNotify( const uint128_t& version, NodePtr node );
133 
134  /* The command handlers. */
135  bool _cmdEnter( ICommand& command );
136  bool _cmdEnterReply( ICommand& command );
137 
138  LB_TS_VAR( _thread );
139 };
140 }
141 
142 #endif // CO_BARRIER_H
A distributed object.
Definition: object.h:45
lunchbox::RefPtr< LocalNode > LocalNodePtr
A reference pointer for LocalNode pointers.
Definition: types.h:91
A helper struct bundling an object identifier and version.
Definition: objectVersion.h:47
void pack(DataOStream &os) override
Serialize the modifications since the last call to commit().
void getInstanceData(DataOStream &os) override
Serialize all instance information of this distributed object.
ChangeType
Object change handling characteristics, see Programming Guide.
Definition: object.h:49
CO_API uint32_t getHeight() const
CO_API bool isAttached() const
CO_API void setHeight(const uint32_t height)
Set the number of participants in the barrier.
lunchbox::RefPtr< Node > NodePtr
A reference pointer for Node pointers.
Definition: types.h:87
A std::ostream-like interface for object serialization.
Definition: dataOStream.h:48
CO_API void increase()
Add one participant to the barrier.
void applyInstanceData(DataIStream &is) override
Deserialize the instance data.
A class managing received commands.
Definition: iCommand.h:43
use pack/unpack delta
Definition: object.h:54
void unpack(DataIStream &is) override
Deserialize a change.
CO_API Barrier(LocalNodePtr localNode, const uint128_t &masterNodeID, const uint32_t height=0)
Construct and register a new distributed barrier.
virtual CO_API ~Barrier()
Destruct the barrier.
A std::istream-like input data stream for binary data.
Definition: dataIStream.h:41
ChangeType getChangeType() const override
Definition: barrier.h:120
A networked, versioned barrier.
Definition: barrier.h:38
CO_API bool enter(const uint32_t timeout=LB_TIMEOUT_INDEFINITE)
Enter the barrier, blocks until the barrier has been reached.
bool isGood() const
Definition: barrier.h:90