122
K
A
DAK
AMX Buffer Manager
9.3 Buffer Applications
Consider the following example. A process control system using AMX has a printer on
which errors and status messages are to be logged. These messages are generated by
several tasks as they perform their process control functions. These tasks must not wait
for the printer because they have more important work to do. Furthermore, each message
size may exceed the standard AMX message size.
A printer task receives the messages from the other tasks and outputs them to the printer.
The problem is to get these messages from the process control tasks to the printer task.
The Buffer Manager provides an ideal solution. A pool of buffers is defined and
dedicated to error logging. As each process control task detects an error, it calls the
Buffer Manager to obtain a buffer, fills the buffer with an appropriate error message and
makes an AMX ajsend call, sending the buffer pointer in an AMX message envelope to
the task mailbox of a printer task.
The printer task automatically executes every time an AMX message arrives in its task
mailbox. The AMX message is delivered to the task on its stack. The printer task
extracts the buffer pointer from the AMX message, outputs the contents of the buffer to
the printer, calls the Buffer Manager to release the buffer and ends. Because the process
control tasks need never wait for the printer task or printer, they are always available to
perform their intended functions.
Now consider the following addition to this example. Suppose it is desired to log
messages on both a display and printer. There are several ways this could be done.
1. Two buffers could be obtained from the Buffer Manager. The same message
would be copied into both buffers. One would be sent to a printer task mailbox,
the other to a display task mailbox.
2. A single buffer could be obtained from the Buffer Manager. It would be filled
with a message and sent to the display task mailbox. The display task would
output the message to the display and send the buffer to the printer task mailbox.
The printer task would output the message to the printer and release the buffer.
3. A single buffer could be obtained from the Buffer Manager. The message would
be copied into the buffer. The Buffer Manager would be called to increase the
buffer use count by one, for a total use count of two. The buffer pointer would
then be sent to both the printer task mailbox and the display task mailbox. Both
tasks would output the message to their output device and release the buffer.
When the slowest of these two tasks released the buffer, the use count would be
zero and the buffer would be free.