home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / programming / gnuc / library / rcs / ix_close.c,v < prev    next >
Encoding:
Text File  |  1992-08-09  |  5.1 KB  |  249 lines

  1. head    1.5;
  2. access;
  3. symbols
  4.     version39-41:1.4;
  5. locks;
  6. comment    @ *  @;
  7.  
  8.  
  9. 1.5
  10. date    92.08.09.20.46.42;    author amiga;    state Exp;
  11. branches;
  12. next    1.4;
  13.  
  14. 1.4
  15. date    92.07.04.19.12.12;    author mwild;    state Exp;
  16. branches;
  17. next    1.3;
  18.  
  19. 1.3
  20. date    92.05.22.01.44.17;    author mwild;    state Exp;
  21. branches;
  22. next    1.2;
  23.  
  24. 1.2
  25. date    92.05.18.12.18.00;    author mwild;    state Exp;
  26. branches;
  27. next    1.1;
  28.  
  29. 1.1
  30. date    92.05.14.19.55.40;    author mwild;    state Exp;
  31. branches;
  32. next    ;
  33.  
  34.  
  35. desc
  36. @close function of library
  37. @
  38.  
  39.  
  40. 1.5
  41. log
  42. @delay restoring of old handlers
  43. @
  44. text
  45. @/*
  46.  *  This file is part of ixemul.library for the Amiga.
  47.  *  Copyright (C) 1991, 1992  Markus M. Wild
  48.  *
  49.  *  This library is free software; you can redistribute it and/or
  50.  *  modify it under the terms of the GNU Library General Public
  51.  *  License as published by the Free Software Foundation; either
  52.  *  version 2 of the License, or (at your option) any later version.
  53.  *
  54.  *  This library is distributed in the hope that it will be useful,
  55.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  56.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  57.  *  Library General Public License for more details.
  58.  *
  59.  *  You should have received a copy of the GNU Library General Public
  60.  *  License along with this library; if not, write to the Free
  61.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  62.  *
  63.  *  $Id: ix_close.c,v 1.4 1992/07/04 19:12:12 mwild Exp $
  64.  *
  65.  *  $Log: ix_close.c,v $
  66.  *  Revision 1.4  1992/07/04  19:12:12  mwild
  67.  *  don't just free death-messages, wake any children possibly waiting on them
  68.  *
  69.  * Revision 1.3  1992/05/22  01:44:17  mwild
  70.  * when debugging, check whether buddy allocator clean
  71.  *
  72.  * Revision 1.2  1992/05/18  12:18:00  mwild
  73.  * changed async mp to be global
  74.  *
  75.  * Revision 1.1  1992/05/14  19:55:40  mwild
  76.  * Initial revision
  77.  *
  78.  */
  79.  
  80. #define KERNEL
  81. #include "ixemul.h"
  82. #undef u
  83. #undef ix
  84. #include <hardware/intbits.h>
  85.  
  86. #undef DEBUG
  87.  
  88. #ifdef DEBUG
  89. #define DP(a) kprintf a
  90. #else
  91. #define DP(a)
  92. #endif
  93.  
  94. #define BASE_EXT_DECL
  95. #define BASE_PAR_DECL    struct ixemul_base *ix,
  96. #define BASE_PAR_DECL0    struct ixemul_base *ix
  97. #define BASE_NAME    ix->ix_intui_base
  98. #include <inline/intuition.h>
  99.  
  100. extern struct ExecBase     *SysBase;
  101.  
  102. void
  103. ix_close (struct ixemul_base *ixbase)
  104. {
  105.   int fd;
  106.   struct Task         *me      =    SysBase->ThisTask;
  107.   struct user         *u     =    (struct user *) me->tc_TrapData;
  108.   struct Process    *child;
  109.   struct user        *cu;
  110.   struct Node        *dm, *ndm;    /* really struct death_msg * */
  111.  
  112. DP(("ix_close.\n"));
  113.     
  114.   RemIntServer (INTB_VERTB, & u->u_itimerint);  
  115. #if later
  116. #endif
  117.   
  118.   /* already reset the trap vector here. It's better to get an alert, than
  119.    * to loop infinitely if one of the following functions should crash */
  120.   me->tc_TrapCode = u->u_otrap_code;
  121.  
  122.   /* close all files */
  123.   for (fd = 0; fd < NOFILE; fd++) 
  124.     if (u->u_ofile[fd]) syscall (SYS_close, fd);
  125.  
  126.   /* had to move this block after the SYS_close's, since close() might have
  127.      to wait for a packet, and then it's essential that our switch/launch
  128.      handlers are still active, or curproc is not updated accordingly */
  129.   me->tc_Flags    = u->u_otask_flags;
  130.   me->tc_Launch      = u->u_olaunch;
  131.   me->tc_Switch   = u->u_oswitch;
  132.   FreeSignal (u->u_sleep_sig);
  133.  
  134.   CloseDevice ((struct IORequest *) u->u_time_req);
  135.   syscall (SYS_DeleteExtIO, u->u_time_req);
  136.   
  137.   if (u->u_startup_cd != (BPTR) -1) __unlock (CurrentDir (u->u_startup_cd));
  138.  
  139.   u->u_trace_flags = 1;
  140.   syscall (SYS_DeletePort, u->u_sync_mp);
  141. #if 0
  142.   /* see ix_open.c */
  143.   DeleteInterruptPort (u->u_async_mp);
  144. #endif
  145.  
  146.   /* have to make sure that no child is trying to manipulate our process
  147.    * lists as well */
  148.   ix_lock_base ();
  149.   
  150.   for ((child = u->p_cptr) && (cu = (struct user *) (child->pr_Task.tc_TrapData));
  151.        child;
  152.        (child = cu->p_osptr) && (cu = (struct user *) (child->pr_Task.tc_TrapData)))
  153.     cu->p_pptr = (struct Process *) 1;
  154.  
  155.   u->p_cptr = 0;
  156.   
  157.   for (dm  = (struct Node *) u->p_zombies.mlh_Head;
  158.        ndm = dm->ln_Succ;
  159.        dm  = ndm)
  160.     {
  161.       /* there might be children sleeping on this, so wake them up now.. */
  162.       ix_wakeup (dm);
  163.       kfree (dm);
  164.     }
  165.  
  166.   ix_unlock_base ();
  167.  
  168.   FreeSignal (u->p_zombie_sig);
  169.  
  170.   all_free ();
  171.  
  172. #ifdef DEBUG
  173.   check_empty (0);
  174. #endif
  175.  
  176.   /* delay this until here, since the above called functions need access
  177.    * to the user area. */
  178.   me->tc_TrapData = u->u_otrap_data;
  179.  
  180.   kfree (u);
  181. }
  182. @
  183.  
  184.  
  185. 1.4
  186. log
  187. @don't just free death-messages, wake any children possibly waiting on them
  188. @
  189. text
  190. @d19 1
  191. a19 1
  192.  *  $Id: ix_close.c,v 1.3 1992/05/22 01:44:17 mwild Exp $
  193. d22 3
  194. d56 2
  195. a61 1
  196.   struct ExecBase     *SysBase =    *(struct ExecBase **)4;
  197. a73 5
  198.   me->tc_Flags    = u->u_otask_flags;
  199.   me->tc_Launch      = u->u_olaunch;
  200.   me->tc_Switch   = u->u_oswitch;
  201.   FreeSignal (u->u_sleep_sig);
  202.  
  203. d81 8
  204. @
  205.  
  206.  
  207. 1.3
  208. log
  209. @when debugging, check whether buddy allocator clean
  210. @
  211. text
  212. @d19 1
  213. a19 1
  214.  *  $Id: ix_close.c,v 1.2 1992/05/18 12:18:00 mwild Exp $
  215. d22 3
  216. d109 5
  217. a113 1
  218.     kfree (dm);
  219. @
  220.  
  221.  
  222. 1.2
  223. log
  224. @changed async mp to be global
  225. @
  226. text
  227. @d19 1
  228. a19 1
  229.  *  $Id: ix_close.c,v 1.1 1992/05/14 19:55:40 mwild Exp $
  230. d22 3
  231. d113 4
  232. @
  233.  
  234.  
  235. 1.1
  236. log
  237. @Initial revision
  238. @
  239. text
  240. @d19 1
  241. a19 1
  242.  *  $Id$
  243. d21 4
  244. a24 1
  245.  *  $Log$
  246. d84 2
  247. d87 1
  248. @
  249.