LCOV - app.info - nsprpub/pr/src/misc/prinrval.c

LCOV - code coverage report
| Current view: | directory - nsprpub/pr/src/misc - prinrval.c (source / functions) |  | Found | Hit | Coverage |
| Test: | app.info | Lines: | 55 | 55 | 100.0 %
| Date: | 2012-06-02 | Functions: | 9 | 9 | 100.0 %

           1                 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
           2                 : /* ***** BEGIN LICENSE BLOCK *****
           3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
           4                 :  *
           5                 :  * The contents of this file are subject to the Mozilla Public License Version
           6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
           7                 :  * the License. You may obtain a copy of the License at
           8                 :  * http://www.mozilla.org/MPL/
           9                 :  *
          10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
          11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
          12                 :  * for the specific language governing rights and limitations under the
          13                 :  * License.
          14                 :  *
          15                 :  * The Original Code is the Netscape Portable Runtime (NSPR).
          16                 :  *
          17                 :  * The Initial Developer of the Original Code is
          18                 :  * Netscape Communications Corporation.
          19                 :  * Portions created by the Initial Developer are Copyright (C) 1998-2000
          20                 :  * the Initial Developer. All Rights Reserved.
          21                 :  *
          22                 :  * Contributor(s):
          23                 :  *
          24                 :  * Alternatively, the contents of this file may be used under the terms of
          25                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
          26                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
          27                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
          28                 :  * of those above. If you wish to allow use of your version of this file only
          29                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
          30                 :  * use your version of this file under the terms of the MPL, indicate your
          31                 :  * decision by deleting the provisions above and replace them with the notice
          32                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
          33                 :  * the provisions above, a recipient may use your version of this file under
          34                 :  * the terms of any one of the MPL, the GPL or the LGPL.
          35                 :  *
          36                 :  * ***** END LICENSE BLOCK ***** */
          37                 :
          38                 : /*
          39                 :  * file:                        prinrval.c
          40                 :  * description:         implementation for the kernel interval timing functions
          41                 :  */
          42                 :
          43                 : #include "primpl.h"
          44                 :
          45                 : /*
          46                 :  *-----------------------------------------------------------------------
          47                 :  *
          48                 :  * _PR_InitClock --
          49                 :  *
          50                 :  *
          51                 :  *-----------------------------------------------------------------------
          52                 :  */
          53                 :
          54           20034 : void _PR_InitClock(void)
          55                 : {
          56                 :     _PR_MD_INTERVAL_INIT();
          57                 : #ifdef DEBUG
          58                 :     {
          59           20034 :         PRIntervalTime ticksPerSec = PR_TicksPerSecond();
          60                 :
          61           20034 :         PR_ASSERT(ticksPerSec >= PR_INTERVAL_MIN);
          62           20034 :         PR_ASSERT(ticksPerSec <= PR_INTERVAL_MAX);
          63                 :     }
          64                 : #endif /* DEBUG */
          65           20034 : }
          66                 :
          67                 : /*
          68                 :  * This version of interval times is based on the time of day
          69                 :  * capability offered by system. This isn't valid for two reasons:
          70                 :  * 1) The time of day is neither linear nor montonically increasing
          71                 :  * 2) The units here are milliseconds. That's not appropriate for our use.
          72                 :  */
          73                 :
          74          930201 : PR_IMPLEMENT(PRIntervalTime) PR_IntervalNow(void)
          75                 : {
          76          930201 :     if (!_pr_initialized) _PR_ImplicitInitialization();
          77          930201 :     return _PR_MD_GET_INTERVAL();
          78                 : }  /* PR_IntervalNow */
          79                 :
          80          541774 : PR_EXTERN(PRUint32) PR_TicksPerSecond(void)
          81                 : {
          82          541774 :     if (!_pr_initialized) _PR_ImplicitInitialization();
          83          541774 :     return _PR_MD_INTERVAL_PER_SEC();
          84                 : }  /* PR_TicksPerSecond */
          85                 :
          86           72129 : PR_IMPLEMENT(PRIntervalTime) PR_SecondsToInterval(PRUint32 seconds)
          87                 : {
          88           72129 :     return seconds * PR_TicksPerSecond();
          89                 : }  /* PR_SecondsToInterval */
          90                 :
          91          203413 : PR_IMPLEMENT(PRIntervalTime) PR_MillisecondsToInterval(PRUint32 milli)
          92                 : {
          93                 :     PRIntervalTime ticks;
          94                 :     PRUint64 tock, tps, msecPerSec, rounding;
          95          203413 :     LL_UI2L(tock, milli);
          96          203413 :     LL_I2L(msecPerSec, PR_MSEC_PER_SEC);
          97          203413 :     LL_I2L(rounding, (PR_MSEC_PER_SEC >> 1));
          98          203413 :     LL_I2L(tps, PR_TicksPerSecond());
          99          203413 :     LL_MUL(tock, tock, tps);
         100          203413 :     LL_ADD(tock, tock, rounding);
         101          203413 :     LL_DIV(tock, tock, msecPerSec);
         102          203413 :     LL_L2UI(ticks, tock);
         103          203413 :     return ticks;
         104                 : }  /* PR_MillisecondsToInterval */
         105                 :
         106           47469 : PR_IMPLEMENT(PRIntervalTime) PR_MicrosecondsToInterval(PRUint32 micro)
         107                 : {
         108                 :     PRIntervalTime ticks;
         109                 :     PRUint64 tock, tps, usecPerSec, rounding;
         110           47469 :     LL_UI2L(tock, micro);
         111           47469 :     LL_I2L(usecPerSec, PR_USEC_PER_SEC);
         112           47469 :     LL_I2L(rounding, (PR_USEC_PER_SEC >> 1));
         113           47469 :     LL_I2L(tps, PR_TicksPerSecond());
         114           47469 :     LL_MUL(tock, tock, tps);
         115           47469 :     LL_ADD(tock, tock, rounding);
         116           47469 :     LL_DIV(tock, tock, usecPerSec);
         117           47469 :     LL_L2UI(ticks, tock);
         118           47469 :     return ticks;
         119                 : }  /* PR_MicrosecondsToInterval */
         120                 :
         121           61511 : PR_IMPLEMENT(PRUint32) PR_IntervalToSeconds(PRIntervalTime ticks)
         122                 : {
         123           61511 :     return ticks / PR_TicksPerSecond();
         124                 : }  /* PR_IntervalToSeconds */
         125                 :
         126           61536 : PR_IMPLEMENT(PRUint32) PR_IntervalToMilliseconds(PRIntervalTime ticks)
         127                 : {
         128                 :     PRUint32 milli;
         129                 :     PRUint64 tock, tps, msecPerSec, rounding;
         130           61536 :     LL_UI2L(tock, ticks);
         131           61536 :     LL_I2L(msecPerSec, PR_MSEC_PER_SEC);
         132           61536 :     LL_I2L(tps, PR_TicksPerSecond());
         133           61536 :     LL_USHR(rounding, tps, 1);
         134           61536 :     LL_MUL(tock, tock, msecPerSec);
         135           61536 :     LL_ADD(tock, tock, rounding);
         136           61536 :     LL_DIV(tock, tock, tps);
         137           61536 :     LL_L2UI(milli, tock);
         138           61536 :     return milli;
         139                 : }  /* PR_IntervalToMilliseconds */
         140                 :
         141           36642 : PR_IMPLEMENT(PRUint32) PR_IntervalToMicroseconds(PRIntervalTime ticks)
         142                 : {
         143                 :     PRUint32 micro;
         144                 :     PRUint64 tock, tps, usecPerSec, rounding;
         145           36642 :     LL_UI2L(tock, ticks);
         146           36642 :     LL_I2L(usecPerSec, PR_USEC_PER_SEC);
         147           36642 :     LL_I2L(tps, PR_TicksPerSecond());
         148           36642 :     LL_USHR(rounding, tps, 1);
         149           36642 :     LL_MUL(tock, tock, usecPerSec);
         150           36642 :     LL_ADD(tock, tock, rounding);
         151           36642 :     LL_DIV(tock, tock, tps);
         152           36642 :     LL_L2UI(micro, tock);
         153           36642 :     return micro;
         154                 : }  /* PR_IntervalToMicroseconds */
         155                 :
         156                 : /* prinrval.c */
         157                 :

Generated by: LCOV version 1.7