Jump to content

DosCreateSpinLock: Difference between revisions

From EDM2
Ak120 (talk | contribs)
Erdmann (talk | contribs)
No edit summary
 
(10 intermediate revisions by 3 users not shown)
Line 1: Line 1:
Create a subsystem spinlock. This function is physical DevHlps introduced with OS/2 SMP.
Create a spinlock for multiprocessor serialisation.


==Syntax==
==Syntax==
<PRE>
APIRET APIENTRY DosCreateSpinLock (PHSPINLOCK pHandle)
DosCreateSpinLock(PHSPINLOCK pHandle)
 
</PRE>
==Parameters==
==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.
;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==  
==Returns==
;ulrc ([[APIRET]])
:0 NO_ERROR
:32804 ERROR_NO_MORE_HANDLES


==Remarks==
==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.
DosCreateSpinLock returns a handle to a spin lock that is allocated in kernel data space. The handle is to be used on subsequent spin lock function calls and DevHlps.
Do not call any API Function while you are holding a spinlock.


==Example Code==
==Example Code==
Line 22: Line 23:
             typedef HSPINLOCK FAR *PHSPINLOCK;
             typedef HSPINLOCK FAR *PHSPINLOCK;
             APIRET APIENTRY DosCreateSpinLock(PHSPINLOCK pHandle);
             APIRET APIENTRY DosCreateSpinLock(PHSPINLOCK pHandle);
             APIRET APIENTRY DosAcquireSpinLock(HSPINLOCK Handle);
             VOID APIENTRY DosAcquireSpinLock(HSPINLOCK Handle);
             APIRET APIENTRY DosReleaseSpinLock(HSPINLOCK Handle);
             VOID APIENTRY DosReleaseSpinLock(HSPINLOCK Handle);
             APIRET APIENTRY DosFreeSpinLock(HSPINLOCK Handle);
             APIRET APIENTRY DosFreeSpinLock(HSPINLOCK Handle);
             };
             };
Line 43: Line 44:


==Related Functions==
==Related Functions==
*[[DosAcquireSpinLock]]
*[[DosFreeSpinLock]]
*[[DosReleaseSpinLock]]


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

Latest revision as of 10:05, 19 July 2023

Create a spinlock for multiprocessor serialisation.

Syntax

APIRET APIENTRY 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.

Returns

ulrc (APIRET)
0 NO_ERROR
32804 ERROR_NO_MORE_HANDLES

Remarks

DosCreateSpinLock returns a handle to a spin lock that is allocated in kernel data space. The handle is to be used on subsequent spin lock function calls and DevHlps. Do not call any API Function while you are holding a spinlock.

Example Code

// OS/2 adv srv 4 SMP spinlock
extern "C" {
            typedef ULONG HSPINLOCK;
            typedef HSPINLOCK FAR *PHSPINLOCK;
            APIRET APIENTRY DosCreateSpinLock(PHSPINLOCK pHandle);
            VOID APIENTRY DosAcquireSpinLock(HSPINLOCK Handle);
            VOID 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