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

  1. /****************************************************************************/
  2. /*                                                                          */
  3. /*                    Copyright (c) IBM Corporation 1992, 1993              */
  4. /*                           All Rights Reserved                            */
  5. /*                                                                          */
  6. /* SOURCE FILE NAME: SHSTART.C                                              */
  7. /*                                                                          */
  8. /* DESCRIPTIVE NAME:  Stream Handler Start stream routine                   */
  9. /*                                                                          */
  10. /* FUNCTION: This function starts a stream instance.                        */
  11. /*                                                                          */
  12. /* ENTRY POINTS: ShcStart                                                   */
  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. /*************************** END OF SPECIFICATIONS **************************/
  23. #define  INCL_NOPMAPI                  /* no PM include files required */
  24. #define  INCL_DOSSEMAPHORES
  25. #define  INCL_DOSPROCESS
  26. #define  INCL_OS2MM
  27. #include <os2.h>
  28. #include <os2me.h>
  29. #include <hhpheap.h>
  30. #include <shi.h>
  31.  
  32. /************************** START OF SPECIFICATIONS *************************/
  33. /*                                                                          */
  34. /* SUBROUTINE NAME: ShcStart                                                */
  35. /*                                                                          */
  36. /* DESCRIPTIVE NAME: Stream Handler Command Start stream routine            */
  37. /*                                                                          */
  38. /* FUNCTION: This routine kick starts the IO thread to start reading or     */
  39. /*   writing.  It may be called indirectly from SpiStartStream, or by the   */
  40. /*   stream manager buffer control code.  If we had to block because no     */
  41. /*   buffers were available, then the buffer control code will send a start.*/
  42. /*                                                                          */
  43. /* NOTES:                                                                   */
  44. /*                                                                          */
  45. /* ENTRY POINT: ShcStart                                                    */
  46. /*   LINKAGE:   CALL NEAR (0:32)                                            */
  47. /*                                                                          */
  48. /* INPUT: Pointer to shc start parameter block (PARM_START) containing:     */
  49. /*   ULONG   ulFunction  Handler command function SHC_START                 */
  50. /*   HID     hid         handler ID                                         */
  51. /*   HSTREAM hstream     handle of stream instance                          */
  52. /*   ULONG   ulFlags     Stop flags (see SSM.H)                             */
  53. /*                                                                          */
  54. /* EXIT-NORMAL: NO_ERROR (0)                                                */
  55. /*                                                                          */
  56. /* EXIT-ERROR:                                                              */
  57. /*   ERROR_DATA_ITEM_NOT_SPECIFIED                                          */
  58. /*   ERROR_INVALID_SEQUENCE                                                 */
  59. /*                                                                          */
  60. /* SIDE EFFECTS:                                                            */
  61. /*   The IO thread is unblocked.                                            */
  62. /*                                                                          */
  63. /* INTERNAL REFERENCES:                                                     */
  64. /*        ROUTINES: None                                                    */
  65. /*                                                                          */
  66. /* EXTERNAL REFERENCES:                                                     */
  67. /*   ROUTINES:                                                              */
  68. /*     ShFindSib                                                            */
  69. /*     DosResumeThread                                                      */
  70. /*     DosPostEventSem                                                      */
  71. /*                                                                          */
  72. /*   DATA STRUCTURES:                                                       */
  73. /*                                                                          */
  74. /*************************** END OF SPECIFICATIONS **************************/
  75.  
  76. RC ShcStart(pstparm)
  77. PPARM_START pstparm;
  78.  
  79. { /* Start of ShcStart */
  80.  
  81. RC rc = NO_ERROR;                       /* local return code */
  82. PSIB psib;                              /* Stream instance block */
  83. BOOL bPaused;                           /* Is stream paused? */
  84.  
  85.   /*
  86.    * Find our Stream Instance Block
  87.    */
  88.   if (!(rc = ShFindSib(&psib, pstparm->hstream, pstparm->hid)))
  89.     { /* We have SIB */
  90.       /* error if we don't have something to stream */
  91.       if (psib->ulStatus < SIB_RUNNING)
  92.         {
  93.           rc = ERROR_DATA_ITEM_NOT_SPECIFIED;
  94.         }
  95.       else
  96.         {
  97.           if (DEAD(psib))
  98.             {
  99.               rc = ERROR_INVALID_SEQUENCE;
  100.             }
  101.           else
  102.             { /* command sequence ok */
  103.  
  104.               bPaused = (psib->ulStatus == SIB_PAUSED);
  105.               psib->ulStatus = SIB_RUNNING;
  106.               if (psib->ThreadID)
  107.                 {
  108.                   DosPostEventSem(psib->hevStop);
  109.                   if (bPaused)
  110.                     {
  111.                       // PvtComment: Eventually all stream handlers that use common code should
  112.                       // PvtComment: use SYNC_SEND_MSG. At that time, get rid of the else part.
  113.                       // PvtComment: and remove the flag from makefiles.
  114. #ifdef SYNCPAUSE
  115.                       // PvtComment: Def 10814
  116.                       // PvtComment: Using semaphore wait to stop the read thread and
  117.                       // PvtComment: not suspending it. This should solve Mountain View problem
  118.                       SEND_MSG(psib,0L,0L);
  119. #else
  120.                       // PvtComment: Old mechanism
  121.                       DosResumeThread(psib->ThreadID);  //PvtComment:
  122. #endif
  123.                     }
  124.                 }
  125.             } /* command sequence ok */
  126.         }
  127.     } /* We have SIB */
  128.  
  129.   return(rc);
  130.  
  131. } /* End of ShcStart */
  132.