home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / emacs-19.28-src.tgz / tar.out / fsf / emacs / unixlib / src / processes.c < prev    next >
C/C++ Source or Header  |  1996-09-28  |  1KB  |  57 lines

  1. #include "amiga.h"
  2. #include <clib/alib_protos.h>
  3.  
  4. #include "processes.h"
  5.  
  6. int _next_pid, _our_pid;
  7. struct MinList _processes;
  8. char _door_name[DOOR_LEN];
  9. struct MsgPort *_children_exit;
  10. struct MsgPort *_startup_port;
  11.  
  12. void _free_entry(struct process *p)
  13. {
  14.   Remove((struct Node *)p);
  15.   free(p);
  16. }
  17.  
  18. struct process *_find_pid(int pid)
  19. {
  20.   struct process *entry;
  21.  
  22.   scan_processes (entry) if (entry->pid == pid) return entry;
  23.  
  24.   return 0;
  25. }
  26.  
  27. void _init_processes(void)
  28. {
  29.   NewList((struct List *)&_processes);
  30.   /* Choose a fairly unique pid for ourselves, but keep it within a range
  31.      which guarantees positive pid's for all created processes.
  32.      This range is further restricted to 23 bits so that a pid fits within the
  33.      range of an emacs number (generally 24 bits, though it is 26 on the Amiga) */
  34.   _our_pid = ((int)_us ^ _startup_time) & 0x7fffff;
  35.   _next_pid = _our_pid + 1;
  36.   _sprintf(_door_name, "door.%lx.%lx", _us, _startup_time);
  37.   if ((_startup_port = CreateMsgPort()) &&
  38.       (_children_exit = CreatePort(_door_name, 0))) return;
  39.  
  40.   _fail("No memory");
  41. }
  42.  
  43. void _cleanup_processes(void)
  44. {
  45.   if (_startup_port) DeleteMsgPort(_startup_port);
  46.   if (_children_exit)
  47.     {
  48.       struct exit_message *msg;
  49.  
  50.       Forbid();
  51.       while (msg = (struct exit_message *)GetMsg(_children_exit))
  52.     FreeMem(msg, sizeof(struct exit_message));
  53.       DeletePort(_children_exit);
  54.       Permit();
  55.     }
  56. }
  57.