Skip to content

Commit

Permalink
wake: backport to osx 10.10 (#269)
Browse files Browse the repository at this point in the history
  • Loading branch information
terpstra authored Sep 5, 2019
1 parent 8a2dc43 commit 1337e2b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
17 changes: 17 additions & 0 deletions src/job.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
#include <algorithm>
#include <limits>
#include <thread>
#ifdef __APPLE__
#include <mach/mach_host.h>
#include <mach/mach_init.h>
#endif

// How many times to SIGTERM a process before SIGKILL
#define TERM_ATTEMPTS 6
Expand Down Expand Up @@ -320,9 +324,22 @@ JobTable::JobTable(Database *db, double percent, bool verbose, bool quiet, bool
imp->active = 0;
imp->limit = std::thread::hardware_concurrency() * percent;
imp->phys_active = 0;

#ifdef __APPLE__
struct host_basic_info hostinfo;
mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT;
int result = host_info(mach_host_self(), HOST_BASIC_INFO, reinterpret_cast<host_info_t>(&hostinfo), &count);
if (result != KERN_SUCCESS || count != HOST_BASIC_INFO_COUNT) {
fprintf(stderr, "host_info failed\n");
exit(1);
}
imp->phys_limit = static_cast<uint64_t>(hostinfo.max_mem);
#else
imp->phys_limit = sysconf(_SC_PHYS_PAGES);
imp->phys_limit *= sysconf(_SC_PAGESIZE);
#endif
imp->phys_limit *= percent;

sigemptyset(&imp->block);

struct sigaction sa;
Expand Down
4 changes: 2 additions & 2 deletions src/regexp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ static PRIMFN(prim_extract) {
RE2_BUG(arg1);

int matches = arg0->exp->NumberOfCapturingGroups();
re2::StringPiece submatch[matches+1];
std::vector<re2::StringPiece> submatch(matches+1);
re2::StringPiece input = sp(arg1);

if (arg0->exp->Match(input, 0, input.size(), RE2::ANCHOR_BOTH, submatch, matches+1)) {
if (arg0->exp->Match(input, 0, input.size(), RE2::ANCHOR_BOTH, &submatch[0], matches+1)) {
size_t need = reserve_list(matches);
for (int i = 0; i < matches; ++i)
need += String::reserve(submatch[i+1].size());
Expand Down

0 comments on commit 1337e2b

Please sign in to comment.