Skip to content

Commit

Permalink
Add XNN_HAS_PTHREADS to common.h, as a way to indicate that a given p…
Browse files Browse the repository at this point in the history
…latform doesn't support pthreads() at all.

Note that it's initially (effectively) unused, since it's only set to 0 for Windows, which already has its own custom code path for threading; however, this flag will be used for at least one upcoming target and landing it separately from introduction of that target seems easier to review.

PiperOrigin-RevId: 660518641
  • Loading branch information
xnnpack-bot committed Aug 8, 2024
1 parent 92bbb10 commit 401807c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/xnnpack/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@
#define XNN_HAS_MMAP 1
#endif

#if XNN_PLATFORM_WINDOWS
#define XNN_HAS_PTHREADS 0
#else
#define XNN_HAS_PTHREADS 1
#endif

// Define compile identification macros

#if defined(__clang__)
Expand Down
22 changes: 20 additions & 2 deletions src/xnnpack/init-once.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2019 Google LLC
// Copyright 2024 Google LLC
//
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree.
Expand All @@ -9,6 +9,7 @@
#include <windows.h>
#else
#include <pthread.h>
#include <stdbool.h>
#endif

#include "xnnpack.h"
Expand All @@ -27,7 +28,7 @@
#define XNN_INIT_ONCE(name) \
InitOnceExecuteOnce(&name##_guard, &name##_windows_wrapper, NULL, NULL) /* no semicolon */

#else
#elif XNN_HAS_PTHREADS

#define XNN_INIT_ONCE_GUARD(name) \
static void init_##name##_config(void); \
Expand All @@ -36,4 +37,21 @@
#define XNN_INIT_ONCE(name) \
pthread_once(&name##_guard, &init_##name##_config) /* no semicolon */

#else

// If we don't have pthreads available (and there isn't any other platform
// specialization), assume we can just get by without special synchronization.

#define XNN_INIT_ONCE_GUARD(name) \
static void init_##name##_config(void); \
static bool name##_guard = 0 /* no semicolon */

#define XNN_INIT_ONCE(name) \
do { \
if (!(name##_guard)) { \
init_##name##_config(); \
name##_guard = 1; \
} \
} while (0) /* no semicolon */

#endif

0 comments on commit 401807c

Please sign in to comment.