X-Git-Url: http://xvm.mit.edu/gitweb/invirt/third/libt4.git/blobdiff_plain/869c0cc91d8f6b2bb80026616372d16450b64d9f..refs/heads/iannucci:/lock_tester.cc diff --git a/lock_tester.cc b/lock_tester.cc index a546e09..63c0722 100644 --- a/lock_tester.cc +++ b/lock_tester.cc @@ -2,26 +2,26 @@ // Lock server tester // -#include "lock_client.h" +#include "include/lock_client.h" #include #include +using namespace std::chrono; + // 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 +31,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; @@ -67,7 +67,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(100ms); LOG_NONMEMBER << "test2: client " << i << " release"; check_release(a); lc[i]->release(a); @@ -113,19 +113,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]);