Build on wheezy, and presumably precise
[invirt/third/libt4.git] / lock_smain.cc
1 #include "rpc.h"
2 #include <arpa/inet.h>
3 #include <stdlib.h>
4 #include <stdio.h>
5 #include <unistd.h>
6 #include "lock_server_cache_rsm.h"
7 #include "paxos.h"
8 #include "rsm.h"
9
10 #include "jsl_log.h"
11
12 // Main loop of lock_server
13
14 char tprintf_thread_prefix = 's';
15
16 int
17 main(int argc, char *argv[])
18 {
19   int count = 0;
20
21   setvbuf(stdout, NULL, _IONBF, 0);
22   setvbuf(stderr, NULL, _IONBF, 0);
23
24   srandom(getpid());
25
26   if(argc != 3){
27     fprintf(stderr, "Usage: %s [master:]port [me:]port\n", argv[0]);
28     exit(1);
29   }
30
31   char *count_env = getenv("RPC_COUNT");
32   if(count_env != NULL){
33     count = atoi(count_env);
34   }
35
36   //jsl_set_debug(2);
37   // Comment out the next line to switch between the ordinary lock
38   // server and the RSM.  In Lab 6, we disable the lock server and
39   // implement Paxos.  In Lab 7, we will make the lock server use your
40   // RSM layer.
41 #define RSM
42 #ifdef RSM
43 // You must comment out the next line once you are done with Step One.
44 //#define STEP_ONE 
45 #ifdef STEP_ONE
46   rpcs server(atoi(argv[1]));
47   lock_server_cache_rsm ls;
48   server.reg(lock_protocol::acquire, &ls, &lock_server_cache_rsm::acquire);
49   server.reg(lock_protocol::release, &ls, &lock_server_cache_rsm::release);
50   server.reg(lock_protocol::stat, &ls, &lock_server_cache_rsm::stat);
51 #else
52   rsm rsm(argv[1], argv[2]);
53   lock_server_cache_rsm ls(&rsm);
54   rsm.set_state_transfer((rsm_state_transfer *)&ls);
55   rsm.reg(lock_protocol::acquire, &ls, &lock_server_cache_rsm::acquire);
56   rsm.reg(lock_protocol::release, &ls, &lock_server_cache_rsm::release);
57   rsm.reg(lock_protocol::stat, &ls, &lock_server_cache_rsm::stat);
58 #endif // STEP_ONE
59 #endif // RSM
60
61 #ifndef RSM
62   lock_server_cache ls;
63   rpcs server(atoi(argv[1]), count);
64   server.reg(lock_protocol::stat, &ls, &lock_server_cache::stat);
65   server.reg(lock_protocol::acquire, &ls, &lock_server_cache::acquire);
66   server.reg(lock_protocol::release, &ls, &lock_server_cache::release);
67 #endif
68
69
70   while(1)
71     sleep(1000);
72 }