Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
edolstra committed Jun 19, 2024
1 parent 576a03e commit 52bd994
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 43 deletions.
4 changes: 2 additions & 2 deletions src/libexpr/parallel-eval.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ static std::array<Sync<WaiterDomain>, 128> waiterDomains;

static Sync<WaiterDomain> & getWaiterDomain(Value & v)
{
//auto domain = std::hash<Value *>{}(&v) % waiterDomains.size();
auto domain = (((size_t) &v) >> 5) % waiterDomains.size();
debug("HASH %x -> %d", &v, domain);
return waiterDomains[domain];
Expand Down Expand Up @@ -40,7 +39,8 @@ InternalType EvalState::waitOnThunk(Value & v, bool awaited)
} else {
/* Mark this value as being waited on. */
auto type = tPending;
if (!v.internalType.compare_exchange_strong(type, tAwaited, std::memory_order_relaxed, std::memory_order_acquire)) {
if (!v.internalType.compare_exchange_strong(
type, tAwaited, std::memory_order_relaxed, std::memory_order_acquire)) {
/* If the value has been finalized in the meantime (i.e. is
no longer pending), we're done. */
if (type != tAwaited) {
Expand Down
40 changes: 11 additions & 29 deletions src/libexpr/parallel-eval.hh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "util.hh"

#if HAVE_BOEHMGC
#include <gc.h>
# include <gc.h>
#endif

namespace nix {
Expand All @@ -26,8 +26,6 @@ struct Executor
work_t work;
};

//std::future<void> enqueue(work_t work);

struct State
{
std::multimap<uint64_t, Item> queue;
Expand All @@ -45,17 +43,16 @@ struct Executor
debug("executor using %d threads", nrCores);
auto state(state_.lock());
for (size_t n = 0; n < nrCores; ++n)
state->threads.push_back(std::thread([&]()
{
#if HAVE_BOEHMGC
state->threads.push_back(std::thread([&]() {
#if HAVE_BOEHMGC
GC_stack_base sb;
GC_get_stack_base(&sb);
GC_register_my_thread(&sb);
#endif
#endif
worker();
#if HAVE_BOEHMGC
#if HAVE_BOEHMGC
GC_unregister_my_thread();
#endif
#endif
}));
}

Expand All @@ -82,7 +79,8 @@ struct Executor

while (true) {
auto state(state_.lock());
if (state->quit) return;
if (state->quit)
return;
if (!state->queue.empty()) {
item = std::move(state->queue.begin()->second);
state->queue.erase(state->queue.begin());
Expand All @@ -102,12 +100,8 @@ struct Executor

std::vector<std::future<void>> spawn(std::vector<std::pair<work_t, uint8_t>> && items)
{
if (items.empty()) return {};

/*
auto item = std::move(items.back());
items.pop_back();
*/
if (items.empty())
return {};

std::vector<std::future<void>> futures;

Expand All @@ -119,24 +113,12 @@ struct Executor
thread_local std::random_device rd;
thread_local std::uniform_int_distribution<uint64_t> dist(0, 1ULL << 48);
auto key = (uint64_t(item.second) << 48) | dist(rd);
state->queue.emplace(
key,
Item {
.promise = std::move(promise),
.work = std::move(item.first)
});
state->queue.emplace(key, Item{.promise = std::move(promise), .work = std::move(item.first)});
}
}

wakeup.notify_all(); // FIXME

//item();

/*
for (auto & future : futures)
future.get();
*/

return futures;
}
};
Expand Down
7 changes: 4 additions & 3 deletions src/libexpr/symbol-table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ Symbol SymbolTable::create(std::string_view s)
{
auto symbols(symbolDomains[domain].read());
auto it = symbols->find(s);
if (it != symbols->end()) return Symbol(it->second);
if (it != symbols->end())
return Symbol(it->second);
}

// Most symbols are looked up more than once, so we trade off insertion performance
Expand All @@ -44,7 +45,8 @@ Symbol SymbolTable::create(std::string_view s)
// on the original implementation using unordered_set
auto symbols(symbolDomains[domain].lock());
auto it = symbols->find(s);
if (it != symbols->end()) return Symbol(it->second);
if (it != symbols->end())
return Symbol(it->second);

// Atomically allocate space for the symbol in the arena.
auto id = arena.allocate(s.size() + 1);
Expand All @@ -65,5 +67,4 @@ size_t SymbolTable::size() const
return res;
}


}
16 changes: 8 additions & 8 deletions tests/unit/libexpr/nix_api_expr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ TEST_F(nix_api_expr_test, nix_expr_eval_add_numbers)

TEST_F(nix_api_expr_test, nix_expr_eval_drv)
{
#if 0
#if 0
auto expr = R"(derivation { name = "myname"; builder = "mybuilder"; system = "mysystem"; })";
nix_expr_eval_from_string(nullptr, state, expr, ".", value);
ASSERT_EQ(NIX_TYPE_ATTRS, nix_get_type(nullptr, value));
Expand All @@ -60,7 +60,7 @@ TEST_F(nix_api_expr_test, nix_expr_eval_drv)

nix_gc_decref(nullptr, valueResult);
nix_state_free(stateResult);
#endif
#endif
}

TEST_F(nix_api_expr_test, nix_build_drv)
Expand Down Expand Up @@ -98,11 +98,11 @@ TEST_F(nix_api_expr_test, nix_build_drv)
StorePath * outStorePath = nix_store_parse_path(ctx, store, outPath.c_str());
ASSERT_EQ(false, nix_store_is_valid_path(ctx, store, outStorePath));

#if 0
#if 0
nix_store_realise(ctx, store, drvStorePath, nullptr, nullptr);
auto is_valid_path = nix_store_is_valid_path(ctx, store, outStorePath);
ASSERT_EQ(true, is_valid_path);
#endif
#endif

// Clean up
nix_store_path_free(drvStorePath);
Expand Down Expand Up @@ -131,17 +131,17 @@ TEST_F(nix_api_expr_test, nix_expr_realise_context_bad_build)
)";
nix_expr_eval_from_string(ctx, state, expr, ".", value);
assert_ctx_ok();
#if 0
#if 0
auto r = nix_string_realise(ctx, state, value, false);
ASSERT_EQ(nullptr, r);
ASSERT_EQ(ctx->last_err_code, NIX_ERR_NIX_ERROR);
ASSERT_THAT(ctx->last_err, testing::Optional(testing::HasSubstr("failed with exit code 1")));
#endif
#endif
}

TEST_F(nix_api_expr_test, nix_expr_realise_context)
{
#if 0
#if 0
// TODO (ca-derivations): add a content-addressed derivation output, which produces a placeholder
auto expr = R"(
''
Expand Down Expand Up @@ -196,7 +196,7 @@ TEST_F(nix_api_expr_test, nix_expr_realise_context)
EXPECT_THAT(names[2], testing::StrEq("not-actually-built-yet.drv"));

nix_realised_string_free(r);
#endif
#endif
}

const char * SAMPLE_USER_DATA = "whatever";
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/libexpr/value/value.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ TEST_F(ValueTest, unsetValue)
{
Value unsetValue;
ASSERT_EQ(false, unsetValue.isValid());
//ASSERT_DEATH(unsetValue.type(), "");
// ASSERT_DEATH(unsetValue.type(), "");
}

TEST_F(ValueTest, vInt)
Expand Down

0 comments on commit 52bd994

Please sign in to comment.