home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tolkit45.zip / os2tk45 / samples / mm / fssht / shstop.c < prev   
C/C++ Source or Header  |  1999-05-11  |  8KB  |  161 lines

  1. /****************************************************************************/
  2. /*                                                                          */
  3. /*                    Copyright (c) IBM Corporation 1992, 1993              */
  4. /*                           All Rights Reserved                            */
  5. /*                                                                          */
  6. /* SOURCE FILE NAME: SHSTOP.C                                               */
  7. /*                                                                          */
  8. /* DESCRIPTIVE NAME:  Stream Handler Stop stream routine                    */
  9. /*                                                                          */
  10. /* FUNCTION: This function stops a stream instance.                         */
  11. /*                                                                          */
  12. /* ENTRY POINTS: ShcStop                                                    */
  13. /*                                                                          */
  14. /* PvtComment: All lines that you do not want to go in the toolkit fssht    */
  15. /* PvtComment: need to contain a string "PvtComment:"                       */
  16. /* PvtComment: These lines are taken out using sed in fssht.mak - Vivek     */
  17. /*                                                                          */
  18. /* PvtComment: Change History                                                           */
  19. /* PvtComment: DATE     DEVELOPER      CHANGE DESCRIPTION                               */
  20. /* PvtComment: ????     ??????????     Original creation                                */
  21. /* PvtComment: 09/17/93 Vivek Nirkhe   Def 10814 - thread suspend problem on pause      */
  22. /* PvtComment: 10/14/93 Vivek Nirkhe   Def 11482 - Record to Notify problem with flush */
  23. /*************************** END OF SPECIFICATIONS **************************/
  24.  
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <string.h>
  28. #include <memory.h>
  29.  
  30. #define  INCL_NOPMAPI                  /* no PM include files required */
  31. #define  INCL_DOSSEMAPHORES
  32. #define  INCL_DOSPROCESS
  33. #define  INCL_OS2MM
  34. #include <os2.h>
  35. #include <os2me.h>
  36. #include <hhpheap.h>
  37. #include <shi.h>
  38.  
  39.  
  40.  
  41. /************************** START OF SPECIFICATIONS *************************/
  42. /*                                                                          */
  43. /* SUBROUTINE NAME: ShcStop                                                 */
  44. /*                                                                          */
  45. /* DESCRIPTIVE NAME: Stream Handler Command Stop stream routine             */
  46. /*                                                                          */
  47. /* FUNCTION: This stops the specified stream.  The flags passed indicate    */
  48. /*           if this should discard all buffers or not.                     */
  49. /*                                                                          */
  50. /* NOTES:                                                                   */
  51. /*                                                                          */
  52. /* ENTRY POINT: ShcStop                                                     */
  53. /*   LINKAGE:   CALL NEAR (0:32)                                            */
  54. /*                                                                          */
  55. /* INPUT: Pointer to shc stop parameter block (PARM_STOP) containing:       */
  56. /*   ULONG   ulFunction  Handler command function SHC_STOP                  */
  57. /*   HID     hid         handler ID                                         */
  58. /*   HSTREAM hstream     handle of stream instance                          */
  59. /*   ULONG   ulFlags     Stop flags (see SSM.H)                             */
  60. /*                                                                          */
  61. /* EXIT-NORMAL: NO_ERROR (0)                                                */
  62. /*                                                                          */
  63. /* EXIT-ERROR:                                                              */
  64. /*   None                                                                   */
  65. /*                                                                          */
  66. /* SIDE EFFECTS:                                                            */
  67. /*   The IO thread is blocked.                                              */
  68. /*                                                                          */
  69. /* INTERNAL REFERENCES:                                                     */
  70. /*        ROUTINES: None                                                    */
  71. /*                                                                          */
  72. /* EXTERNAL REFERENCES:                                                     */
  73. /*   ROUTINES:                                                              */
  74. /*     ShFindSib                                                            */
  75. /*                                                                          */
  76. /*   DATA STRUCTURES:                                                       */
  77. /*                                                                          */
  78. /*************************** END OF SPECIFICATIONS **************************/
  79.  
  80. RC ShcStop(pstparm)
  81. PPARM_STOP pstparm;
  82.  
  83. { /* Start of ShcStop */
  84.  
  85. RC    rc = NO_ERROR;                    /* local return code */
  86. PSIB  psib;                             /* Stream instance block */
  87.  
  88.  
  89.   /*
  90.    * Find our Stream Instance Block
  91.    */
  92.   if (!(rc = ShFindSib(&psib, pstparm->hstream, pstparm->hid)))
  93.     { /* We have SIB */
  94.  
  95.       /* Don't bother checking most states since the stream manager does this */
  96.       /* for us before the command gets here. */
  97.  
  98.       /* If this is stop Flush and we are the target then we will stop when we */
  99.       /* run out of buffers.  So ignore the stop command. */
  100.  
  101.       if (!((pstparm->ulFlags & SPI_STOP_FLUSH) && (pstparm->hid == TgtHandlerID)))
  102.         { /* not flush and target handler */
  103.           if (pstparm->ulFlags & (SPI_STOP_DISCARD | SPI_STOP_FLUSH))
  104.             { /* We must release all buffers */
  105.               if (psib->ThreadID)
  106.                 {
  107.                   /*  Update action flags to stop the independent thread, and wait on the */
  108.                   /*  command sync semaphore to wait until it gets the command. */
  109.  
  110.                   if (pstparm->ulFlags & SPI_STOP_DISCARD)
  111.                     SYNC_SEND_MSG(psib,SIBACTFLG_STOP_DISCARD,SIB_RUNNING);
  112.  
  113.                   if (pstparm->ulFlags & SPI_STOP_FLUSH)
  114.                     SYNC_SEND_MSG(psib,SIBACTFLG_STOP_FLUSH,SIB_RUNNING);
  115.                 }
  116.  
  117.               else
  118.                 {
  119.                   if (pstparm->ulFlags & SPI_STOP_DISCARD)
  120.                     psib->ulActionFlags |= SIBACTFLG_STOP_DISCARD;
  121.                   if (pstparm->ulFlags & SPI_STOP_FLUSH)
  122.                     psib->ulActionFlags |= SIBACTFLG_STOP_FLUSH;
  123.                 }
  124.             } /* We must release all buffers */
  125.           else
  126.             { /* Assume stop pause command*/
  127.  
  128.               if (psib->ulStatus == SIB_RUNNING)
  129.                 {
  130.                   psib->ulStatus = SIB_PAUSED;
  131.                   // PvtComment: Eventually all stream handlers that use common code should
  132.                   // PvtComment: use SYNC_SEND_MSG. At that time, get rid of the else part.
  133.                   // PvtComment: and remove the flag from makefiles.
  134. #ifdef SYNCPAUSE
  135.                   // PvtComment: Def 10814
  136.                   // PvtComment: Using semaphore wait to stop the read thread and
  137.                   // PvtComment: not suspending it. This should solve Mountain View problem
  138.                   SYNC_SEND_MSG(psib,SIBACTFLG_STOP_PAUSE,0L);
  139. #else
  140.                   // PvtComment: Old mechanism
  141.                   SUSPEND_IO(psib); // PvtComment:
  142. #endif
  143.                 }
  144.             } /* Assume stop pause command*/
  145.         } /* not flush and target handler */
  146.  
  147.       else
  148.         {
  149.           SYNC_SEND_MSG(psib,SIBACTFLG_STOP_FLUSH,SIB_RUNNING);
  150.           // PvtComment: Defect 11482 - Simple resume would not unblock the write thread
  151.           // PvtComment: from the hevStop semaphore.
  152.           // PvtComment: RESUME_IO(psib,SIB_RUNNING);            /* Flush the target */
  153.         }
  154.     } /* We have SIB */
  155.  
  156.  
  157.  
  158.   return(rc);
  159.  
  160. } /* End of ShcStop */
  161.