Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | /* * Copyright (c) 201 Apple Inc. All rights reserved. * * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * * This file contains Original Code and/or Modifications of Original Code * as defined in and that are subject to the Apple Public Source License * Version 2.0 (the 'License'). You may not use this file except in * compliance with the License. The rights granted to you under the License * may not be used to create, or enable the creation or redistribution of, * unlawful or unlicensed copies of an Apple operating system, or to * circumvent, violate, or enable the circumvention or violation of, any * terms of an Apple operating system software license agreement. * * Please obtain a copy of the License at * http://www.opensource.apple.com/apsl/ and read it before using this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. * Please see the License for the specific language governing rights and * limitations under the License. * * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ */ #ifndef _I386_LOCKS_I386_INLINES_H_ #define _I386_LOCKS_I386_INLINES_H_ #include <kern/locks.h> #include <kern/lock_stat.h> #include <kern/turnstile.h> #if LCK_MTX_USE_ARCH // Enforce program order of loads and stores. #define ordered_load(target) os_atomic_load(target, compiler_acq_rel) #define ordered_store_release(target, value) ({ \ os_atomic_store(target, value, release); \ os_compiler_barrier(); \ }) /* Enforce program order of loads and stores. */ #define ordered_load_mtx_state(lock) ordered_load(&(lock)->lck_mtx_state) #define ordered_store_mtx_state_release(lock, value) ordered_store_release(&(lock)->lck_mtx_state, (value)) #define ordered_store_mtx_owner(lock, value) os_atomic_store(&(lock)->lck_mtx_owner, (value), compiler_acq_rel) #if DEVELOPMENT | DEBUG void lck_mtx_owner_check_panic(lck_mtx_t *mutex) __abortlike; #endif __attribute__((always_inline)) static inline void lck_mtx_ilk_unlock_inline( lck_mtx_t *mutex, uint32_t state) { state &= ~LCK_MTX_ILOCKED_MSK; ordered_store_mtx_state_release(mutex, state); enable_preemption(); } __attribute__((always_inline)) static inline void lck_mtx_lock_finish_inline( lck_mtx_t *mutex, uint32_t state) { assert(state & LCK_MTX_ILOCKED_MSK); /* release the interlock and re-enable preemption */ lck_mtx_ilk_unlock_inline(mutex, state); LCK_MTX_ACQUIRED(mutex, mutex->lck_mtx_grp, false, state & LCK_MTX_PROFILE_MSK); } __attribute__((always_inline)) static inline void lck_mtx_lock_finish_inline_with_cleanup( lck_mtx_t *mutex, uint32_t state) { assert(state & LCK_MTX_ILOCKED_MSK); /* release the interlock and re-enable preemption */ lck_mtx_ilk_unlock_inline(mutex, state); LCK_MTX_ACQUIRED(mutex, mutex->lck_mtx_grp, false, state & LCK_MTX_PROFILE_MSK); turnstile_cleanup(); } __attribute__((always_inline)) static inline void lck_mtx_try_lock_finish_inline( lck_mtx_t *mutex, uint32_t state) { /* release the interlock and re-enable preemption */ lck_mtx_ilk_unlock_inline(mutex, state); LCK_MTX_TRY_ACQUIRED(mutex, mutex->lck_mtx_grp, false, state & LCK_MTX_PROFILE_MSK); } __attribute__((always_inline)) static inline void lck_mtx_convert_spin_finish_inline( lck_mtx_t *mutex, uint32_t state) { /* release the interlock and acquire it as mutex */ state &= ~(LCK_MTX_ILOCKED_MSK | LCK_MTX_SPIN_MSK); state |= LCK_MTX_MLOCKED_MSK; ordered_store_mtx_state_release(mutex, state); enable_preemption(); } __attribute__((always_inline)) static inline void lck_mtx_unlock_finish_inline( lck_mtx_t *mutex, uint32_t state) { enable_preemption(); LCK_MTX_RELEASED(mutex, mutex->lck_mtx_grp, state & LCK_MTX_PROFILE_MSK); } #endif /* LCK_MTX_USE_ARCH */ #endif /* _I386_LOCKS_I386_INLINES_H_ */ |