---
title: IOLockAlloc
framework: kernel
role: symbol
role_heading: Function
path: kernel/1553021-iolockalloc
---

# IOLockAlloc

Allocates and initializes a mutex.

## Declaration

```occ
struct IOLock * IOLockAlloc(void);
```

```occ
IOLock * IOLockAlloc(void);
```

## Return Value

Return Value Pointer to the allocated lock, or zero on failure.

## Discussion

Discussion Allocates a mutex in general purpose memory, and initializes 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. IOLocks use the global IOKit lock group, IOLockGroup. To simplify kext debugging and lock-heat analysis, consider using lck_* locks with a per-driver lock group, as defined in kern/locks.h.

## See Also

### Mutexes

- [IOLockInitWithState](kernel/1553028-iolockinitwithstate.md)
- [IOLockFree](kernel/1553034-iolockfree.md)
- [IOTryLock](kernel/1553012-iotrylock.md)
- [IOTakeLock](kernel/1553007-iotakelock.md)
- [IOLockLock](kernel/1553000-iolocklock.md)
- [IOUnlock](kernel/1552994-iounlock.md)
- [IOLockTryLock](kernel/1553018-iolocktrylock.md)
- [IOLockUnlock](kernel/1553006-iolockunlock.md)
- [IOLockWakeup](kernel/1553016-iolockwakeup.md)
- [IOLockSleep](kernel/1553026-iolocksleep.md)
- [IOLockSleepDeadline](kernel/1553030-iolocksleepdeadline.md)
- [IOLockGetMachLock](kernel/1553008-iolockgetmachlock.md)
