~rdoering/ubuntu/intrepid/erlang/fix-535090

« back to all changes in this revision

Viewing changes to erts/lib_src/common/erl_misc_utils.c

  • Committer: Bazaar Package Importer
  • Author(s): Soren Hansen
  • Date: 2007-05-01 16:57:10 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20070501165710-2sapk0hp2gf3o0ip
Tags: 1:11.b.4-2ubuntu1
* Merge with Debian Unstable. Remaining changes:
  - Add -fno-stack-protector to fix broken crypto_drv.
* DebianMaintainerField update.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#include "config.h"
21
21
#endif
22
22
 
23
 
#ifdef HAVE_UNISTD_H
24
 
# include <unistd.h>
25
 
#endif
26
 
 
27
 
#if (defined(NO_SYSCONF) || !defined(_SC_NPROCESSORS_CONF)) \
28
 
    && defined(HAVE_SYS_SYSCTL_H)
29
 
#include <sys/types.h> /* Needed on Darwin */
30
 
#include <sys/param.h> /* Needed on OpenBSD */
31
 
#include <sys/sysctl.h>
 
23
#if defined(__WIN32__)
 
24
#  include <windows.h>
 
25
#elif defined(VXWORKS)
 
26
#  include <selectLib.h>
 
27
#  include <errno.h>
 
28
#else /* UNIX */
 
29
#  include <sys/types.h>
 
30
#  include <sys/param.h>
 
31
#  ifdef SYS_SELECT_H
 
32
#    include <sys/select.h>
 
33
#  endif
 
34
#  if TIME_WITH_SYS_TIME
 
35
#     include <sys/time.h>
 
36
#     include <time.h>
 
37
#  else
 
38
#     if HAVE_SYS_TIME_H
 
39
#         include <sys/time.h>
 
40
#     else
 
41
#         include <time.h>
 
42
#     endif
 
43
#  endif
 
44
#  include <string.h>
 
45
#  ifdef HAVE_UNISTD_H
 
46
#    include <unistd.h>
 
47
#  endif
 
48
#  if (defined(NO_SYSCONF) || !defined(_SC_NPROCESSORS_CONF))
 
49
#    ifdef HAVE_SYS_SYSCTL_H
 
50
#      include <sys/sysctl.h>
 
51
#    endif
 
52
#  endif
 
53
#  include <errno.h>
32
54
#endif
33
55
 
34
56
#include "erl_misc_utils.h"
37
59
erts_no_of_cpus(void)
38
60
{
39
61
    int ncpus;
40
 
#if !defined(NO_SYSCONF) && defined(_SC_NPROCESSORS_CONF)
 
62
#ifdef __WIN32__
 
63
    SYSTEM_INFO sys_info;
 
64
    GetSystemInfo(&sys_info);
 
65
    ncpus = (int) sys_info.dwNumberOfProcessors;
 
66
#elif !defined(NO_SYSCONF) && defined(_SC_NPROCESSORS_CONF)
41
67
    ncpus = (int) sysconf(_SC_NPROCESSORS_CONF);
42
68
#elif defined(HAVE_SYS_SYSCTL_H) && defined(CTL_HW) && defined(HW_NCPU)
43
69
    {
44
70
        int mib[2] = {CTL_HW, HW_NCPU};
45
71
        size_t ncpus_len = sizeof(int);
46
72
        if (sysctl(&mib[0], 2, &ncpus, &ncpus_len, NULL, 0) < 0)
47
 
            ncpus = 1;
 
73
            ncpus = -1;
48
74
    }
49
75
#else
50
 
    ncpus = 1;
 
76
    ncpus = -1;
51
77
#endif
52
78
    return ncpus;
53
79
}
54
80
 
 
81
int
 
82
erts_milli_sleep(long ms)
 
83
{
 
84
    if (ms > 0) {
 
85
#ifdef __WIN32__
 
86
        Sleep((DWORD) ms);
 
87
#else
 
88
        struct timeval tv;
 
89
        tv.tv_sec = ms / 1000;
 
90
        tv.tv_usec = (ms % 1000) * 1000;
 
91
        if (select(0, NULL, NULL, NULL, &tv) < 0)
 
92
            return errno == EINTR ? 1 : -1;
 
93
#endif
 
94
    }
 
95
    return 0;
 
96
}