root/plugin/ipc/connectionidentifier.cpp
/* [<][>][^][v][top][bottom][index][help] */
DEFINITIONS
This source file includes following definitions.
- _nextConnectionId
- serialize
- create
- null
- self
1 /****************************************************************************
2 * Copyright (C) 2006-2013 by Jason Ansel, Kapil Arya, and Gene Cooperman *
3 * jansel@csail.mit.edu, kapil@ccs.neu.edu, gene@ccs.neu.edu *
4 * *
5 * This file is part of the dmtcp/src module of DMTCP (DMTCP:dmtcp/src). *
6 * *
7 * DMTCP:dmtcp/src is free software: you can redistribute it and/or *
8 * modify it under the terms of the GNU Lesser General Public License as *
9 * published by the Free Software Foundation, either version 3 of the *
10 * License, or (at your option) any later version. *
11 * *
12 * DMTCP:dmtcp/src is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU Lesser General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU Lesser General Public *
18 * License along with DMTCP:dmtcp/src. If not, see *
19 * <http://www.gnu.org/licenses/>. *
20 ****************************************************************************/
21
22 #include "connectionidentifier.h"
23 #include "dmtcp.h"
24 #include "../jalib/jassert.h"
25
26 using namespace dmtcp;
27
28 static int _nextConId = CONNECTION_ID_START;
29 static int _nextConnectionId()
30 {
31 //static int id = CONNECTION_ID_START;
32 return _nextConId++;
33 }
34
35 ConnectionIdentifier::ConnectionIdentifier(int id)
36 {
37 _upid = dmtcp_get_uniquepid();
38 _id = id;
39 }
40
41 void ConnectionIdentifier::serialize (jalib::JBinarySerializer& o)
42 {
43 JSERIALIZE_ASSERT_POINT ("ConnectionIdentifier:");
44 o & _nextConId;
45 JASSERT(_nextConId >= CONNECTION_ID_START);
46 }
47
48 ConnectionIdentifier ConnectionIdentifier::create()
49 {
50 return ConnectionIdentifier (_nextConnectionId());
51 }
52 ConnectionIdentifier ConnectionIdentifier::null()
53 {
54 static ConnectionIdentifier n;
55 return n;
56 }
57 // FIXME: This is never used.
58 ConnectionIdentifier ConnectionIdentifier::self()
59 {
60 return ConnectionIdentifier(-1);
61 }
62
63 bool ConnectionIdentifier::operator<(const ConnectionIdentifier& that)
64 const
65 {
66 #define TRY_LEQ(param) \
67 if(_upid.param != that._upid.param) return _upid.param < that._upid.param;
68
69 TRY_LEQ ( _hostid );
70 TRY_LEQ ( _pid );
71 TRY_LEQ ( _time );
72 return _id < that._id;
73 }
74
75 bool ConnectionIdentifier::operator==(const ConnectionIdentifier& that)
76 const
77 {
78 return _upid._hostid == that._upid._hostid &&
79 _upid._pid == that._upid._pid &&
80 _upid._time == that._upid._time &&
81 _upid._computation_generation == that._upid._computation_generation &&
82 _id == that._id;
83 }
84
85 ostream& dmtcp::operator<<(ostream& o, const ConnectionIdentifier& id)
86 {
87 o << std::hex << id.hostid()
88 << '-' << std::dec << id.pid()
89 << '-' << std::hex << id.time()
90 << std::dec << '(' << id.conId() << ')';
91 return o;
92 }