114
K
A
DAK
AMX Message Exchange Manager
Messages are sent to message exchanges in AMX message envelopes. The Message
Exchange Manager gets a free message envelope from the common pool of envelopes
maintained by AMX. You must therefore be sure to allocate enough message envelopes
to meet the needs of all of your message exchange messages as well as your task
messages.
Receive
Any task, ISP or Timer Procedure can get a message from a message exchange by calling
procedure ajmxget. If the message exchange has any messages, the highest priority
message (0 highest; 3 lowest) which arrived first will be given to the caller. If the
message exchange is empty, the caller will immediately receive an error indication.
Tasks can also call procedure ajmxwat to get a message from a message exchange. Only
tasks are allowed to call this procedure because the caller may have to wait for a message
to arrive at the message exchange. If the message exchange has any messages, the
highest priority message (0 highest; 3 lowest) which arrived first will be given to the
caller. If the message exchange is empty, the caller will be forced to wait for a message
to arrive.
The task specifies the interval, measured in system ticks, which it is willing to wait for a
message to arrive. An interval of 0 indicates a willingness to wait forever. The task must
also specify the priority at which it is prepared to wait, zero being the highest priority.
The Message Exchange Manager will add the task to the message exchange's wait queue
at the priority the task said it was willing to wait. Thus a task can preempt other tasks
already waiting in the queue at lower priority.
When a message finally arrives at the message exchange, the Message Exchange
Manager will give it to the task, if any, at the head of the message exchange's wait queue.
A task switch may occur immediately if the task being given the message is of higher
task priority than the currently running task.
If no message arrives at the message exchange before the timeout interval specified by a
task expires, the task will be removed from the message exchange wait queue and will
resume execution with a timeout indication.
Delete
When a message exchange is no longer needed, it can be deleted with a call to ajmxdel.
The Message Exchange Manager will reject the attempt to delete the message exchange if
any task is waiting on the message exchange wait queue or if any messages remain in any
of the exchange's message queues. When the Message Exchange Manager deletes the
message exchange, it marks the message exchange as invalid such that any subsequent
reference to the message exchange will be rejected.
You must be absolutely sure that no producer or consumer is referencing the message
exchange just as you go to delete it. Be aware that the deleted message exchange id may
be immediately reused by AMX for some other purpose.