Clean-ups
[invirt/third/libt4.git] / lock_tester.cc
index 58e691f..fbdeeb4 100644 (file)
@@ -5,26 +5,21 @@
 #include "lock_client.h"
 #include <arpa/inet.h>
 #include <unistd.h>
-#include "handle.h"
-
-char log_thread_prefix = 'c';
 
 // 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";
@@ -34,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;
@@ -70,7 +65,7 @@ static void test2(int i) {
     lc[i]->acquire(a);
     LOG_NONMEMBER << "test2: client " << i << " acquire done";
     check_grant(a);
-    usleep(100000);
+    std::this_thread::sleep_for(milliseconds(100));
     LOG_NONMEMBER << "test2: client " << i << " release";
     check_release(a);
     lc[i]->release(a);
@@ -115,19 +110,21 @@ static void test5(int i) {
 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]);
@@ -183,9 +180,4 @@ main(int argc, char *argv[])
 
     for (int i = 0; i < nt; i++)
         delete lc[i];
-
-    handle::shutdown();
-    poll_mgr::shared_mgr.shutdown();
-
-    LOG_NONMEMBER << argv[0] << ": clean-up complete";
 }