Rewrote threaded log code to be more idiomatic.
[invirt/third/libt4.git] / lock_tester.cc
index 5e615ca..e9ec0a8 100644 (file)
@@ -26,7 +26,7 @@ static void check_grant(lock_protocol::lockid_t lid) {
     lock ml(count_mutex);
     int x = lid[0] & 0x0f;
     if (ct[x] != 0) {
-        LOG_NONMEMBER("error: server granted " << lid << " twice");
+        LOG_NONMEMBER << "error: server granted " << lid << " twice";
         exit(1);
     }
     ct[x] += 1;
@@ -36,14 +36,14 @@ static void check_release(lock_protocol::lockid_t lid) {
     lock ml(count_mutex);
     int x = lid[0] & 0x0f;
     if (ct[x] != 1) {
-        LOG_NONMEMBER("error: client released un-held lock " << lid);
+        LOG_NONMEMBER << "error: client released un-held lock " << lid;
         exit(1);
     }
     ct[x] -= 1;
 }
 
 static void test1(void) {
-    LOG_NONMEMBER("acquire a release a acquire a release a");
+    LOG_NONMEMBER << "acquire a release a acquire a release a";
     lc[0]->acquire(a);
     check_grant(a);
     lc[0]->release(a);
@@ -53,7 +53,7 @@ static void test1(void) {
     lc[0]->release(a);
     check_release(a);
 
-    LOG_NONMEMBER("acquire a acquire b release b release a");
+    LOG_NONMEMBER << "acquire a acquire b release b release a";
     lc[0]->acquire(a);
     check_grant(a);
     lc[0]->acquire(b);
@@ -65,46 +65,46 @@ static void test1(void) {
 }
 
 static void test2(int i) {
-    LOG_NONMEMBER("test2: client " << i << " acquire a release a");
+    LOG_NONMEMBER << "test2: client " << i << " acquire a release a";
     lc[i]->acquire(a);
-    LOG_NONMEMBER("test2: client " << i << " acquire done");
+    LOG_NONMEMBER << "test2: client " << i << " acquire done";
     check_grant(a);
     usleep(100000);
-    LOG_NONMEMBER("test2: client " << i << " release");
+    LOG_NONMEMBER << "test2: client " << i << " release";
     check_release(a);
     lc[i]->release(a);
-    LOG_NONMEMBER("test2: client " << i << " release done");
+    LOG_NONMEMBER << "test2: client " << i << " release done";
 }
 
 static void test3(int i) {
-    LOG_NONMEMBER("test3: client " << i << " acquire a release a concurrent");
+    LOG_NONMEMBER << "test3: client " << i << " acquire a release a concurrent";
     for (int j = 0; j < 10; j++) {
         lc[i]->acquire(a);
         check_grant(a);
-        LOG_NONMEMBER("test3: client " << i << " got lock");
+        LOG_NONMEMBER << "test3: client " << i << " got lock";
         check_release(a);
         lc[i]->release(a);
     }
 }
 
 static void test4(int i) {
-    LOG_NONMEMBER("test4: thread " << i << " acquire a release a concurrent; same clnt");
+    LOG_NONMEMBER << "test4: thread " << i << " acquire a release a concurrent; same clnt";
     for (int j = 0; j < 10; j++) {
         lc[0]->acquire(a);
         check_grant(a);
-        LOG_NONMEMBER("test4: thread " << i << " on client 0 got lock");
+        LOG_NONMEMBER << "test4: thread " << i << " on client 0 got lock";
         check_release(a);
         lc[0]->release(a);
     }
 }
 
 static void test5(int i) {
-    LOG_NONMEMBER("test5: client " << i << " acquire a release a concurrent; same and diff clnt");
+    LOG_NONMEMBER << "test5: client " << i << " acquire a release a concurrent; same and diff clnt";
     for (int j = 0; j < 10; j++) {
         if (i < 5)  lc[0]->acquire(a);
         else  lc[1]->acquire(a);
         check_grant(a);
-        LOG_NONMEMBER("test5: client " << i << " got lock");
+        LOG_NONMEMBER << "test5: client " << i << " got lock";
         check_release(a);
         if (i < 5) lc[0]->release(a);
         else lc[1]->release(a);
@@ -122,7 +122,7 @@ main(int argc, char *argv[])
     srandom((uint32_t)getpid());
 
     if (argc < 2) {
-        LOG_NONMEMBER("Usage: " << argv[0] << " [host:]port [test]");
+        LOG_NONMEMBER << "Usage: " << argv[0] << " [host:]port [test]";
         exit(1);
     }
 
@@ -131,12 +131,12 @@ main(int argc, char *argv[])
     if (argc > 2) {
         test = atoi(argv[2]);
         if (test < 1 || test > 5) {
-            LOG_NONMEMBER("Test number must be between 1 and 5");
+            LOG_NONMEMBER << "Test number must be between 1 and 5";
             exit(1);
         }
     }
 
-    LOG_NONMEMBER("cache lock client");
+    LOG_NONMEMBER << "cache lock client";
     for (int i = 0; i < nt; i++) lc[i] = new lock_client(dst);
 
     if (!test || test == 1) {
@@ -152,7 +152,7 @@ main(int argc, char *argv[])
     }
 
     if (!test || test == 3) {
-        LOG_NONMEMBER("test 3");
+        LOG_NONMEMBER << "test 3";
 
         for (int i = 0; i < nt; i++)
             th[i] = thread(test3, i);
@@ -161,7 +161,7 @@ main(int argc, char *argv[])
     }
 
     if (!test || test == 4) {
-        LOG_NONMEMBER("test 4");
+        LOG_NONMEMBER << "test 4";
 
         for (int i = 0; i < 2; i++)
             th[i] = thread(test4, i);
@@ -170,7 +170,7 @@ main(int argc, char *argv[])
     }
 
     if (!test || test == 5) {
-        LOG_NONMEMBER("test 5");
+        LOG_NONMEMBER << "test 5";
 
         for (int i = 0; i < nt; i++)
             th[i] = thread(test5, i);
@@ -178,6 +178,6 @@ main(int argc, char *argv[])
             th[i].join();
     }
 
-    LOG_NONMEMBER(argv[0] << ": passed all tests successfully");
+    LOG_NONMEMBER << argv[0] << ": passed all tests successfully";
 
 }