summaryrefslogtreecommitdiff
path: root/util/systeminfo_win32.cpp
blob: 19c182878eec7fe0df5fe7998b25e2983dbfcc02 (plain)
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
/**
 * Copyright (c) 2011 10gen Inc.
 *
 * This program is free software: you can redistribute it and/or  modify
 * it under the terms of the GNU Affero General Public License, version 3,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "pch.h"
#include "util/systeminfo.h"

#include <windows.h>

namespace mongo {

    size_t SystemInfo::getPhysicalRam() {
	/*
	  The value of this should not be changing while the system is running,
	  so it should be safe to do this once for the lifetime of the
	  application.

	  This could present a race condition if multiple threads do this at
	  the same time, but all paths through here will produce the same
	  result, so it's not worth locking or worrying about it.
	 */
	static bool unknown = true;
	static size_t ramSize = 0;

	if (unknown) {
	    MEMORYSTATUSEX status;
	    status.dwLength = sizeof(status);
	    GlobalMemoryStatusEx(&status);
	    ramSize = static_cast<size_t>(status.ullTotalPhys);
	    unknown = false;
	}

	return ramSize;
    }

}