---
title: IORWLockAlloc
framework: kernel
role: symbol
role_heading: Function
path: kernel/1553010-iorwlockalloc
---

# IORWLockAlloc

Allocates and initializes a read/write lock.

## Declaration

```occ
struct IORWLock * IORWLockAlloc(void);
```

```occ
IORWLock * IORWLockAlloc(void);
```

## Return Value

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

## Discussion

Discussion Allocates and initializes a read/write lock in general purpose memory. 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. IORWLocks 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

### Read/Write Locks

- [IORWLockFree](kernel/1553003-iorwlockfree.md)
- [IORWLockGetMachLock](kernel/1553033-iorwlockgetmachlock.md)
- [IORWLockRead](kernel/1553004-iorwlockread.md)
- [IORWLockUnlock](kernel/1553011-iorwlockunlock.md)
- [IORWLockWrite](kernel/1552996-iorwlockwrite.md)
- [IORWUnlock](kernel/1553027-iorwunlock.md)
- [IOWriteLock](kernel/1552985-iowritelock.md)
- [IOReadLock](kernel/1553022-ioreadlock.md)
