Skip to content

Commit

Permalink
Fix ft_utils build for Windows
Browse files Browse the repository at this point in the history
Summary: Checking for _MS_VER didn't cover all Windows, so WV_PAUSE() was using the incorrect macro definition on some Windows platforms.

Reviewed By: SonicField

Differential Revision: D68021227

fbshipit-source-id: 61c2d55c7c32ff453a9e391fc63e7a2c0a19dffa
  • Loading branch information
Kevin Newton authored and facebook-github-bot committed Jan 13, 2025
1 parent 01d3e09 commit 39e2eb0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
30 changes: 12 additions & 18 deletions _concurrency.c
Original file line number Diff line number Diff line change
Expand Up @@ -748,34 +748,28 @@ static void ConcurrentDequeList_dealloc(ConcurrentDequeList* list) {
* spinning when waiting for a lock.
*/
#ifndef WV_PAUSE
#if defined(_MSC_VER) // Microsoft compilers
#if defined(_M_X64) || defined(_M_IX86) // Intel/AMD
#include <immintrin.h>
#define WV_PAUSE() _mm_pause()
#elif defined(_M_ARM) || defined(_M_ARM64) // ARM
#define WV_PAUSE() __yield()
#if defined(_WIN32)
#include <windows.h>
#define WV_PAUSE() YieldProcessor() /* Windows */
#elif defined(__GNUC__) || defined(__clang__)
#if defined(__x86_64__) || defined(__i386__)
#define WV_PAUSE() __builtin_ia32_pause() /* Intel/AMD */
#elif defined(__aarch64__) || defined(__arm__)
#define WV_PAUSE() asm volatile("yield" ::: "memory") /* ARM */
#else
#define WV_PAUSE() // Fallback: no-op
#define WV_PAUSE() /* Unknown */
#endif
#elif defined(__GNUC__) || defined(__clang__) // GCC/Clang
#if defined(__x86_64__) || defined(__i386__) // Intel/AMD

#define WV_PAUSE() __builtin_ia32_pause()
#elif defined(__aarch64__) || defined(__arm__) // ARM
#define WV_PAUSE() asm volatile("yield" ::: "memory")
#else
#define WV_PAUSE() // Fallback: no-op
#define WV_PAUSE() /* Unknown */
#endif
#else // Unknown compiler
#define WV_PAUSE() // Fallback: no-op
#endif
#endif // WV_PAUSE

/* Pause for the given number of iterations, using the WV_PAUSE macro.
*/
static inline void ConcurrentDeque_backoff_pause(unsigned int backoff) {
for (unsigned int pause = 0; pause < backoff; pause++)
for (unsigned int pause = 0; pause < backoff; pause++) {
WV_PAUSE();
}
}

/* An infinite for-loop that performs exponential backoff.
Expand Down
2 changes: 0 additions & 2 deletions test_weave.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# pyre-unsafe

# We deliberately do not import weave because we want to ensure the native code does this.
import os
import sys
import threading
import unittest
Expand All @@ -23,7 +22,6 @@


@unittest.skipIf(sys.version_info < (3, 13), "Requires Python 3.13 or later")
@unittest.skipIf(os.name == "nt", "Windows currently broken for this test")
class TestTLSManagement(unittest.TestCase):
def setUp(self):
ft_utils.ENABLE_EXPERIMENTAL = True
Expand Down

0 comments on commit 39e2eb0

Please sign in to comment.