-
Notifications
You must be signed in to change notification settings - Fork 3
/
cl-cpus-win32.lisp
67 lines (56 loc) · 1.91 KB
/
cl-cpus-win32.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
(in-package :cl-cpus)
(cffi:define-foreign-library kernel32
(:windows "C:/WINDOWS/system32/kernel32.dll"))
(cffi:use-foreign-library kernel32)
;; C++ Syntax from https://msdn.microsoft.com/en-us/library/windows/desktop/ms724958(v=vs.85).aspx
;; typedef struct _SYSTEM_INFO {
;; union {
;; DWORD dwOemId;
;; struct {
;; WORD wProcessorArchitecture;
;; WORD wReserved;
;; };
;; };
;; DWORD dwPageSize;
;; LPVOID lpMinimumApplicationAddress;
;; LPVOID lpMaximumApplicationAddress;
;; DWORD_PTR dwActiveProcessorMask;
;; DWORD dwNumberOfProcessors;
;; DWORD dwProcessorType;
;; DWORD dwAllocationGranularity;
;; WORD wProcessorLevel;
;; WORD wProcessorRevision;
;; } SYSTEM_INFO;
(cffi:defctype dword :unsigned-long)
(cffi:defctype word :unsigned-short)
(cffi:defcstruct processor-struct
(processor-architecture word)
(reserved word))
(cffi:defcunion oem-union
(oem-ide dword)
(processor-struct (:struct processor-struct)))
(cffi:defcstruct system-info
(oem-info (:union oem-union))
(page-size dword)
(minimum-application-address :pointer)
(maximum-application-address :pointer)
(active-processor-mask (:pointer dword))
(number-of-processors dword)
(processor-type dword)
(allocation-granularity dword)
(processor-level word)
(processor-revision word))
;; C++ Syntax from https://msdn.microsoft.com/en-us/library/windows/desktop/ms724381(v=vs.85).aspx
;; void WINAPI GetSystemInfo(
;; _Out_ LPSYSTEM_INFO lpSystemInfo
;; );
(cffi:defcfun ("GetSystemInfo" get-system-info) :void
(data (:pointer (:struct system-info))))
(defvar *number-of-processors*
(cffi:with-foreign-object (info '(:struct system-info))
(get-system-info info)
(cffi:foreign-slot-value info '(:struct system-info)
'number-of-processors)))
(defun get-number-of-processors ()
"Get CPU Threads count."
*number-of-processors*)