if (!*tree) { msg->prev = msg->next = NULL; *tree = msg; return; }
cur->parent = newparent; cur->next = *new; cur->prev = NULL; *new = cur;
static void insert_message (THREAD **tree, THREAD *msg){#if 0 /* XXX */  THREAD *tmp;#endif  /* NOTE: we do NOT clear the `msg->child' link here because when we do   * the pseudo-threading, we want to preserve any sub-threads.  So we clear   * the `msg->child' in the main routine where we know it is safe to do.   */  /* if there are no elements in the list, just add it and return */  if (!*tree)  {    msg->prev = msg->next = NULL;    *tree = msg;    return;  }  /* check to see if this message belongs at the beginning of the list */#if 0 /* XXX */  if (!sortFunc || sortFunc ((void *) &msg, (void *) tree) < 0)  {#endif    (*tree)->prev = msg;    msg->next = *tree;    msg->prev = NULL;    *tree = msg;    return;#if 0 /* XXX */  }    /* search for the correct spot in the list to insert */  for (tmp = *tree; tmp->next; tmp = tmp->next)    if (sortFunc ((void *) &msg, (void *) &tmp->next) < 0)    {      msg->prev = tmp;      msg->next = tmp->next;      tmp->next->prev = msg;      tmp->next = msg;      return;    }  /* did not insert yet, so add this message to the end of the list */  tmp->next = msg;  msg->prev = tmp;  msg->next = NULL;#endif}