Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /* NetWare can not use this implementation of clock, since it does not
  2.    have times or any similar function.  It provides its own version of
  3.    clock in clib.nlm.  If we can not use clib.nlm, then we must write
  4.    clock in sys/netware.  */
  5.  
  6. #ifdef CLOCK_PROVIDED
  7.  
  8. int _dummy_clock = 1;
  9.  
  10. #else
  11.  
  12. /*
  13.  * clock.c
  14.  * Original Author:     G. Haley
  15.  *
  16.  * Determines the processor time used by the program since invocation. The time
  17.  * in seconds is the value returned divided by the value of the macro CLK_TCK.
  18.  * If the processor time used is not available, (clock_t) -1 is returned.
  19.  */
  20.  
  21. /*
  22. FUNCTION
  23. <<clock>>---cumulative processor time
  24.  
  25. INDEX
  26.         clock
  27.  
  28. ANSI_SYNOPSIS
  29.         #include <time.h>
  30.         clock_t clock(void);
  31.  
  32. TRAD_SYNOPSIS
  33.         #include <time.h>
  34.         clock_t clock();
  35.  
  36. DESCRIPTION
  37. Calculates the best available approximation of the cumulative amount
  38. of time used by your program since it started.  To convert the result
  39. into seconds, divide by the macro <<CLOCKS_PER_SEC>>.
  40.  
  41. RETURNS
  42. The amount of processor time used so far by your program, in units
  43. defined by the machine-dependent macro <<CLOCKS_PER_SEC>>.  If no
  44. measurement is available, the result is (clock_t)<<-1>>.
  45.  
  46. PORTABILITY
  47. ANSI C requires <<clock>> and <<CLOCKS_PER_SEC>>.
  48.  
  49. Supporting OS subroutine required: <<times>>.
  50. */
  51.  
  52. #include <time.h>
  53. #include <sys/times.h>
  54. #include <reent.h>
  55.  
  56.  
  57. clock_t
  58. _DEFUN (_times_r, (ptr, ptms),
  59.      struct _reent *ptr _AND
  60.      struct tms *ptms)
  61. {
  62.   return -1;
  63. }
  64.  
  65. clock_t
  66. clock ()
  67. {
  68.   struct tms tim_s;
  69.   clock_t res;
  70.  
  71.   if ((res = (clock_t) _times_r (_REENT, &tim_s)) != -1)
  72.     res = (clock_t) (tim_s.tms_utime + tim_s.tms_stime +
  73.                      tim_s.tms_cutime + tim_s.tms_cstime);
  74.  
  75.   return res;
  76. }
  77.  
  78. #endif /* CLOCK_PROVIDED */
  79.