1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-27 08:31:16 +02:00

Build sandbox support etc. unconditionally on Linux

Also, use "#if __APPLE__" instead of "#if SANDBOX_ENABLED" to prevent
ambiguity.
This commit is contained in:
Eelco Dolstra 2015-12-03 16:30:19 +01:00
parent 7431932b29
commit 8f67325a7c
4 changed files with 24 additions and 70 deletions

View file

@ -2,14 +2,14 @@
#include "util.hh"
#include "affinity.hh"
#if HAVE_SCHED_H
#if __linux__
#include <sched.h>
#endif
namespace nix {
#if HAVE_SCHED_SETAFFINITY
#if __linux__
static bool didSaveAffinity = false;
static cpu_set_t savedAffinity;
#endif
@ -17,7 +17,7 @@ static cpu_set_t savedAffinity;
void setAffinityTo(int cpu)
{
#if HAVE_SCHED_SETAFFINITY
#if __linux__
if (sched_getaffinity(0, sizeof(cpu_set_t), &savedAffinity) == -1) return;
didSaveAffinity = true;
printMsg(lvlDebug, format("locking this thread to CPU %1%") % cpu);
@ -32,7 +32,7 @@ void setAffinityTo(int cpu)
int lockToCurrentCPU()
{
#if HAVE_SCHED_SETAFFINITY
#if __linux__
int cpu = sched_getcpu();
if (cpu != -1) setAffinityTo(cpu);
return cpu;
@ -44,7 +44,7 @@ int lockToCurrentCPU()
void restoreAffinity()
{
#if HAVE_SCHED_SETAFFINITY
#if __linux__
if (!didSaveAffinity) return;
if (sched_setaffinity(0, sizeof(cpu_set_t), &savedAffinity) == -1)
printMsg(lvlError, "failed to restore affinity %1%");