From 1d0d87ab98794fb7c6d10038d42c6e61935ea88e Mon Sep 17 00:00:00 2001 From: "(no author)" <(no author)@41a61cd8-c433-0410-bb1c-e256eeef9e11> Date: Thu, 20 Dec 2007 21:42:55 +0000 Subject: [PATCH] r1423@opsdev009 (orig r75350): dreiss | 2007-12-20 13:42:05 -0800 Thrift: A hack to prevent incorrect usage of Mutex Guards. Reviewed By: boz Test Plan: dreiss@dreiss-vmware:safe_concurrency:thrift/test$ nl -ba guard_test.cc 1 #include "../lib/cpp/src/concurrency/Mutex.h" 2 using facebook::thrift::concurrency::Guard; 3 void test() { 4 facebook::thrift::concurrency::Mutex m; 5 Guard(m); 6 Guard g1(m); 7 8 facebook::thrift::concurrency::ReadWriteMutex rwm; 9 facebook::thrift::concurrency::RWGuard(m); 10 facebook::thrift::concurrency::RWGuard g2(rwm); 11 } dreiss@dreiss-vmware:safe_concurrency:thrift/test$ g++ -c guard_test.cc guard_test.cc: In function ?void test()?: guard_test.cc:5: error: ?incorrect_use_of_Guard? was not declared in this scope guard_test.cc:9: error: ?incorrect_use_of_RWGuard? is not a member of ?facebook::thrift::concurrency? dreiss@dreiss-vmware:safe_concurrency:thrift/test$ Revert Plan: ok git-svn-id: http://svn.facebook.com/svnroot/thrift/trunk@730 41a61cd8-c433-0410-bb1c-e256eeef9e11 --- lib/cpp/src/concurrency/Mutex.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/cpp/src/concurrency/Mutex.h b/lib/cpp/src/concurrency/Mutex.h index 7594339..f3c7cd0 100644 --- a/lib/cpp/src/concurrency/Mutex.h +++ b/lib/cpp/src/concurrency/Mutex.h @@ -83,6 +83,12 @@ class RWGuard { }; +// A little hack to prevent someone from trying to do "Guard(m);" +// Sorry for polluting the global namespace, but I think it's worth it. +#define Guard(m) incorrect_use_of_Guard(m) +#define RWGuard(m) incorrect_use_of_RWGuard(m) + + }}} // facebook::thrift::concurrency #endif // #ifndef _THRIFT_CONCURRENCY_MUTEX_H_ -- 2.11.4.GIT