home *** CD-ROM | disk | FTP | other *** search
/ C/C++ User's Journal & Wi…eveloper's Journal Tools / C-C__Users_Journal_and_Windows_Developers_Journal_Tools_1997.iso / smxdemo / dlm / prempt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-29  |  1.8 KB  |  76 lines

  1. /*
  2. * PREMPT.C                                                Version 2.32
  3. *
  4. * DLM. Contains code to demonstrate the preemption of disk io as a
  5. * dynamically loaded smx module.  Adapted from ddemo.c.
  6. *
  7. * Copyright (c) 1993 Micro Digital Associates, Inc. 
  8. *               All Rights Reserved.
  9. *
  10. * Authors: Ralph Moore & Ron Schow
  11. ***********************************************************************/
  12. #ifdef DLM_MOD
  13.  #include "dlm_core.h"
  14. #else
  15.  #include "core.h"
  16. #endif
  17.  
  18. #include  <stdio.h>
  19.  
  20. /* function prototypes */
  21.  
  22. #if __cplusplus
  23.  extern "C" {
  24. #endif
  25.  
  26. #ifndef DLM_MOD
  27.  void dlm_preempter_main(void);
  28. #endif
  29.  
  30. #if __cplusplus
  31. }
  32. #endif
  33.  
  34. /* variables */
  35. long     dlm_preempts;    /* preempt task run counter */
  36.  
  37. /* variables to store ptrs to smx globals */
  38. SCB_PTR  dlm_in_clib;
  39. ECB_PTR  dlm_ticks;
  40.  
  41.  
  42. /***** PREEMPTER
  43. * The purpose of this task is to test that disk i/o operations can
  44. * be preempted by tasks of various lengths. To alter the length of
  45. * operation, change the dctr initialization value.
  46. **********************************************************************/
  47.  
  48. #ifndef DLM_MOD
  49.  void _cdecl dlm_preempter_main(void)
  50. #else
  51.  void _cdecl main()
  52. #endif
  53.  
  54. {
  55.    static char  buffer[10];    /* output buffer for this task */ 
  56.    long         dctr;
  57.  
  58.    dlm_in_clib = (SCB_PTR) get_handle("in_clib");
  59.    dlm_ticks   = (ECB_PTR) get_handle("ticks");
  60.  
  61.    unlock();
  62.    dlm_preempts = 0;
  63.    
  64.    wr_string(0,9,LIGHTBLUE,BLACK,!BLINK,"PREEMPTER TASK   runs = ");
  65.    
  66.    while(count(2, dlm_ticks, INF))
  67.       {
  68.       for(dctr = 100L; dctr; dctr--);   /* delay */
  69.       test(dlm_in_clib, INF);
  70.       sprintf(buffer, "%.6ld", ++dlm_preempts);
  71.       signal(dlm_in_clib);
  72.       
  73.       wr_string(24,9,LIGHTBLUE,BLACK,!BLINK,buffer);
  74.       }
  75. }
  76.