home *** CD-ROM | disk | FTP | other *** search
- [ 6. Event Semaphores]
- EMBEDDED DOS EVENT SEMAPHORES
- ════════════════════════════════════════════════════════════════════════
- The event object is the basic mechanism used to control synchronous
- dispatching of threads. An event is assigned a state, and must always
- be in either the set or cleared states.
-
- Facilities are provided by the kernel to set, clear, and pulse events.
- The kernel also provides allocation and deallocation services to make
- event objects. Threads may inspect the state of an event object, and
- may wait on an event until the event has reached the set state.
-
- 1. AllocateEvent
-
- An event object is created with the AllocateEvent kernel
- function. Once the event is allocated, it is automatically
- maintained by the kernel in response to service requests.
-
- This function returns a handle to an event object that must be
- used by the caller in subsequent kernel services that operate on
- events. The kernel initializes the event object to the cleared
- state.
-
- Upon return, the macro instruction call clears the carry flag if
- the operation was successful, and sets it if the operation was
- not performed.
-
- Assembly Language Format:
-
- mov dl, SYS_ALLOCATE_EVENT
- int 2dh ; (AX) = event handle.
- jc Failure
-
- Macro Instruction Format:
-
- label AllocateEvent <EventHandle>
-
- Portable Request Format:
-
- STATUS AllocateEvent(
- OUT PHANDLE EventHandle
- );
-
- Parameters:
-
- EventHandle - Specifies a 16-bit general purpose register or
- a pointer to a word in memory where the kernel will
- return a handle to the allocated event.
-
- 2. DeallocateEvent
-
- An event object is destroyed with the DeallocateEvent kernel
- function. Once the event is deallocated, its corresponding
- handle becomes invalid and may no longer be used.
-
- This function returns allocated resources to the system so that
- they may be recycled. If any threads are blocked on the event
- object, then they are automatically destroyed by the kernel.
-
- Upon return, the macro instruction call clears the carry flag if
- the operation was successful, and sets it if the operation was
- not performed.
-
- Assembly Language Format:
-
- mov ax, <EventHandle> ; (AX) = handle to event.
- mov dl, SYS_DEALLOCATE_EVENT
- int 2dh
- jc Failure
-
- Macro Instruction Format:
-
- label DeallocateEvent <EventHandle>
-
- Portable Request Format:
-
- STATUS DeallocateEvent(
- IN HANDLE EventHandle
- );
-
- Parameters:
-
- EventHandle - Specifies a 16-bit general purpose register or
- word in memory containing a handle to an event to be
- deallocated.
-
- 3. SetEvent
-
- An event object may be transfered to the set state by calling the
- SetEvent kernel function. Setting an event will cause all threads
- blocking on the event object to be rescheduled by the kernel.
-
- Upon return, the macro instruction call clears the carry flag if
- the operation was successful, and sets it if the operation was
- not performed.
-
- Assembly Language Format:
-
- mov ax, <EventHandle> ; (AX) = handle to event.
- mov dl, SYS_SET_EVENT
- int 2dh
- jc Failure
-
- Macro Instruction Format:
-
- label SetEvent <EventHandle>
-
- Portable Request Format:
-
- STATUS SetEvent(
- IN HANDLE EventHandle
- );
-
- Parameters:
-
- EventHandle - Specifies a 16-bit general purpose register or
- word in memory containing a handle to an event to be set.
-
- 4. ClearEvent
-
- An event object may be transfered to the cleared state by calling
- the ClearEvent kernel function. Clearing an event will not
- affect the status of thread blocking on the event object.
-
- Upon return, the macro instruction call clears the carry flag if
- the operation was successful, and sets it if the operation was
- not performed.
-
- Assembly Language Format:
-
- mov ax, <EventHandle> ; (AX) = handle to event.
- mov dl, SYS_CLEAR_EVENT
- int 2dh
- jc Failure
-
- Macro Instruction Format:
-
- label ClearEvent <EventHandle>
-
- Portable Request Format:
-
- STATUS ClearEvent(
- IN HANDLE EventHandle
- );
-
- Parameters:
-
- EventHandle - Specifies a 16-bit general purpose register or
- word in memory containing a handle to an event to be
- cleared.
-
- 5. PulseEvent
-
- An event object may be momentarily transfered to the set state by
- calling the PulseEvent kernel function. Pulsing an event will
- cause all threads blocking on the event object to be rescheduled
- by the kernel, but the event's status is not changed.
-
- Upon return, the macro instruction call clears the carry flag if
- the operation was successful, and sets it if the operation was
- not performed.
-
- Assembly Language Format:
-
- mov ax, <EventHandle> ; (AX) = handle to event.
- mov dl, SYS_PULSE_EVENT
- int 2dh
- jc Failure
-
- Macro Instruction Format:
-
- label PulseEvent <EventHandle>
-
- Portable Request Format:
-
- STATUS PulseEvent(
- IN HANDLE EventHandle
- );
-
- Parameters:
-
- EventHandle - Specifies a 16-bit general purpose register or
- word in memory containing a handle to an event to be
- pulsed.
-
- 6. QueryEvent
-
- The state of an event object may be inspected by calling the
- QueryEvent kernel function. The function returns the value TRUE
- if the event was set at the time of the call, and FALSE
- otherwise.
-
- Upon return, the macro instruction call clears the carry flag if
- the operation was successful, and sets it if the operation was
- not performed.
-
- Assembly Language Format:
-
- mov ax, <EventHandle> ; (AX) = handle to event.
- mov dl, SYS_QUERY_EVENT
- int 2dh ; (AX) = 0 if clear, non-zero if set.
- jc Failure
-
- Macro Instruction Format:
-
- label QueryEvent <EventHandle>, <EventStatus>
-
- Portable Request Format:
-
- STATUS QueryEvent(
- IN HANDLE EventHandle,
- OUT PUSHORT EventStatus
- );
-
- Parameters:
-
- EventHandle - Specifies a 16-bit general purpose register or
- word in memory containing a handle to an event to be
- queried.
-
- EventStatus - Specifies a 16-bit general purpose register or
- address of a word in memory where the kernel will
- return the status of the event.
-
- 7. WaitEvent
-
- A thread may wait for an event to reach the set state by calling
- the WaitEvent kernel function. If the event is already in the
- set state at the time the request is issued, the thread will
- continue execution without waiting. If the event is in the
- cleared state at the time the request is issued, the thread will
- block until the event is pulsed or set, at which time the thread
- will resume execution.
-
- If a thread is blocked on an event, the kernel immediately
- selects another thread in the system for execution. If no
- threads are available for execution, then the scheduler executes
- an idle loop waiting for a thread to be allocated or unblocked.
-
- Upon return, the macro instruction call clears the carry flag if
- the operation was successful, and sets it if the operation was
- not performed.
-
- Assembly Language Format:
-
- mov ax, <EventHandle> ; (AX) = handle to event.
- mov dl, SYS_WAIT_EVENT
- int 2dh ; wait for pulse or set status.
- jc Failure
-
- Macro Instruction Format:
-
- label WaitEvent <EventHandle>
-
- Portable Request Format:
-
- STATUS WaitEvent(
- IN HANDLE EventHandle
- );
-
- Parameters:
-
- EventHandle - Specifies a 16-bit general purpose register or
- word in memory containing a handle to an event to be
- blocked on.