 |
Semaphores
|
The AMX Semaphore Manager provides a general purpose counting semaphore with priority queuing and timeout. Any number of user defined semaphores can be created for mutual exclusion and resource management.
A semaphore is created with a request to the Semaphore Manager specifying the initial semaphore count. A task wishing to gain control of a semaphore or to use one of the resources managed by the semaphore requests the Semaphore Manager to grant the access. It specifies the priority at which it wishes to wait if the resource is not immediately available. It can optionally specify the maximum time interval which it is prepared to wait for access.
Any task, Timer Procedure or Interrupt Service Procedure can signal the release of a semaphore. The Semaphore Manager will immediately grant access to the semaphore to the highest priority task on the semaphore's wait queue. Recall that tasks are ordered on the queue according to the priority at which they wished to wait. If the task which is granted the resource is of higher priority than the task which was executing at the time the semaphore signal occurred, an immediate task switch will occur.
If a task is waiting for access to a semaphore and the timeout interval which it specified expires, the Semaphore Manager removes the task from the semaphore's queue and allows it to resume execution with a timeout indication.
 |
AMX Resource Management
|
The AMX Semaphore Manager provides the simplest mechanism for controlling the access to critical resources. Resources may include numeric coprocessors, disk files, input/output devices, database components, regions of memory, specific words of memory, or any other "entity" which is considered to be a resource.
An application task requests ownership of a resource with a call to the Semaphore Manager. If the resource is available, the task is granted immediate ownership of it. If the resource is unavailable, the task is placed on the list of tasks waiting for the resource at the priority specified by the task. When the task which currently owns the resource releases it with a call to the Semaphore Manager, the resource will be given to the task which has been waiting longest.
Although the Semaphore Manager uses a binary semaphore mechanism for controlling access to resources, it differs from the counting semaphore facility in one significant feature. Resource ownership is tied to a specific task. Only the task owning a resource is permitted to signal its release. The Semaphore Manager does not permit more than one task to share ownership of a particular resource.
|
Semaphore Manager |
| Function |
Service |
| cjsmcreate |
Create a counting or resource semaphore |
| cjsmdelete |
Delete a semaphore |
| |
| cjsmwait |
Get use of a semaphore (optional timeout) |
| cjsmsignal |
Signal to a semaphore |
| cjsmstatus |
Fetch status of a semaphore |
| |
| cjrmrsv |
Reserve a resource (optional timeout) |
| cjrmrls |
Release a resource (nested) |
| cjrmfree |
Free a resource (unconditional) |
|
|