Thread-safe version of loopKeepAlive()
[folly.git] / folly / CPortability.h
index c348b3611d6c53b6b99e4b61114bf11dc52daebd..5c497cb2f06492eca0267117cae5292e986a7c2a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2015 Facebook, Inc.
+ * Copyright 2016 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * limitations under the License.
  */
 
-#ifndef CPORTABILITY_H
-#define CPORTABILITY_H
+#pragma once
 
 /* These definitions are in a separate file so that they
  * may be included from C- as well as C++-based projects. */
 
+/**
+ * Portable version check.
+ */
+#ifndef __GNUC_PREREQ
+# if defined __GNUC__ && defined __GNUC_MINOR__
+/* nolint */
+#  define __GNUC_PREREQ(maj, min) ((__GNUC__ << 16) + __GNUC_MINOR__ >= \
+                                   ((maj) << 16) + (min))
+# else
+/* nolint */
+#  define __GNUC_PREREQ(maj, min) 0
+# endif
+#endif
+
 /* Define a convenience macro to test when address sanitizer is being used
  * across the different compilers (e.g. clang, gcc) */
 #if defined(__clang__)
 # define FOLLY_DISABLE_ADDRESS_SANITIZER
 #endif
 
+/* Define a convenience macro to test when thread sanitizer is being used
+ * across the different compilers (e.g. clang, gcc) */
+#if defined(__clang__)
+# if __has_feature(thread_sanitizer)
+#  define FOLLY_SANITIZE_THREAD 1
+# endif
+#elif defined(__GNUC__) && __SANITIZE_THREAD__
+# define FOLLY_SANITIZE_THREAD 1
+#endif
 
 /**
  * ASAN/MSAN/TSAN define pre-processor symbols:
 # define UBSAN_DISABLE(x)
 #endif // UNDEFINED_SANITIZER
 
-#endif // CPORTABILITY_H
+/**
+ * Macro for marking functions as having public visibility.
+ */
+#if defined(__GNUC__)
+# if __GNUC_PREREQ(4, 9)
+#  define FOLLY_EXPORT [[gnu::visibility("default")]]
+# else
+#  define FOLLY_EXPORT __attribute__((__visibility__("default")))
+# endif
+#else
+# define FOLLY_EXPORT
+#endif