DosCreateSpinLock: Difference between revisions
Appearance
mNo edit summary |
|||
| Line 47: | Line 47: | ||
*[[DosReleaseSpinLock]] | *[[DosReleaseSpinLock]] | ||
[[Category: | [[Category:Dos]] | ||
Revision as of 22:05, 10 December 2017
Create a spinlock for multiprocessor serialisation.
Syntax
DosCreateSpinLock (pHandle)
Parameters
- phandle (PHSPINLOCK)
- A pointer to the spinlock handle that can be passed to DosAcquireSpinLock to acquire a spinlock and to DosReleaseSpinLock to release the spinlock.
Returns
- ulrc (APIRET)
- 0 NO_ERROR
- 32804 ERROR_NO_MORE_HANDLES
Remarks
The device driver should protect access to critical resources using spinlocks. The device driver allocates spinlocks in the Init routine by calling DevHlp_CreateSpinLock. CreateSpinLock returns a handle for use by the device driver. This handle is passed to DevHlp_AcquireSpinLock and DevHlp_ReleaseSpinLock. The spinlock is freed by calling DevHlp_FreeSpinLock. The driver may request any number of spinlocks, as the spinlocks are represented by a very small data structure. Once created, the spinlocks never go away.
Example Code
// OS/2 adv srv 4 SMP spinlock
extern "C" {
typedef ULONG HSPINLOCK;
typedef HSPINLOCK FAR *PHSPINLOCK;
APIRET APIENTRY DosCreateSpinLock(PHSPINLOCK pHandle);
APIRET APIENTRY DosAcquireSpinLock(HSPINLOCK Handle);
APIRET APIENTRY DosReleaseSpinLock(HSPINLOCK Handle);
APIRET APIENTRY DosFreeSpinLock(HSPINLOCK Handle);
};
class SpinLock {
HSPINLOCK sl;
public:
SpinLock() { DosCreateSpinLock(&sl); }
~SpinLock() { DosFreeSpinLock(sl); }
void Request() {
DosAcquireSpinLock(sl);
}
void Release() {
DosReleaseSpinLock(sl);
}
};