All random numbers generated via one PRNG seeded in one place.
[invirt/third/libt4.git] / lock_tester.cc
index a546e09..07961c7 100644 (file)
@@ -8,20 +8,18 @@
 
 // must be >= 2
 const int nt = 6; //XXX: lab1's rpc handlers are blocking. Since rpcs uses a thread pool of 10 threads, we cannot test more than 10 blocking rpc.
-static string dst;
 static lock_client *lc[nt];
-static lock_protocol::lockid_t a = "1";
-static lock_protocol::lockid_t b = "2";
-static lock_protocol::lockid_t c = "3";
+static const char * a = "1";
+static const char * b = "2";
 
 // check_grant() and check_release() check that the lock server
 // doesn't grant the same lock to both clients.
 // it assumes that lock names are distinct in the first byte.
 static int ct[256];
-static std::mutex count_mutex;
+static std::mutex * count_mutex;
 
 static void check_grant(lock_protocol::lockid_t lid) {
-    lock ml(count_mutex);
+    lock ml(*count_mutex);
     int x = lid[0] & 0x0f;
     if (ct[x] != 0) {
         LOG_NONMEMBER << "error: server granted " << lid << " twice";
@@ -31,7 +29,7 @@ static void check_grant(lock_protocol::lockid_t lid) {
 }
 
 static void check_release(lock_protocol::lockid_t lid) {
-    lock ml(count_mutex);
+    lock ml(*count_mutex);
     int x = lid[0] & 0x0f;
     if (ct[x] != 1) {
         LOG_NONMEMBER << "error: client released un-held lock " << lid;
@@ -113,19 +111,20 @@ int
 main(int argc, char *argv[])
 {
     global = new t4_state('c');
+    count_mutex = new std::mutex();
+
     thread th[nt];
     int test = 0;
 
     setvbuf(stdout, NULL, _IONBF, 0);
     setvbuf(stderr, NULL, _IONBF, 0);
-    srandom((uint32_t)getpid());
 
     if (argc < 2) {
         LOG_NONMEMBER << "Usage: " << argv[0] << " [host:]port [test]";
         exit(1);
     }
 
-    dst = argv[1]; 
+    string dst = argv[1]; 
 
     if (argc > 2) {
         test = atoi(argv[2]);