Jump to content

DosCreateSpinLock: Difference between revisions

From EDM2
Line 43: Line 43:
==Related Functions==
==Related Functions==


[[Category:]]
[[Category:DevHlps]]

Revision as of 19:37, 7 June 2017

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

Syntax

DosCreateSpinLock(PHSPINLOCK pHandle)

Parameters

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