Jump to content

DosCreateSpinLock

From EDM2

Create a subsystem spinlock. This function is physical DevHlps introduced with OS/2 SMP.

Syntax

DosCreateSpinLock(PHSPINLOCK 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.

Return Code

Errors

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);
        }

};

Related Functions