Statistics
| Branch: | Revision:

root / src / common / commonutil.cc @ e1750c09

History | View | Annotate | Download (1.44 KB)

1
//=========================================================================
2
//  COMMONUTIL.CC - part of
3
//                  OMNeT++/OMNEST
4
//           Discrete System Simulation in C++
5
//
6
//  Author: Andras Varga
7
//
8
//=========================================================================
9

    
10
/*--------------------------------------------------------------*
11
  Copyright (C) 2006-2008 OpenSim Ltd.
12

13
  This file is distributed WITHOUT ANY WARRANTY. See the file
14
  `license' for details on this and other legal matters.
15
*--------------------------------------------------------------*/
16

    
17
#include <stdio.h>
18
#include <stdarg.h>
19
#include <locale.h>
20
#include "commonutil.h"
21

    
22
USING_NAMESPACE
23

    
24

    
25
static double zero = 0.0;
26
double const NaN = zero / zero;
27
double const POSITIVE_INFINITY = 1.0 / zero;
28
double const NEGATIVE_INFINITY = -1.0 / zero;
29

    
30
//----
31

    
32
void setPosixLocale()
33
{
34
    setlocale(LC_ALL, "C");
35
}
36

    
37
//----
38

    
39
int DebugCall::depth;
40

    
41
DebugCall::DebugCall(const char *fmt,...)
42
{
43
    char buf[1024];
44
    VSNPRINTF(buf, 1024, fmt);
45
    funcname = buf;
46
    printf("%*s ++ %s\n", depth++*2, "", funcname.c_str());
47
}
48

    
49
DebugCall::~DebugCall()
50
{
51
    printf("%*s -- %s\n", --depth*2, "", funcname.c_str());
52
}
53

    
54
//----
55

    
56
#ifdef _MSC_VER
57
// source: http://en.wikipedia.org/wiki/RDTSC
58
__declspec(naked)
59
uint64 __cdecl readCPUTimeStampCounter()
60
{
61
   __asm
62
   {
63
      rdtsc
64
      ret       ; return value at EDX:EAX
65
   }
66
}
67
#else
68
uint64 readCPUTimeStampCounter()
69
{
70
    return 0;
71
}
72
#endif
73

    
74