Commit 36d628a1 authored by Chad Austin's avatar Chad Austin Committed by Facebook Github Bot

mark SYNCHRONIZED macros deprecated

Summary: Produce a -Wdeprecated-declarations warning in code that uses the old SYNCHRONIZED macros.

Reviewed By: yfeldblum

Differential Revision: D19567088

fbshipit-source-id: b0637c06cbd125d09e1b39eec1e82a71ddca2324
parent b4e3be33
...@@ -1774,6 +1774,11 @@ void swap(Synchronized<T, M>& lhs, Synchronized<T, M>& rhs) { ...@@ -1774,6 +1774,11 @@ void swap(Synchronized<T, M>& lhs, Synchronized<T, M>& rhs) {
*/ */
#define SYNCHRONIZED_VAR(var) FB_CONCATENATE(SYNCHRONIZED_##var##_, __LINE__) #define SYNCHRONIZED_VAR(var) FB_CONCATENATE(SYNCHRONIZED_##var##_, __LINE__)
namespace detail {
struct [[deprecated(
"use explicit lock(), wlock(), or rlock() instead")]] SYNCHRONIZED_macro_is_deprecated{};
}
/** /**
* NOTE: This API is deprecated. Use lock(), wlock(), rlock() or the withLock * NOTE: This API is deprecated. Use lock(), wlock(), rlock() or the withLock
* functions instead. In the future it will be marked with a deprecation * functions instead. In the future it will be marked with a deprecation
...@@ -1805,6 +1810,7 @@ void swap(Synchronized<T, M>& lhs, Synchronized<T, M>& rhs) { ...@@ -1805,6 +1810,7 @@ void swap(Synchronized<T, M>& lhs, Synchronized<T, M>& rhs) {
FOLLY_MSVC_DISABLE_WARNING(4459) /* declaration hides global */ \ FOLLY_MSVC_DISABLE_WARNING(4459) /* declaration hides global */ \
FOLLY_GCC_DISABLE_NEW_SHADOW_WARNINGS \ FOLLY_GCC_DISABLE_NEW_SHADOW_WARNINGS \
if (bool SYNCHRONIZED_VAR(state) = false) { \ if (bool SYNCHRONIZED_VAR(state) = false) { \
::folly::detail::SYNCHRONIZED_macro_is_deprecated{}; \
} else \ } else \
for (auto SYNCHRONIZED_VAR(lockedPtr) = \ for (auto SYNCHRONIZED_VAR(lockedPtr) = \
(FB_VA_GLUE(FB_ARG_2_OR_1, (__VA_ARGS__))).contextualLock(); \ (FB_VA_GLUE(FB_ARG_2_OR_1, (__VA_ARGS__))).contextualLock(); \
...@@ -1823,6 +1829,7 @@ void swap(Synchronized<T, M>& lhs, Synchronized<T, M>& rhs) { ...@@ -1823,6 +1829,7 @@ void swap(Synchronized<T, M>& lhs, Synchronized<T, M>& rhs) {
*/ */
#define TIMED_SYNCHRONIZED(timeout, ...) \ #define TIMED_SYNCHRONIZED(timeout, ...) \
if (bool SYNCHRONIZED_VAR(state) = false) { \ if (bool SYNCHRONIZED_VAR(state) = false) { \
::folly::detail::SYNCHRONIZED_macro_is_deprecated{}; \
} else \ } else \
for (auto SYNCHRONIZED_VAR(lockedPtr) = \ for (auto SYNCHRONIZED_VAR(lockedPtr) = \
(FB_VA_GLUE(FB_ARG_2_OR_1, (__VA_ARGS__))).timedAcquire(timeout); \ (FB_VA_GLUE(FB_ARG_2_OR_1, (__VA_ARGS__))).timedAcquire(timeout); \
...@@ -1871,6 +1878,7 @@ void swap(Synchronized<T, M>& lhs, Synchronized<T, M>& rhs) { ...@@ -1871,6 +1878,7 @@ void swap(Synchronized<T, M>& lhs, Synchronized<T, M>& rhs) {
*/ */
#define SYNCHRONIZED_DUAL(n1, e1, n2, e2) \ #define SYNCHRONIZED_DUAL(n1, e1, n2, e2) \
if (bool SYNCHRONIZED_VAR(state) = false) { \ if (bool SYNCHRONIZED_VAR(state) = false) { \
::folly::detail::SYNCHRONIZED_macro_is_deprecated{}; \
} else \ } else \
for (auto SYNCHRONIZED_VAR(ptrs) = acquireLockedPair(e1, e2); \ for (auto SYNCHRONIZED_VAR(ptrs) = acquireLockedPair(e1, e2); \
!SYNCHRONIZED_VAR(state); \ !SYNCHRONIZED_VAR(state); \
......
...@@ -28,6 +28,8 @@ ...@@ -28,6 +28,8 @@
#include <folly/synchronization/RWSpinLock.h> #include <folly/synchronization/RWSpinLock.h>
#include <folly/test/SynchronizedTestLib.h> #include <folly/test/SynchronizedTestLib.h>
FOLLY_GNU_DISABLE_WARNING("-Wdeprecated-declarations")
using namespace folly::sync_tests; using namespace folly::sync_tests;
namespace folly { namespace folly {
......
...@@ -458,7 +458,7 @@ testUnlock() { ...@@ -458,7 +458,7 @@ testUnlock() {
// Testing the deprecated SYNCHRONIZED and SYNCHRONIZED_CONST APIs // Testing the deprecated SYNCHRONIZED and SYNCHRONIZED_CONST APIs
template <class Mutex> template <class Mutex>
void testDeprecated() { [[deprecated]] void testDeprecated() {
folly::Synchronized<std::vector<int>, Mutex> obj; folly::Synchronized<std::vector<int>, Mutex> obj;
obj.contextualLock()->resize(1000); obj.contextualLock()->resize(1000);
...@@ -585,7 +585,7 @@ void testAcquireLockedWithConst() { ...@@ -585,7 +585,7 @@ void testAcquireLockedWithConst() {
// Testing the deprecated SYNCHRONIZED_DUAL API // Testing the deprecated SYNCHRONIZED_DUAL API
template <class Mutex> template <class Mutex>
void testDualLocking() { [[deprecated]] void testDualLocking() {
folly::Synchronized<std::vector<int>, Mutex> v; folly::Synchronized<std::vector<int>, Mutex> v;
folly::Synchronized<std::map<int, int>, Mutex> m; folly::Synchronized<std::map<int, int>, Mutex> m;
...@@ -618,7 +618,7 @@ void testDualLocking() { ...@@ -618,7 +618,7 @@ void testDualLocking() {
// Testing the deprecated SYNCHRONIZED_DUAL API // Testing the deprecated SYNCHRONIZED_DUAL API
template <class Mutex> template <class Mutex>
void testDualLockingWithConst() { [[deprecated]] void testDualLockingWithConst() {
folly::Synchronized<std::vector<int>, Mutex> v; folly::Synchronized<std::vector<int>, Mutex> v;
folly::Synchronized<std::map<int, int>, Mutex> m; folly::Synchronized<std::map<int, int>, Mutex> m;
...@@ -762,7 +762,7 @@ void testTimedShared() { ...@@ -762,7 +762,7 @@ void testTimedShared() {
// Testing the deprecated TIMED_SYNCHRONIZED API // Testing the deprecated TIMED_SYNCHRONIZED API
template <class Mutex> template <class Mutex>
void testTimedSynchronized() { [[deprecated]] void testTimedSynchronized() {
folly::Synchronized<std::vector<int>, Mutex> v; folly::Synchronized<std::vector<int>, Mutex> v;
folly::Synchronized<uint64_t, Mutex> numTimeouts{0}; folly::Synchronized<uint64_t, Mutex> numTimeouts{0};
...@@ -809,7 +809,7 @@ void testTimedSynchronized() { ...@@ -809,7 +809,7 @@ void testTimedSynchronized() {
// Testing the deprecated TIMED_SYNCHRONIZED_CONST API // Testing the deprecated TIMED_SYNCHRONIZED_CONST API
template <class Mutex> template <class Mutex>
void testTimedSynchronizedWithConst() { [[deprecated]] void testTimedSynchronizedWithConst() {
folly::Synchronized<std::vector<int>, Mutex> v; folly::Synchronized<std::vector<int>, Mutex> v;
folly::Synchronized<uint64_t, Mutex> numTimeouts{0}; folly::Synchronized<uint64_t, Mutex> numTimeouts{0};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment