Просмотр исходного кода

only spawn threads as necessary

rebrand
Martin Dørum 5 лет назад
Родитель
Сommit
5dd213551c
2 измененных файлов: 16 добавлений и 9 удалений
  1. 1
    1
      src/DepNode.cc
  2. 15
    8
      src/parallel.cc

+ 1
- 1
src/DepNode.cc Просмотреть файл

return; return;
} }


build_cond_.wait(lock, [=] { return build_complete_; });
build_cond_.wait(lock, [this] { return build_complete_; });
} }


void DepNode::writeCompDB(const std::string &outDir, compdb::Writer &w) { void DepNode::writeCompDB(const std::string &outDir, compdb::Writer &w) {

+ 15
- 8
src/parallel.cc Просмотреть файл

static std::unique_ptr<Worker[]> workers; static std::unique_ptr<Worker[]> workers;
static Worker *head= nullptr; static Worker *head= nullptr;
static int threads_running = 0; static int threads_running = 0;
static int max_threads = 0;
static int num_threads = 0;
static int waiting = 0; static int waiting = 0;


static void workerFunc(Worker *w) { static void workerFunc(Worker *w) {
return ParallelContext{}; return ParallelContext{};
} }


max_threads = num;
workers.reset(new Worker[num]); workers.reset(new Worker[num]);
for (int i = 0; i < num; ++i) {
Worker *w = &workers[i];
w->next_worker = head;
head = w;

w->running = true;
w->thread = std::thread(workerFunc, w);
}


// Don't spawn threads; they're spawned as needed
return ParallelContext{}; return ParallelContext{};
} }




workers.reset(); workers.reset();
head = nullptr; head = nullptr;
num_threads = 0;
max_threads = 0;
} }


void run(std::function<void(void)> func) { void run(std::function<void(void)> func) {
return; return;
} }


if (head == nullptr && num_threads < max_threads) {
Worker *w = &workers[num_threads++];
w->next_worker = head;
head = w;

w->running = true;
w->thread = std::thread(workerFunc, w);
}

waiting += 1; waiting += 1;
workers_cond.wait(lock, [] { return head != nullptr; }); workers_cond.wait(lock, [] { return head != nullptr; });
Worker *w = head; Worker *w = head;

Загрузка…
Отмена
Сохранить