[THRIFT-5510] On Windows NOMINMAX and WIN32_LEAN_AND_MEAN are unset even if set before

Only define and undefine NOMINMAX and WIN32_LEAN_AND_MEAN if they have not been set before.
diff --git a/lib/cpp/src/thrift/windows/Sync.h b/lib/cpp/src/thrift/windows/Sync.h
index f5b8a05..a5b2ac5 100644
--- a/lib/cpp/src/thrift/windows/Sync.h
+++ b/lib/cpp/src/thrift/windows/Sync.h
@@ -29,11 +29,23 @@
 
 // Including Windows.h can conflict with Winsock2 usage, and also
 // adds problematic macros like min() and max(). Try to work around:
+#ifndef NOMINMAX
 #define NOMINMAX
+#define _THRIFT_UNDEF_NOMINMAX
+#endif
+#ifndef WIN32_LEAN_AND_MEAN
 #define WIN32_LEAN_AND_MEAN
+#define _THRIFT_UNDEF_WIN32_LEAN_AND_MEAN
+#endif
 #include <Windows.h>
+#ifdef _THRIFT_UNDEF_NOMINMAX
 #undef NOMINMAX
+#undef _THRIFT_UNDEF_NOMINMAX
+#endif
+#ifdef _THRIFT_UNDEF_WIN32_LEAN_AND_MEAN
 #undef WIN32_LEAN_AND_MEAN
+#undef _THRIFT_UNDEF_WIN32_LEAN_AND_MEAN
+#endif
 
 /*
   Lightweight synchronization objects that only make sense on Windows.  For cross-platform