Commit bc16b096 authored by Joe Loser's avatar Joe Loser Committed by Facebook Github Bot

AtomicSharedPtr-detail.h does not work with libc++ (#900)

Summary:
Problem:
- There are several tests enabled which rely on using
  shared_ptr_internals found in
  folly/concurrency/detail/AtomicSharedPtr-detail.h and
  the implementation only works for libstdc++ and not with other vendors
  such as libc++ and libcpp.
- This results in a hard error when compiling with Clang with libc++.

Solution:
- Add a CMake configure check to detect whether one is using libstdc++.
  FOLLY_USE_LIBSTDCPP macro is set to 1 if using libstdc++, 0 otherwise.
- Use FOLLY_USE_LIBSTDCPP to conditionally run the tests relying on
  shared_ptr_internals only when using libstdc++.

Note:
- A longer-term solution would be to implement the similar
  shared_ptr_internals with the libc++ types and provide a fallback
  locking approach for libcpp (MSVC standard library implementation).

Pull Request resolved: https://github.com/facebook/folly/pull/900

Reviewed By: djwatson

Differential Revision: D9312236

Pulled By: yfeldblum

fbshipit-source-id: 657eddc1e530b00bd5f5b10e7155bc3b6aac3726
parent 27ab332b
...@@ -179,6 +179,15 @@ check_cxx_source_compiles(" ...@@ -179,6 +179,15 @@ check_cxx_source_compiles("
FOLLY_USE_LIBCPP FOLLY_USE_LIBCPP
) )
check_cxx_source_compiles("
#include <type_traits>
#if !__GLIBCXX__
#error No libstdc++
#endif
int main() { return 0; }"
FOLLY_USE_LIBSTDCPP
)
check_cxx_source_runs(" check_cxx_source_runs("
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
......
...@@ -372,6 +372,12 @@ constexpr auto kIsLibcpp = true; ...@@ -372,6 +372,12 @@ constexpr auto kIsLibcpp = true;
constexpr auto kIsLibcpp = false; constexpr auto kIsLibcpp = false;
#endif #endif
#if FOLLY_USE_LIBSTDCPP
constexpr auto kIsLibstdcpp = true;
#else
constexpr auto kIsLibstdcpp = false;
#endif
#if _MSC_VER #if _MSC_VER
constexpr auto kMscVer = _MSC_VER; constexpr auto kMscVer = _MSC_VER;
#else #else
......
...@@ -13,6 +13,11 @@ ...@@ -13,6 +13,11 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
// AtomicSharedPtr-detail.h only works with libstdc++, so skip these tests for
// other vendors
#ifdef FOLLY_USE_LIBSTDCPP
#include <folly/concurrency/AtomicSharedPtr.h> #include <folly/concurrency/AtomicSharedPtr.h>
#include <sys/time.h> #include <sys/time.h>
...@@ -225,3 +230,11 @@ int main(int, char**) { ...@@ -225,3 +230,11 @@ int main(int, char**) {
runSuite<folly::atomic_shared_ptr<int>>(); runSuite<folly::atomic_shared_ptr<int>>();
return 0; return 0;
} }
#else // #ifdef FOLLY_USE_LIBSTDCPP
int main(int, char**) {
return 1;
}
#endif // #ifdef FOLLY_USE_LIBSTDCPP
...@@ -13,6 +13,11 @@ ...@@ -13,6 +13,11 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
// AtomicSharedPtr-detail.h only works with libstdc++, so skip these tests for
// other vendors
#ifdef FOLLY_USE_LIBSTDCPP
#include <atomic> #include <atomic>
#include <memory> #include <memory>
#include <thread> #include <thread>
...@@ -182,3 +187,4 @@ TEST(AtomicSharedPtr, DeterministicTest) { ...@@ -182,3 +187,4 @@ TEST(AtomicSharedPtr, DeterministicTest) {
DSched::join(t); DSched::join(t);
} }
} }
#endif // #ifdef FOLLY_USE_LIBSTDCPP
...@@ -14,6 +14,10 @@ ...@@ -14,6 +14,10 @@
* limitations under the License. * limitations under the License.
*/ */
// AtomicSharedPtr-detail.h only works with libstdc++, so skip these tests for
// other vendors
#ifdef FOLLY_USE_LIBSTDCPP
#include <memory> #include <memory>
#include <thread> #include <thread>
#include <vector> #include <vector>
...@@ -199,3 +203,5 @@ int main(int argc, char** argv) { ...@@ -199,3 +203,5 @@ int main(int argc, char** argv) {
return ret; return ret;
} }
#endif // #ifdef FOLLY_USE_LIBSTDCPP
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