[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
automatically.

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... */
        DeleteMsgPort(newmp);
    }