TEMPLATE MAGIC FOR GREAT JUSTICE
[invirt/third/libt4.git] / paxos.cc
index 4434788..b0ec640 100644 (file)
--- a/paxos.cc
+++ b/paxos.cc
@@ -59,7 +59,7 @@ proposer::isrunning()
 
 // check if the servers in l2 contains a majority of servers in l1
 bool
-proposer::majority(const std::vector<std::string> &l1, 
+proposer::majority(const std::vector<std::string> &l1,
                const std::vector<std::string> &l2)
 {
   unsigned n = 0;
@@ -71,9 +71,9 @@ proposer::majority(const std::vector<std::string> &l1,
   return n >= (l1.size() >> 1) + 1;
 }
 
-proposer::proposer(class paxos_change *_cfg, class acceptor *_acceptor, 
+proposer::proposer(class paxos_change *_cfg, class acceptor *_acceptor,
                   std::string _me)
-  : cfg(_cfg), acc (_acceptor), me (_me), break1 (false), break2 (false), 
+  : cfg(_cfg), acc (_acceptor), me (_me), break1 (false), break2 (false),
     stable (true)
 {
   my_n.n = 0;
@@ -145,7 +145,7 @@ proposer::run(int instance, std::vector<std::string> cur_nodes, std::string newv
 // otherwise fill in accepts with set of nodes that accepted,
 // set v to the v_a with the highest n_a, and return true.
 bool
-proposer::prepare(unsigned instance, std::vector<std::string> &accepts, 
+proposer::prepare(unsigned instance, std::vector<std::string> &accepts,
          std::vector<std::string> nodes,
          std::string &v)
 {
@@ -199,7 +199,7 @@ proposer::accept(unsigned instance, std::vector<std::string> &accepts,
 }
 
 void
-proposer::decide(unsigned instance, std::vector<std::string> accepts, 
+proposer::decide(unsigned instance, std::vector<std::string> accepts,
              std::string v)
 {
     struct paxos_protocol::decidearg arg = { instance, v };
@@ -213,7 +213,7 @@ proposer::decide(unsigned instance, std::vector<std::string> accepts,
     }
 }
 
-acceptor::acceptor(class paxos_change *_cfg, bool _first, std::string _me, 
+acceptor::acceptor(class paxos_change *_cfg, bool _first, std::string _me,
             std::string _value)
   : cfg(_cfg), me (_me), instance_h(0)
 {
@@ -232,14 +232,13 @@ acceptor::acceptor(class paxos_change *_cfg, bool _first, std::string _me,
   }
 
   pxs = new rpcs(atoi(_me.c_str()));
-  pxs->reg(paxos_protocol::preparereq, this, &acceptor::preparereq);
-  pxs->reg(paxos_protocol::acceptreq, this, &acceptor::acceptreq);
-  pxs->reg(paxos_protocol::decidereq, this, &acceptor::decidereq);
+  pxs->reg(paxos_protocol::preparereq, &acceptor::preparereq, this);
+  pxs->reg(paxos_protocol::acceptreq, &acceptor::acceptreq, this);
+  pxs->reg(paxos_protocol::decidereq, &acceptor::decidereq, this);
 }
 
 paxos_protocol::status
-acceptor::preparereq(std::string src, paxos_protocol::preparearg a,
-    paxos_protocol::prepareres &r)
+acceptor::preparereq(paxos_protocol::prepareres &r, std::string src, paxos_protocol::preparearg a)
 {
     lock ml(pxs_mutex);
     r.oldinstance = false;
@@ -260,7 +259,7 @@ acceptor::preparereq(std::string src, paxos_protocol::preparearg a,
 }
 
 paxos_protocol::status
-acceptor::acceptreq(std::string src, paxos_protocol::acceptarg a, bool &r)
+acceptor::acceptreq(bool &r, std::string src, paxos_protocol::acceptarg a)
 {
     lock ml(pxs_mutex);
     r = false;
@@ -275,10 +274,10 @@ acceptor::acceptreq(std::string src, paxos_protocol::acceptarg a, bool &r)
 
 // the src argument is only for debug purpose
     paxos_protocol::status
-acceptor::decidereq(std::string src, paxos_protocol::decidearg a, int &r)
+acceptor::decidereq(int &r, std::string src, paxos_protocol::decidearg a)
 {
     lock ml(pxs_mutex);
-    tprintf("decidereq for accepted instance %d (my instance %d) v=%s\n", 
+    tprintf("decidereq for accepted instance %d (my instance %d) v=%s\n",
             a.instance, instance_h, v_a.c_str());
     if (a.instance == instance_h + 1) {
         VERIFY(v_a == a.v);