[Contents] [Index] [Help] [Retrace] [Browse <] [Browse >]

Before a message port is deleted, all outstanding messages from other
tasks must be returned.  This is done by getting and replying to all
messages at the port until message queue is empty.  Of course, there is no
need to reply to messages owned by the current task (the task performing
the port deletion).  Public ports attached to the system with AddPort()
must be removed from the system with RemPort() before deallocation.  This
amiga.lib functions CreatePort() and DeletePort() handle this

The following example of port deletion is equivalent to the DeletePort()
function as supplied in amiga.lib.  Note that DeletePort() must only be
used on ports created with CreatePort().

    void DeletePort(mp)
    struct MsgPort *mp;
        if ( mp->mp_Node.ln_Name ) RemPort(mp);  /* if it was public... */

        mp->mp_SigTask         = (struct Task *) -1;
                                /* Make it difficult to re-use the port */
        mp->mp_MsgList.lh_Head = (struct Node *) -1;

        FreeSignal( mp->mp_SigBit );
        FreeMem( mp, (ULONG)sizeof(struct MsgPort) );

To delete ports created with CreateMsgPort(), DeleteMsgPort() must be
used.  Note that these functions are only available in V36 and higher.  If
the port was made public with AddPort(), RemPort() must be used first, to
remove the port from the system.  Again, make sure all outstanding
messages are replied to, so that the message queue is empty.

    struct MsgPort *newmp;

    if (newmp)
        if ( newmp->mp_Node.ln_Name ) RemPort(newmp);
                                /* if it was public... */

[Back to Amiga Developer Docs]