| 1 |
/* |
| 2 |
* Copyright (c) 2023 |
| 3 |
* |
| 4 |
* Permission to use, copy, modify, and distribute this software for any |
| 5 |
* purpose with or without fee is hereby granted, provided that the above |
| 6 |
* copyright notice and this permission notice appear in all copies. |
| 7 |
* |
| 8 |
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 9 |
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 10 |
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 11 |
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 12 |
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 13 |
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 14 |
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 15 |
*/ |
| 16 |
|
| 17 |
#ifndef _MACPORTS_LOCK_H_ |
| 18 |
#define _MACPORTS_LOCK_H_ |
| 19 |
|
| 20 |
/* MP support header */ |
| 21 |
#include "MacportsLegacySupport.h" |
| 22 |
|
| 23 |
#if __MP_LEGACY_SUPPORT_OS_UNFAIR_LOCK__ |
| 24 |
|
| 25 |
/* |
| 26 |
os/lock.h does not exist |
| 27 |
use deprecated OSSpinLock instead |
| 28 |
|
| 29 |
see https://developer.apple.com/documentation/os/os_unfair_lock |
| 30 |
*/ |
| 31 |
|
| 32 |
#include <libkern/OSAtomic.h> |
| 33 |
|
| 34 |
#define OS_UNFAIR_LOCK_INIT OS_SPINLOCK_INIT |
| 35 |
|
| 36 |
typedef OSSpinLock os_unfair_lock; |
| 37 |
typedef OSSpinLock *os_unfair_lock_t; |
| 38 |
|
| 39 |
__MP__BEGIN_DECLS |
| 40 |
|
| 41 |
void os_unfair_lock_lock(os_unfair_lock_t lock); |
| 42 |
|
| 43 |
bool os_unfair_lock_trylock(os_unfair_lock_t lock); |
| 44 |
|
| 45 |
void os_unfair_lock_unlock(os_unfair_lock_t lock); |
| 46 |
|
| 47 |
__MP__END_DECLS |
| 48 |
|
| 49 |
/* |
| 50 |
it is not clear how to implement these functions |
| 51 |
|
| 52 |
void os_unfair_lock_assert_owner(const os_unfair_lock *lock); |
| 53 |
void os_unfair_lock_assert_not_owner(const os_unfair_lock *lock); |
| 54 |
*/ |
| 55 |
|
| 56 |
#else /*__MP_LEGACY_SUPPORT_OS_UNFAIR_LOCK__*/ |
| 57 |
|
| 58 |
/* Include the primary system os/lock.h */ |
| 59 |
#include_next <os/lock.h> |
| 60 |
|
| 61 |
#endif /*__MP_LEGACY_SUPPORT_OS_UNFAIR_LOCK__*/ |
| 62 |
|
| 63 |
#endif |