/*
- * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 1998-2002 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
#error IOLocks.h is for kernel use only
#endif
-#ifndef IOKIT_DEPRECATED
-#define IOKIT_DEPRECATED 1
-#endif
+#include <sys/appleapiopts.h>
#include <IOKit/system.h>
extern "C" {
#endif
-#include <kern/lock.h>
-#include <kern/simple_lock.h>
+#include <libkern/locks.h>
#include <machine/machine_routines.h>
+extern lck_grp_t *IOLockGroup;
+
/*
* Mutex lock operations
*/
-typedef mutex_t IOLock;
+#ifdef XNU_KERNEL_PRIVATE
+typedef lck_mtx_t IOLock;
+#else
+typedef struct _IOLock IOLock;
+#endif /* XNU_KERNEL_PRIVATE */
+
/*! @function IOLockAlloc
- @abstract Allocates and initializes an osfmk mutex.
- @discussion Allocates an osfmk mutex in general purpose memory, and initilizes it. Mutexes are general purpose blocking mutual exclusion locks, supplied by osfmk/kern/lock.h. This function may block and so should not be called from interrupt level or while a simple lock is held.
+ @abstract Allocates and initializes a mutex.
+ @discussion Allocates a mutex in general purpose memory, and initilizes it. Mutexes are general purpose blocking mutual exclusion locks, supplied by libkern/locks.h. This function may block and so should not be called from interrupt level or while a spin lock is held.
@result Pointer to the allocated lock, or zero on failure. */
IOLock * IOLockAlloc( void );
/*! @function IOLockFree
- @abstract Frees an osfmk mutex.
+ @abstract Frees a mutex.
@discussion Frees a lock allocated with IOLockAlloc. Any blocked waiters will not be woken.
@param lock Pointer to the allocated lock. */
void IOLockFree( IOLock * lock);
+/*! @function IOLockGetMachLock
+ @abstract Accessor to a Mach mutex.
+ @discussion Accessor to the Mach mutex.
+ @param lock Pointer to the allocated lock. */
+
+lck_mtx_t * IOLockGetMachLock( IOLock * lock);
+
/*! @function IOLockLock
- @abstract Lock an osfmk mutex.
- @discussion Lock the mutex. If the lock is held by any thread, block waiting for its unlock. This function may block and so should not be called from interrupt level or while a simple lock is held. Locking the mutex recursively from one thread will result in deadlock.
+ @abstract Lock a mutex.
+ @discussion Lock the mutex. If the lock is held by any thread, block waiting for its unlock. This function may block and so should not be called from interrupt level or while a spin lock is held. Locking the mutex recursively from one thread will result in deadlock.
@param lock Pointer to the allocated lock. */
+#ifdef XNU_KERNEL_PRIVATE
+#ifndef IOLOCKS_CPP
static __inline__
void IOLockLock( IOLock * lock)
{
- mutex_lock(lock);
+ lck_mtx_lock(lock);
}
+#else
+void IOLockLock( IOLock * lock);
+#endif /* !IOLOCKS_CPP */
+#else
+void IOLockLock( IOLock * lock);
+#endif /* XNU_KERNEL_PRIVATE */
/*! @function IOLockTryLock
- @abstract Attempt to lock an osfmk mutex.
+ @abstract Attempt to lock a mutex.
@discussion Lock the mutex if it is currently unlocked, and return true. If the lock is held by any thread, return false.
@param lock Pointer to the allocated lock.
@result True if the mutex was unlocked and is now locked by the caller, otherwise false. */
+#ifdef XNU_KERNEL_PRIVATE
+#ifndef IOLOCKS_CPP
static __inline__
boolean_t IOLockTryLock( IOLock * lock)
{
- return(mutex_try(lock));
+ return(lck_mtx_try_lock(lock));
}
+#else
+boolean_t IOLockTryLock( IOLock * lock);
+#endif /* !IOLOCKS_CPP */
+#else
+boolean_t IOLockTryLock( IOLock * lock);
+#endif /* XNU_KERNEL_PRIVATE */
/*! @function IOLockUnlock
- @abstract Unlock an osfmk mutex.
-@discussion Unlock the mutex and wake any blocked waiters. Results are undefined if the caller has not locked the mutex. This function may block and so should not be called from interrupt level or while a simple lock is held.
+ @abstract Unlock a mutex.
+@discussion Unlock the mutex and wake any blocked waiters. Results are undefined if the caller has not locked the mutex. This function may block and so should not be called from interrupt level or while a spin lock is held.
@param lock Pointer to the allocated lock. */
+#ifdef XNU_KERNEL_PRIVATE
+#ifndef IOLOCKS_CPP
static __inline__
void IOLockUnlock( IOLock * lock)
{
- mutex_unlock(lock);
+ lck_mtx_unlock(lock);
}
+#else
+void IOLockUnlock( IOLock * lock);
+#endif /* !IOLOCKS_CPP */
+#else
+void IOLockUnlock( IOLock * lock);
+#endif /* XNU_KERNEL_PRIVATE */
+
+/*! @function IOLockSleep
+ @abstract Sleep with mutex unlock and relock
+@discussion Prepare to sleep,unlock the mutex, and re-acquire it on wakeup.Results are undefined if the caller has not locked the mutex. This function may block and so should not be called from interrupt level or while a spin lock is held.
+ @param lock Pointer to the locked lock.
+ @param event The event to sleep on.
+ @param interType How can the sleep be interrupted.
+ @result The wait-result value indicating how the thread was awakened.*/
+int IOLockSleep( IOLock * lock, void *event, UInt32 interType);
+
+int IOLockSleepDeadline( IOLock * lock, void *event,
+ AbsoluteTime deadline, UInt32 interType);
+
+void IOLockWakeup(IOLock * lock, void *event, bool oneThread);
-#if IOKIT_DEPRECATED
+#ifdef __APPLE_API_OBSOLETE
/* The following API is deprecated */
typedef enum {
kIOLockStateUnlocked = 0,
- kIOLockStateLocked = 1,
+ kIOLockStateLocked = 1
} IOLockState;
void IOLockInitWithState( IOLock * lock, IOLockState state);
static __inline__ boolean_t IOTryLock( IOLock * lock) { return(IOLockTryLock(lock)); }
static __inline__ void IOUnlock( IOLock * lock) { IOLockUnlock(lock); }
-#endif /* IOKIT_DEPRECATED */
+#endif /* __APPLE_API_OBSOLETE */
/*
* Recursive lock operations
/*! @function IORecursiveLockAlloc
@abstract Allocates and initializes an recursive lock.
- @discussion Allocates a recursive lock in general purpose memory, and initilizes it. Recursive locks function identically to osfmk mutexes but allow one thread to lock more than once, with balanced unlocks.
+ @discussion Allocates a recursive lock in general purpose memory, and initilizes it. Recursive locks function identically to mutexes but allow one thread to lock more than once, with balanced unlocks.
@result Pointer to the allocated lock, or zero on failure. */
IORecursiveLock * IORecursiveLockAlloc( void );
void IORecursiveLockFree( IORecursiveLock * lock);
+/*! @function IORecursiveLockGetMachLock
+ @abstract Accessor to a Mach mutex.
+ @discussion Accessor to the Mach mutex.
+ @param lock Pointer to the allocated lock. */
+
+lck_mtx_t * IORecursiveLockGetMachLock( IORecursiveLock * lock);
+
/*! @function IORecursiveLockLock
@abstract Lock a recursive lock.
- @discussion Lock the recursive lock. If the lock is held by another thread, block waiting for its unlock. This function may block and so should not be called from interrupt level or while a simple lock is held. The lock may be taken recursively by the same thread, with a balanced number of calls to IORecursiveLockUnlock.
+ @discussion Lock the recursive lock. If the lock is held by another thread, block waiting for its unlock. This function may block and so should not be called from interrupt level or while a spin lock is held. The lock may be taken recursively by the same thread, with a balanced number of calls to IORecursiveLockUnlock.
@param lock Pointer to the allocated lock. */
void IORecursiveLockLock( IORecursiveLock * lock);
/*! @function IORecursiveLockUnlock
@abstract Unlock a recursive lock.
-@discussion Undo one call to IORecursiveLockLock, if the lock is now unlocked wake any blocked waiters. Results are undefined if the caller does not balance calls to IORecursiveLockLock with IORecursiveLockUnlock. This function may block and so should not be called from interrupt level or while a simple lock is held.
+@discussion Undo one call to IORecursiveLockLock, if the lock is now unlocked wake any blocked waiters. Results are undefined if the caller does not balance calls to IORecursiveLockLock with IORecursiveLockUnlock. This function may block and so should not be called from interrupt level or while a spin lock is held.
@param lock Pointer to the allocated lock. */
void IORecursiveLockUnlock( IORecursiveLock * lock);
* Complex (read/write) lock operations
*/
-typedef lock_t IORWLock;
+#ifdef XNU_KERNEL_PRIVATE
+typedef lck_rw_t IORWLock;
+#else
+typedef struct _IORWLock IORWLock;
+#endif /* XNU_KERNEL_PRIVATE */
/*! @function IORWLockAlloc
- @abstract Allocates and initializes an osfmk general (read/write) lock.
-@discussion Allocates an initializes an osfmk lock_t in general purpose memory, and initilizes it. Read/write locks provide for multiple readers, one exclusive writer, and are supplied by osfmk/kern/lock.h. This function may block and so should not be called from interrupt level or while a simple lock is held.
+ @abstract Allocates and initializes a read/write lock.
+@discussion Allocates and initializes a read/write lock in general purpose memory, and initilizes it. Read/write locks provide for multiple readers, one exclusive writer, and are supplied by libkern/locks.h. This function may block and so should not be called from interrupt level or while a spin lock is held.
@result Pointer to the allocated lock, or zero on failure. */
IORWLock * IORWLockAlloc( void );
/*! @function IORWLockFree
- @abstract Frees an osfmk general (read/write) lock.
+ @abstract Frees a read/write lock.
@discussion Frees a lock allocated with IORWLockAlloc. Any blocked waiters will not be woken.
@param lock Pointer to the allocated lock. */
void IORWLockFree( IORWLock * lock);
+/*! @function IORWLockGetMachLock
+ @abstract Accessor to a Mach read/write lock.
+ @discussion Accessor to the Mach read/write lock.
+ @param lock Pointer to the allocated lock. */
+
+lck_rw_t * IORWLockGetMachLock( IORWLock * lock);
+
/*! @function IORWLockRead
- @abstract Lock an osfmk lock for read.
-@discussion Lock the lock for read, allowing multiple readers when there are no writers. If the lock is held for write, block waiting for its unlock. This function may block and so should not be called from interrupt level or while a simple lock is held. Locking the lock recursively from one thread, for read or write, can result in deadlock.
+ @abstract Lock a read/write lock for read.
+@discussion Lock the lock for read, allowing multiple readers when there are no writers. If the lock is held for write, block waiting for its unlock. This function may block and so should not be called from interrupt level or while a spin lock is held. Locking the lock recursively from one thread, for read or write, can result in deadlock.
@param lock Pointer to the allocated lock. */
+#ifdef XNU_KERNEL_PRIVATE
+#ifndef IOLOCKS_CPP
static __inline__
void IORWLockRead( IORWLock * lock)
{
- lock_read( lock);
+ lck_rw_lock_shared( lock);
}
+#else
+void IORWLockRead( IORWLock * lock);
+#endif /* !IOLOCKS_CPP */
+#else
+void IORWLockRead( IORWLock * lock);
+#endif /* XNU_KERNEL_PRIVATE */
/*! @function IORWLockWrite
- @abstract Lock an osfmk lock for write.
- @discussion Lock the lock for write, allowing one writer exlusive access. If the lock is held for read or write, block waiting for its unlock. This function may block and so should not be called from interrupt level or while a simple lock is held. Locking the lock recursively from one thread, for read or write, can result in deadlock.
+ @abstract Lock a read/write lock for write.
+ @discussion Lock the lock for write, allowing one writer exlusive access. If the lock is held for read or write, block waiting for its unlock. This function may block and so should not be called from interrupt level or while a spin lock is held. Locking the lock recursively from one thread, for read or write, can result in deadlock.
@param lock Pointer to the allocated lock. */
+#ifdef XNU_KERNEL_PRIVATE
+#ifndef IOLOCKS_CPP
static __inline__
void IORWLockWrite( IORWLock * lock)
{
- lock_write( lock);
+ lck_rw_lock_exclusive( lock);
}
+#else
+void IORWLockWrite( IORWLock * lock);
+#endif /* !IOLOCKS_CPP */
+#else
+void IORWLockWrite( IORWLock * lock);
+#endif /* XNU_KERNEL_PRIVATE */
/*! @function IORWLockUnlock
- @abstract Unlock an osfmk lock.
- @discussion Undo one call to IORWLockRead or IORWLockWrite. Results are undefined if the caller has not locked the lock. This function may block and so should not be called from interrupt level or while a simple lock is held.
+ @abstract Unlock a read/write lock.
+ @discussion Undo one call to IORWLockRead or IORWLockWrite. Results are undefined if the caller has not locked the lock. This function may block and so should not be called from interrupt level or while a spin lock is held.
@param lock Pointer to the allocated lock. */
+#ifdef XNU_KERNEL_PRIVATE
+#ifndef IOLOCKS_CPP
static __inline__
void IORWLockUnlock( IORWLock * lock)
{
- lock_done( lock);
+ lck_rw_done( lock);
}
+#else
+void IORWLockUnlock( IORWLock * lock);
+#endif /* !IOLOCKS_CPP */
+#else
+void IORWLockUnlock( IORWLock * lock);
+#endif /* XNU_KERNEL_PRIVATE */
-#if IOKIT_DEPRECATED
+#ifdef __APPLE_API_OBSOLETE
/* The following API is deprecated */
static __inline__ void IOWriteLock( IORWLock * lock) { IORWLockWrite(lock); }
static __inline__ void IORWUnlock( IORWLock * lock) { IORWLockUnlock(lock); }
-#endif /* IOKIT_DEPRECATED */
+#endif /* __APPLE_API_OBSOLETE */
/*
* Simple locks. Cannot block while holding a simple lock.
*/
-typedef simple_lock_data_t IOSimpleLock;
+#ifdef KERNEL_PRIVATE
+typedef lck_spin_t IOSimpleLock;
+#else
+typedef struct _IOSimpleLock IOSimpleLock;
+#endif /* XNU_KERNEL_PRIVATE */
/*! @function IOSimpleLockAlloc
- @abstract Allocates and initializes an osfmk simple (spin) lock.
- @discussion Allocates an initializes an osfmk simple lock in general purpose memory, and initilizes it. Simple locks provide non-blocking mutual exclusion for synchronization between thread context and interrupt context, or for multiprocessor synchronization, and are supplied by osfmk/kern/simple_lock.h. This function may block and so should not be called from interrupt level or while a simple lock is held.
+ @abstract Allocates and initializes a spin lock.
+ @discussion Allocates an initializes a spin lock in general purpose memory, and initilizes it. Spin locks provide non-blocking mutual exclusion for synchronization between thread context and interrupt context, or for multiprocessor synchronization, and are supplied by libkern/locks.h. This function may block and so should not be called from interrupt level or while a spin lock is held.
@result Pointer to the allocated lock, or zero on failure. */
IOSimpleLock * IOSimpleLockAlloc( void );
/*! @function IOSimpleLockFree
- @abstract Frees an osfmk simple (spin) lock.
+ @abstract Frees a spin lock.
@discussion Frees a lock allocated with IOSimpleLockAlloc.
@param lock Pointer to the lock. */
void IOSimpleLockFree( IOSimpleLock * lock );
+/*! @function IOSimpleLockGetMachLock
+ @abstract Accessor to a Mach spin lock.
+ @discussion Accessor to the Mach spin lock.
+ @param lock Pointer to the allocated lock. */
+
+lck_spin_t * IOSimpleLockGetMachLock( IOSimpleLock * lock);
+
/*! @function IOSimpleLockInit
- @abstract Initialize an osfmk simple (spin) lock.
- @discussion Initialize an embedded osfmk simple lock, to the unlocked state.
+ @abstract Initialize a spin lock.
+ @discussion Initialize an embedded spin lock, to the unlocked state.
@param lock Pointer to the lock. */
void IOSimpleLockInit( IOSimpleLock * lock );
/*! @function IOSimpleLockLock
- @abstract Lock an osfmk simple lock.
-@discussion Lock the simple lock. If the lock is held, spin waiting for its unlock. Simple locks disable preemption, cannot be held across any blocking operation, and should be held for very short periods. When used to synchronize between interrupt context and thread context they should be locked with interrupts disabled - IOSimpleLockLockDisableInterrupt() will do both. Locking the lock recursively from one thread will result in deadlock.
+ @abstract Lock a spin lock.
+@discussion Lock the spin lock. If the lock is held, spin waiting for its unlock. Spin locks disable preemption, cannot be held across any blocking operation, and should be held for very short periods. When used to synchronize between interrupt context and thread context they should be locked with interrupts disabled - IOSimpleLockLockDisableInterrupt() will do both. Locking the lock recursively from one thread will result in deadlock.
@param lock Pointer to the lock. */
+#ifdef XNU_KERNEL_PRIVATE
+#ifndef IOLOCKS_CPP
static __inline__
void IOSimpleLockLock( IOSimpleLock * lock )
{
- usimple_lock( lock );
+ lck_spin_lock( lock );
}
+#else
+void IOSimpleLockLock( IOSimpleLock * lock );
+#endif /* !IOLOCKS_CPP */
+#else
+void IOSimpleLockLock( IOSimpleLock * lock );
+#endif /* XNU_KERNEL_PRIVATE */
/*! @function IOSimpleLockTryLock
- @abstract Attempt to lock an osfmk simple lock.
-@discussion Lock the simple lock if it is currently unlocked, and return true. If the lock is held, return false. Successful calls to IOSimpleLockTryLock should be balanced with calls to IOSimpleLockUnlock.
+ @abstract Attempt to lock a spin lock.
+@discussion Lock the spin lock if it is currently unlocked, and return true. If the lock is held, return false. Successful calls to IOSimpleLockTryLock should be balanced with calls to IOSimpleLockUnlock.
@param lock Pointer to the lock.
@result True if the lock was unlocked and is now locked by the caller, otherwise false. */
+#ifdef XNU_KERNEL_PRIVATE
+#ifndef IOLOCKS_CPP
static __inline__
boolean_t IOSimpleLockTryLock( IOSimpleLock * lock )
{
- return( usimple_lock_try( lock ) );
+ return( lck_spin_try_lock( lock ) );
}
+#else
+boolean_t IOSimpleLockTryLock( IOSimpleLock * lock );
+#endif /* !IOLOCKS_CPP */
+#else
+boolean_t IOSimpleLockTryLock( IOSimpleLock * lock );
+#endif /* XNU_KERNEL_PRIVATE */
/*! @function IOSimpleLockUnlock
- @abstract Unlock an osfmk simple lock.
+ @abstract Unlock a spin lock.
@discussion Unlock the lock, and restore preemption. Results are undefined if the caller has not locked the lock.
@param lock Pointer to the lock. */
+#ifdef XNU_KERNEL_PRIVATE
+#ifndef IOLOCKS_CPP
static __inline__
void IOSimpleLockUnlock( IOSimpleLock * lock )
{
- usimple_unlock( lock );
+ lck_spin_unlock( lock );
}
+#else
+void IOSimpleLockUnlock( IOSimpleLock * lock );
+#endif /* !IOLOCKS_CPP */
+#else
+void IOSimpleLockUnlock( IOSimpleLock * lock );
+#endif /* XNU_KERNEL_PRIVATE */
typedef long int IOInterruptState;
/*! @function IOSimpleLockLockDisableInterrupt
- @abstract Lock an osfmk simple lock.
- @discussion Lock the simple lock. If the lock is held, spin waiting for its unlock. Simple locks disable preemption, cannot be held across any blocking operation, and should be held for very short periods. When used to synchronize between interrupt context and thread context they should be locked with interrupts disabled - IOSimpleLockLockDisableInterrupt() will do both. Locking the lock recursively from one thread will result in deadlock.
+ @abstract Lock a spin lock.
+ @discussion Lock the spin lock. If the lock is held, spin waiting for its unlock. Simple locks disable preemption, cannot be held across any blocking operation, and should be held for very short periods. When used to synchronize between interrupt context and thread context they should be locked with interrupts disabled - IOSimpleLockLockDisableInterrupt() will do both. Locking the lock recursively from one thread will result in deadlock.
@param lock Pointer to the lock. */
static __inline__
IOInterruptState IOSimpleLockLockDisableInterrupt( IOSimpleLock * lock )
{
IOInterruptState state = ml_set_interrupts_enabled( false );
- usimple_lock( lock );
+ IOSimpleLockLock( lock );
return( state );
}
/*! @function IOSimpleLockUnlockEnableInterrupt
- @abstract Unlock an osfmk simple lock, and restore interrupt state.
+ @abstract Unlock a spin lock, and restore interrupt state.
@discussion Unlock the lock, and restore preemption and interrupts to the state as they were when the lock was taken. Results are undefined if the caller has not locked the lock.
@param lock Pointer to the lock.
@param state The interrupt state returned by IOSimpleLockLockDisableInterrupt() */
void IOSimpleLockUnlockEnableInterrupt( IOSimpleLock * lock,
IOInterruptState state )
{
- usimple_unlock( lock );
+ IOSimpleLockUnlock( lock );
ml_set_interrupts_enabled( state );
}