Line data Source code
1 :
2 : /* Copyright (c) 2007-2012, Stefan Eilemann <eile@equalizergraphics.com>
3 : * 2012, Daniel Nachbaur <danielnachbaur@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 : #include "unbufferedMasterCM.h"
22 :
23 : #include "log.h"
24 : #include "node.h"
25 : #include "object.h"
26 : #include "objectDataIStream.h"
27 : #include "objectDeltaDataOStream.h"
28 : #include "objectInstanceDataOStream.h"
29 :
30 : namespace co
31 : {
32 2 : UnbufferedMasterCM::UnbufferedMasterCM(Object* object)
33 2 : : VersionedMasterCM(object)
34 : {
35 2 : _version = VERSION_FIRST;
36 2 : LBASSERT(object);
37 2 : LBASSERT(object->getLocalNode());
38 2 : }
39 :
40 4 : UnbufferedMasterCM::~UnbufferedMasterCM()
41 : {
42 4 : }
43 :
44 2 : uint128_t UnbufferedMasterCM::commit(const uint32_t)
45 : {
46 : #if 0
47 : LBLOG( LOG_OBJECTS ) << "commit v" << _version << " " << command
48 : << std::endl;
49 : #endif
50 2 : if (!_object->isDirty())
51 0 : return _version;
52 :
53 2 : _maxVersion.waitGE(_version.low() + 1);
54 4 : Mutex mutex(_slaves);
55 2 : if (_slaves->empty())
56 0 : return _version;
57 :
58 4 : ObjectDeltaDataOStream os(this);
59 2 : os.enableCommit(_version + 1, *_slaves);
60 2 : _object->pack(os);
61 2 : os.disable();
62 :
63 2 : if (os.hasSentData())
64 : {
65 2 : ++_version;
66 2 : LBASSERT(_version != VERSION_NONE);
67 : #if 0
68 : LBLOG( LOG_OBJECTS ) << "Committed v" << _version << ", id "
69 : << _object->getID() << std::endl;
70 : #endif
71 : }
72 :
73 2 : return _version;
74 : }
75 63 : }
|