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