tbb_task.cpp 1.37 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
#include "pls/internal/scheduling/tbb_task.h"

namespace pls {
    namespace internal {
        namespace scheduling {
            tbb_sub_task::tbb_sub_task(tbb_sub_task *parent, class tbb_task *tbb_task):
                    ref_count_{0},
                    parent_{parent},
                    tbb_task_{tbb_task} {
                parent->ref_count_++;
            }

            tbb_sub_task::~tbb_sub_task()  {
                wait_for_all();
            }

            void tbb_sub_task::execute()  {
                execute_internal();
                wait_for_all();
            }

            tbb_sub_task* tbb_sub_task::get_local_task() {
                // TODO: get a task from the bottom of our sub-task queue
            }

            void tbb_sub_task::wait_for_all() {
                while (ref_count_ > 0) {
                    tbb_sub_task* local_task = get_local_task();
                    if (local_task != nullptr) {
                        local_task->execute();
                        continue;
                    } else {
                        // Try to steal work.
                        // External steal will be executed explicitly
                        if (tbb_task_->steal_work()) {
                            // TODO: Internal Success, execute stolen task
                        }
                    }
                }
            }
        }
    }
}