root/uniquepid.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


   1 /****************************************************************************
   2  *   Copyright (C) 2006-2008 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 DMTCP.                                             *
   6  *                                                                          *
   7  *  DMTCP 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 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 #pragma once
  23 #ifndef UNIQUEPID_H
  24 #define UNIQUEPID_H
  25 
  26 #include <sys/types.h>
  27 #include "dmtcp.h"
  28 #include "../jalib/jserialize.h"
  29 
  30 
  31 namespace dmtcp
  32 {
  33   struct UniquePid : private DmtcpUniqueProcessId
  34   {
  35   public:
  36     static UniquePid& ParentProcess();
  37     static UniquePid& ThisProcess(bool disableJTrace = false);
  38     UniquePid();
  39 
  40     UniquePid ( const uint64_t& host, const pid_t& pd, const uint64_t& tm,
  41                 const int& gen = 0 ) {
  42       _hostid = host;
  43       _pid = pd;
  44       _time = tm;
  45       _computation_generation = gen;
  46     }
  47 
  48     UniquePid(DmtcpUniqueProcessId id) {
  49       _hostid = id._hostid;
  50       _pid = id._pid;
  51       _time = id._time;
  52       _computation_generation = id._computation_generation;
  53     }
  54 
  55     uint64_t hostid() const { return _hostid; }
  56     pid_t pid() const { return _pid; }
  57     int computationGeneration() const { return _computation_generation; }
  58     uint64_t time() const { return _time; }
  59     DmtcpUniqueProcessId upid() const {
  60       DmtcpUniqueProcessId up;
  61       up._hostid = _hostid;
  62       up._pid = _pid;
  63       up._time = _time;
  64       up._computation_generation = _computation_generation;
  65       return up;
  66     }
  67 
  68     void incrementGeneration();
  69 
  70     static void serialize( jalib::JBinarySerializer& o );
  71 
  72     bool operator< ( const UniquePid& that ) const;
  73     bool operator== ( const UniquePid& that ) const;
  74     bool operator!= ( const UniquePid& that ) const { return ! operator== ( that ); }
  75 
  76     static void restart();
  77     static void resetOnFork ( const UniquePid& newId );
  78 
  79     string toString() const;
  80 
  81     bool isNull() const;
  82   };
  83 
  84   ostream& operator << ( ostream& o,const UniquePid& id );
  85   ostream& operator << ( ostream& o,const DmtcpUniqueProcessId& id );
  86   bool operator==(const DmtcpUniqueProcessId& a, const DmtcpUniqueProcessId& b);
  87   bool operator!=(const DmtcpUniqueProcessId& a, const DmtcpUniqueProcessId& b);
  88 }
  89 
  90 #endif

/* [<][>][^][v][top][bottom][index][help] */