blob: 595d8a456150d2f69cbc40b30cad1aea114e3a92 [file] [log] [blame]
DRC2e7b76b2009-04-03 12:04:24 +00001/* Copyright (C)2004 Landmark Graphics Corporation
2 * Copyright (C)2005 Sun Microsystems, Inc.
3 *
4 * This library is free software and may be redistributed and/or modified under
5 * the terms of the wxWindows Library License, Version 3.1 or (at your option)
6 * any later version. The full license is in the LICENSE.txt file included
7 * with this distribution.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * wxWindows Library License for more details.
13 */
14
15#ifndef __RRUTIL_H__
16#define __RRUTIL_H__
17
18#ifdef _WIN32
19 #include <windows.h>
20 #define sleep(t) Sleep((t)*1000)
21 #define usleep(t) Sleep((t)/1000)
22#else
23 #include <unistd.h>
24 #define stricmp strcasecmp
25 #define strnicmp strncasecmp
26#endif
27
28#ifndef min
29 #define min(a,b) ((a)<(b)?(a):(b))
30#endif
31
32#ifndef max
33 #define max(a,b) ((a)>(b)?(a):(b))
34#endif
35
36#define pow2(i) (1<<(i))
37#define isPow2(x) (((x)&(x-1))==0)
38
39#ifdef sgi
40#define _SC_NPROCESSORS_CONF _SC_NPROC_CONF
41#endif
42
43#ifdef sun
44#define __inline inline
45#endif
46
47static __inline int numprocs(void)
48{
49 #ifdef _WIN32
DRC8b014d72010-02-18 13:03:41 +000050 DWORD_PTR ProcAff, SysAff; unsigned long i; int count=0;
DRC2e7b76b2009-04-03 12:04:24 +000051 if(!GetProcessAffinityMask(GetCurrentProcess(), &ProcAff, &SysAff)) return(1);
DRC8b014d72010-02-18 13:03:41 +000052 for(i=0; i<sizeof(long)*8; i++) if(ProcAff&(unsigned long)(1<<i)) count++;
DRC2e7b76b2009-04-03 12:04:24 +000053 return(count);
54 #elif defined (__APPLE__)
55 return(1);
56 #else
57 long count=1;
58 if((count=sysconf(_SC_NPROCESSORS_CONF))!=-1) return((int)count);
59 else return(1);
60 #endif
61}
62
63#define byteswap(i) ( \
64 (((i) & 0xff000000) >> 24) | \
65 (((i) & 0x00ff0000) >> 8) | \
66 (((i) & 0x0000ff00) << 8) | \
67 (((i) & 0x000000ff) << 24) )
68
69#define byteswap16(i) ( \
70 (((i) & 0xff00) >> 8) | \
71 (((i) & 0x00ff) << 8) )
72
73static __inline int littleendian(void)
74{
75 unsigned int value=1;
76 unsigned char *ptr=(unsigned char *)(&value);
77 if(ptr[0]==1 && ptr[3]==0) return 1;
78 else return 0;
79}
80
81#endif