• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2022 Google LLC
2 //
3 // This source code is licensed under the BSD-style license found in the
4 // LICENSE file in the root directory of this source tree.
5 
6 #pragma once
7 
8 #include <xnnpack.h>
9 #include <xnnpack/common.h>
10 
11 #if XNN_PLATFORM_WINDOWS
12 #ifndef WIN32_LEAN_AND_MEAN
13 #define WIN32_LEAN_AND_MEAN
14 #endif
15 #include <windows.h>
16 #elif XNN_PLATFORM_MACOS || XNN_PLATFORM_IOS
17 #include <dispatch/dispatch.h>
18 #else
19 #include <pthread.h>
20 #endif
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 struct xnn_mutex {
27 #if XNN_PLATFORM_WINDOWS
28   HANDLE handle;
29 #elif XNN_PLATFORM_MACOS || XNN_PLATFORM_IOS
30   dispatch_semaphore_t semaphore;
31 #elif XNN_PLATFORM_WEB && !defined(__EMSCRIPTEN_PTHREADS__)
32   char _; // Dummy member variable to comply with the C standard
33 #else
34   pthread_mutex_t mutex;
35 #endif
36 };
37 
38 enum xnn_status xnn_mutex_init(struct xnn_mutex* mutex);
39 enum xnn_status xnn_mutex_lock(struct xnn_mutex* mutex);
40 enum xnn_status xnn_mutex_unlock(struct xnn_mutex* mutex);
41 enum xnn_status xnn_mutex_destroy(struct xnn_mutex* mutex);
42 
43 #ifdef __cplusplus
44 } // extern "C"
45 #endif
46