(file) Return to cpu.h CVS log (file) (dir) Up to [OMI] / omi / pal

 1 krisbash 1.1 /*
 2              **==============================================================================
 3              **
 4              ** Open Management Infrastructure (OMI)
 5              **
 6              ** Copyright (c) Microsoft Corporation
 7              ** 
 8              ** Licensed under the Apache License, Version 2.0 (the "License"); you may not 
 9              ** use this file except in compliance with the License. You may obtain a copy 
10              ** of the License at 
11              **
12              **     http://www.apache.org/licenses/LICENSE-2.0 
13              **
14              ** THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15              ** KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 
16              ** WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 
17              ** MERCHANTABLITY OR NON-INFRINGEMENT. 
18              **
19              ** See the Apache 2 License for the specific language governing permissions 
20              ** and limitations under the License.
21              **
22 krisbash 1.1 **==============================================================================
23              */
24              
25              #ifndef _pal_cpu_h
26              #define _pal_cpu_h
27              
28              #include "palcommon.h"
29              
30              #if defined(PAL_HAVE_POSIX)
31              # include <unistd.h>
32              # include <time.h>
33              # include <sys/time.h>
34              # include <sys/types.h>
35              #endif
36              
37              PAL_BEGIN_EXTERNC
38              
39              PAL_INLINE int CPU_GetCount()
40              {
41              #if defined(_MSC_VER)
42                  SYSTEM_INFO info;
43 krisbash 1.1     GetSystemInfo(&info);
44                  return info.dwNumberOfProcessors;
45              #elif !defined(_SC_NPROCESSORS_ONLN)
46                  return 1;                           /* ATTN: Not implemented */
47              #else
48                  return sysconf(_SC_NPROCESSORS_ONLN);
49              #endif
50              }
51              
52              PAL_INLINE int CPU_GetCurrent()
53              {
54              #if defined(_MSC_VER)
55                  return GetCurrentProcessorNumber();
56              #elif defined(CONFIG_HAVE_SCHED_GETCPU)
57                  int sched_getcpu();
58                  return sched_getcpu();
59              #else
60                  /* ATTN: sched_getcpu is not implemented! */
61                  return 0;
62              #endif
63              }
64 krisbash 1.1 
65              PAL_INLINE ptrdiff_t CPU_GetTimeStamp()
66              {
67              #if defined(_MSC_VER) && defined(_ARM_)
68              	return (ptrdiff_t)(GetTickCount64() * 1000);
69              #elif defined(_MSC_VER)
70              	return (ptrdiff_t)(ReadTimeStampCounter() >> 11);
71              #else
72                  struct timeval tv;
73                  gettimeofday(&tv, NULL);
74                  return (ptrdiff_t)(tv.tv_sec * 1000000 + tv.tv_usec);
75              #endif
76              }
77              
78              _Success_(return == 0)
79              int CPU_GetLocalTimestamp(
80                  _Out_ PAL_Datetime* current);
81              
82              _Success_(return == 0)
83              int CPU_GetUtcTimestamp(
84                  _Out_ PAL_Datetime* current);
85 krisbash 1.1 
86              PAL_END_EXTERNC
87              
88              #endif /* _pal_cpu_h */

ViewCVS 0.9.2