home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / mmpm21tk.zip / TK / FSSHT / SHDESTRY.C < prev    next >
C/C++ Source or Header  |  1993-02-25  |  7KB  |  139 lines

  1. /****************************************************************************/
  2. /*                                                                          */
  3. /*                    Copyright (c) IBM Corporation 1992, 1993              */
  4. /*                           All Rights Reserved                            */
  5. /*                                                                          */
  6. /* SOURCE FILE NAME: SHDESTRY.C                                             */
  7. /*                                                                          */
  8. /* DESCRIPTIVE NAME:  Stream Handler Destroy stream routine                 */
  9. /*                                                                          */
  10. /* FUNCTION: This function destroys a stream instance.                      */
  11. /*                                                                          */
  12. /* ENTRY POINTS: ShcDestroy                                                 */
  13. /*                                                                          */
  14. /*************************** END OF SPECIFICATIONS **************************/
  15. #define  INCL_NOPMAPI                  /* no PM include files required */
  16. #define  INCL_DOSSEMAPHORES
  17. #define  INCL_DOSPROCESS
  18. #include <os2.h>
  19. #include <os2me.h>
  20. #include <hhpheap.h>
  21. #include <shi.h>
  22.  
  23. /************************** START OF SPECIFICATIONS *************************/
  24. /*                                                                          */
  25. /* SUBROUTINE NAME: ShcDestroy                                              */
  26. /*                                                                          */
  27. /* DESCRIPTIVE NAME: Stream Handler Command Destroy stream routine          */
  28. /*                                                                          */
  29. /* FUNCTION: Destroys the specified stream.  Which means it takes the       */
  30. /*           stream instance block off the active chain; it signals the     */
  31. /*           worker thread to end (SIBACTFLG_KILL) and waits for it; then it*/
  32. /*           deallocates the sib.  At this point the stream is gone from    */
  33. /*           this stream handler.                                           */
  34. /*                                                                          */
  35. /* ENTRY POINT: ShcDestroy                                                  */
  36. /*   LINKAGE:   CALL NEAR (0:32)                                            */
  37. /*                                                                          */
  38. /* INPUT: Pointer to Destroy SHC paramater block (PARM_DESTROY).  It        */
  39. /*   contains:                                                              */
  40. /*     ULONG    ulFunction;           Handler command function (SHC_DESTROY)*/
  41. /*     HID      hid;                  handler ID                            */
  42. /*     HSTREAM  hstream;              handle of stream instance             */
  43. /*                                                                          */
  44. /* EXIT-NORMAL: 0 NO_ERROR                                                  */
  45. /*                                                                          */
  46. /* EXIT-ERROR:                                                              */
  47. /*   ERROR_INVALID_STREAM                                                   */
  48. /*   Errors from:                                                           */
  49. /*     DosRequestMutexSem                                                   */
  50. /*                                                                          */
  51. /* SIDE EFFECTS:                                                            */
  52. /*   All information known to this stream handler about the stream is gone. */
  53. /*   This includes the worker read/write thread and the stream instance     */
  54. /*   block.  The stream is destroyed.                                       */
  55. /*                                                                          */
  56. /* INTERNAL REFERENCES:                                                     */
  57. /*        ROUTINES: None                                                    */
  58. /*                                                                          */
  59. /* EXTERNAL REFERENCES:                                                     */
  60. /*   ROUTINES:                                                              */
  61. /*    HhpFreeMem - Free memory (sib)                                        */
  62. /*                                                                          */
  63. /*   DATA STRUCTURES:                                                       */
  64. /*    pHeap - Pointer to Stream handler heap.                               */
  65. /*    hmtxGlobalData - handle of mutex semaphore to control global data     */
  66. /*      access.  In this case the control of the sib chain, and control of  */
  67. /*      the heap control blocks.                                            */
  68. /*                                                                          */
  69. /* NOTES: Filter stream handlers only have 1 worker thread for 2 streams.   */
  70. /*   This is indicated by a NULL (0) sib.ThreadID for the second stream.    */
  71. /*   So when destroy is called for this second stream (sib.threadid = 0)    */
  72. /*   we skip the code to end the thread since there one does not exist.     */
  73. /*                                                                          */
  74. /*************************** END OF SPECIFICATIONS **************************/
  75.  
  76. RC ShcDestroy(pdyparm)
  77. PPARM_DESTROY pdyparm;
  78.  
  79. { /* Start of ShcDestroy */
  80.  
  81. RC rc = NO_ERROR;                       /* local return code */
  82. PSIB psib;                              /* Stream instance block */
  83. PSIB psibPrev = NULL;                   /* previous Stream instance block in */
  84.                                         /* chain */
  85.  
  86.   /*
  87.    * Find our Stream Instance Block and take it off the list
  88.    */
  89.   ENTERCRITX(rc);
  90.  
  91.   psib = pSIB_list_head;
  92.   while ((psib) &&
  93.          !((psib->hStream == pdyparm->hstream) && (psib->HandlerID == pdyparm->hid)))
  94.     {
  95.       psibPrev = psib;
  96.       psib = psib->pnxtSIB;
  97.     }
  98.  
  99.   /* If the sib was found take it off the chain.  If it was not found the */
  100.   /* stream handle and id is invalid. */
  101.  
  102.   if (psib)
  103.     { /* Take the sib off the chain */
  104.  
  105.       /* If previous sib in chain then take this sib out.  If no previous */
  106.       /*  sib then this is the first sib in the chain so update the list */
  107.       /*  head. */
  108.  
  109.       if (psibPrev)
  110.         {
  111.           psibPrev->pnxtSIB = psib->pnxtSIB;
  112.         }
  113.       else
  114.         {
  115.           pSIB_list_head = psib->pnxtSIB;
  116.         }
  117.     } /* Take the sib off the chain */
  118.   else
  119.     {
  120.       rc = ERROR_INVALID_STREAM;
  121.     }
  122.  
  123.   EXITCRIT;
  124.  
  125.   if (!rc)
  126.     { /* We have SIB */
  127.  
  128.       /* First kill the read write thread */
  129.  
  130.       /* Check sib threadid to make sure there is a thread for this stream */
  131.       /* before resume and waiting for it. */
  132.  
  133.       DestroySIB(psib);
  134.     } /* We have SIB */
  135.  
  136.   return(rc);
  137.  
  138. } /* End of ShcDestroy */
  139.