Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Osx compatibility #22

Merged
merged 5 commits into from
Oct 13, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions externals/coda-oss/modules/c++/sys/source/OSUnix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@
#include <sstream>
#include <limits.h>

#if defined(__APPLE__)

#include <sys/types.h>
#include <sys/sysctl.h>
#include <mach/vm_statistics.h>
#include <mach/mach_types.h>
#include <mach/mach_init.h>
#include <mach/mach_host.h>

#endif

#include "sys/OSUnix.h"
#include "sys/File.h"

Expand Down Expand Up @@ -275,12 +286,47 @@ size_t sysconfCaller(int name)

void sys::OSUnix::getMemInfo(size_t &totalPhysMem, size_t &freePhysMem) const
{
// Unfortunately sysctl is the best way to do this on OSX,
// but sysctl is deprecated in favor of sysconf on linux
#if defined(__APPLE__)
long long physMem = 0;
size_t size = sizeof(physMem);
int status = sysctlbyname("hw.memsize", &physMem, &size, 0, 0);
if(status)
{
throw sys::SystemException(Ctxt("Call to sysctl() has failed"));
}

mach_port_t machPort = mach_host_self();
mach_msg_type_number_t count = HOST_VM_INFO_COUNT;
vm_size_t pageSize = 0;
vm_statistics_data_t vmstat;

if(KERN_SUCCESS != host_statistics(machPort, HOST_VM_INFO,
(host_info_t) &vmstat, &count))
{
throw sys::SystemException(Ctxt("Call to host_statistics() has failed"));
}

if(KERN_SUCCESS != host_page_size(machPort, &pageSize))
{
throw sys::SystemException(Ctxt("Call to host_page_size has failed"));
}

long long freeBytes = vmstat.free_count * pageSize;

totalPhysMem = physMem / 1024 / 1024;
freePhysMem = freeBytes / 1024 / 1024;

#else
long long pageSize = sysconfCaller(_SC_PAGESIZE);
long long totalNumPages = sysconfCaller(_SC_PHYS_PAGES);
long long availNumPages = sysconfCaller(_SC_AVPHYS_PAGES);

totalPhysMem = (pageSize*totalNumPages/1024)/1024;
freePhysMem = (pageSize*availNumPages/1024)/1024;

#endif
}

void sys::DirectoryUnix::close()
Expand Down
7 changes: 7 additions & 0 deletions externals/coda-oss/modules/c++/sys/tests/OSTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ int main(int argc, char **argv)
std::cout << "The delimiter on this platform: " << os.getDelimiter()
<< std::endl;
std::cout << "The process id: " << os.getProcessId() << std::endl;

size_t freeMemory = 0;
size_t physMemory = 0;
os.getMemInfo(physMemory, freeMemory);
std::cout << "Total physical memory (MB): " << physMemory << std::endl;
std::cout << "Total free memory (MB): " << freeMemory << std::endl;

//std::cout << "The user is: " << os.getUsername() << std::endl;
/////////////////////////////////////////////
// File exists check!!!
Expand Down
4 changes: 4 additions & 0 deletions projects/csm/wscript
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ PLUGIN = 'CSM'
REMOVEPLUGINPREFIX = True

import sys, os, re
from waflib import Errors

DIRS = 'external'

Expand All @@ -22,6 +23,7 @@ def configure(conf):
linuxRegex = r'.*-.*-linux-.*|i686-pc-.*|linux'
solarisRegex = r'sparc-sun.*|i.86-pc-solaris.*|sunos'
winRegex = r'win32'
osxRegex = r'darwin'
if re.match(linuxRegex, sys.platform):
platformName = 'linux'
elif re.match(solarisRegex, sys.platform):
Expand All @@ -37,6 +39,8 @@ def configure(conf):
# For example, if you're building with VS 2008 Express, use:
# --enable-32bit "--msvc_version=msvc 9.0Exp"
platformName = 'winVC' + str(conf.env['MSVC_VERSION']).replace('.', '')
elif re.match(osxRegex,sys.platform):
platformName='darwin'
else:
raise Errors.WafError('Unsupported platform %s' % sys.platform)

Expand Down