Difference between revisions of "DosEnterCritSec (OS/2 1.x)"
m |
m |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 2: | Line 2: | ||
==Syntax== | ==Syntax== | ||
− | DosEnterCritSec ( ) | + | DosEnterCritSec () |
==Return Code== | ==Return Code== | ||
− | + | ;rc (USHORT) - return:Return code descriptions are: | |
− | Return code descriptions are: | + | *0 NO_ERROR |
− | * 0 | + | *484 ERROR_CRITSEC_OVERFLOW |
− | * 484 | + | |
==Remarks== | ==Remarks== | ||
Line 15: | Line 14: | ||
If a signal occurs, thread 1 begins execution to process the signal even though another thread in the process has a DosEnterCritSec active. (Thread 1 of a process is its initial thread of execution, not a thread created with the DosCreateThread call.) Any processing done by thread 1 to satisfy the signal must not include accessing the critical resource intended to be protected by the DosEnterCritSec request. | If a signal occurs, thread 1 begins execution to process the signal even though another thread in the process has a DosEnterCritSec active. (Thread 1 of a process is its initial thread of execution, not a thread created with the DosCreateThread call.) Any processing done by thread 1 to satisfy the signal must not include accessing the critical resource intended to be protected by the DosEnterCritSec request. | ||
− | A count is maintained of the number of times a DosEnterCritSec request is made without a corresponding DosExitCritSec. The count is incremented by DosEnterCritSec and decremented by DosExitCritSec. Normal thread dispatching is not restored until the count is 0. The outstanding DosEnterCritSec count is maintained in a word. If overflow occurs, the count is set to the maximum value, no operation is performed, and the request returns with an error. | + | A count is maintained of the number of times a DosEnterCritSec request is made without a corresponding [[DosExitCritSec (OS/2 1.x)|DosExitCritSec]]. The count is incremented by DosEnterCritSec and decremented by DosExitCritSec. Normal thread dispatching is not restored until the count is 0. The outstanding DosEnterCritSec count is maintained in a word. If overflow occurs, the count is set to the maximum value, no operation is performed, and the request returns with an error. |
− | A thread can also execute code without having to give up time slices to other threads in its process if it requests a priority class that is higher than those of the other threads. A thread's priority is examined and changed with DosGetPrty and DosSetPrty. | + | A thread can also execute code without having to give up time slices to other threads in its process if it requests a priority class that is higher than those of the other threads. A thread's priority is examined and changed with DosGetPrty and DosSetPrty. |
− | == | + | ==Bindings== |
− | ===C | + | ===C=== |
<PRE> | <PRE> | ||
#define INCL_DOSPROCESS | #define INCL_DOSPROCESS | ||
Line 26: | Line 25: | ||
USHORT rc = DosEnterCritSec(VOID); | USHORT rc = DosEnterCritSec(VOID); | ||
− | USHORT | + | USHORT rc; /* return code */ |
</PRE> | </PRE> | ||
− | + | ===MASM=== | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | ===MASM | + | |
<PRE> | <PRE> | ||
EXTRN DosEnterCritSec:FAR | EXTRN DosEnterCritSec:FAR | ||
Line 50: | Line 38: | ||
</PRE> | </PRE> | ||
− | [[Category: | + | ==Example Code== |
+ | This example enters a section that will not be pre-empted, performs a simple task, and then exits quickly. | ||
+ | <PRE> | ||
+ | #define INCL_DOSPROCESS | ||
+ | |||
+ | USHORT flag; | ||
+ | |||
+ | DosEnterCritSec(); /* Enter critical code section */ | ||
+ | flag = TRUE; /* Perform some work */ | ||
+ | DosExitCritSec(); /* Exit critical code section */ | ||
+ | </PRE> | ||
+ | |||
+ | [[Category:Dos16]] |
Latest revision as of 23:13, 25 January 2020
This call disables thread switching for the current process.
Syntax
DosEnterCritSec ()
Return Code
- rc (USHORT) - return
- Return code descriptions are:
- 0 NO_ERROR
- 484 ERROR_CRITSEC_OVERFLOW
Remarks
DosEnterCritSec causes other threads in the process to block themselves and give up their time slice. After a DosEnterCritSec request is made, no dynamic link calls should be made until the corresponding DosExitCritSec call is completed.
If a signal occurs, thread 1 begins execution to process the signal even though another thread in the process has a DosEnterCritSec active. (Thread 1 of a process is its initial thread of execution, not a thread created with the DosCreateThread call.) Any processing done by thread 1 to satisfy the signal must not include accessing the critical resource intended to be protected by the DosEnterCritSec request.
A count is maintained of the number of times a DosEnterCritSec request is made without a corresponding DosExitCritSec. The count is incremented by DosEnterCritSec and decremented by DosExitCritSec. Normal thread dispatching is not restored until the count is 0. The outstanding DosEnterCritSec count is maintained in a word. If overflow occurs, the count is set to the maximum value, no operation is performed, and the request returns with an error.
A thread can also execute code without having to give up time slices to other threads in its process if it requests a priority class that is higher than those of the other threads. A thread's priority is examined and changed with DosGetPrty and DosSetPrty.
Bindings
C
#define INCL_DOSPROCESS USHORT rc = DosEnterCritSec(VOID); USHORT rc; /* return code */
MASM
EXTRN DosEnterCritSec:FAR INCL_DOSPROCESS EQU 1 CALL DosEnterCritSec Returns WORD
Example Code
This example enters a section that will not be pre-empted, performs a simple task, and then exits quickly.
#define INCL_DOSPROCESS USHORT flag; DosEnterCritSec(); /* Enter critical code section */ flag = TRUE; /* Perform some work */ DosExitCritSec(); /* Exit critical code section */