| 17 | namespace py = pybind11; |
| 18 | |
| 19 | PYBIND11_MODULE(pycgraph, cg) { |
| 20 | cg.doc() = "CGraph with python api, github: https://github.com/ChunelFeng/CGraph"; |
| 21 | |
| 22 | py::class_<UThreadPoolConfig>(cg, "UThreadPoolConfig") |
| 23 | .def(py::init<>()) |
| 24 | .def_readwrite("default_thread_size", &UThreadPoolConfig::default_thread_size_) |
| 25 | .def_readwrite("secondary_thread_size", &UThreadPoolConfig::secondary_thread_size_) |
| 26 | .def_readwrite("max_thread_size", &UThreadPoolConfig::max_thread_size_) |
| 27 | .def_readwrite("max_task_steal_range", &UThreadPoolConfig::max_task_steal_range_) |
| 28 | .def_readwrite("max_local_batch_size", &UThreadPoolConfig::max_local_batch_size_) |
| 29 | .def_readwrite("max_pool_batch_size", &UThreadPoolConfig::max_pool_batch_size_) |
| 30 | .def_readwrite("max_steal_batch_size", &UThreadPoolConfig::max_steal_batch_size_) |
| 31 | .def_readwrite("primary_thread_busy_epoch", &UThreadPoolConfig::primary_thread_busy_epoch_) |
| 32 | .def_readwrite("primary_thread_empty_interval", &UThreadPoolConfig::primary_thread_empty_interval_) |
| 33 | .def_readwrite("secondary_thread_ttl", &UThreadPoolConfig::secondary_thread_ttl_) |
| 34 | .def_readwrite("monitor_span", &UThreadPoolConfig::monitor_span_) |
| 35 | .def_readwrite("queue_empty_interval", &UThreadPoolConfig::queue_emtpy_interval_) |
| 36 | .def_readwrite("primary_thread_policy", &UThreadPoolConfig::primary_thread_policy_) |
| 37 | .def_readwrite("secondary_thread_policy", &UThreadPoolConfig::secondary_thread_policy_) |
| 38 | .def_readwrite("primary_thread_priority", &UThreadPoolConfig::primary_thread_priority_) |
| 39 | .def_readwrite("secondary_thread_priority", &UThreadPoolConfig::secondary_thread_priority_) |
| 40 | .def_readwrite("bind_cpu_enable", &UThreadPoolConfig::bind_cpu_enable_) |
| 41 | .def_readwrite("batch_task_enable", &UThreadPoolConfig::batch_task_enable_) |
| 42 | .def_readwrite("monitor_enable", &UThreadPoolConfig::monitor_enable_); |
| 43 | |
| 44 | py::class_<GElementRelation>(cg, "GElementRelation") |
| 45 | .def(py::init<>()) |
| 46 | .def_readonly("predecessors", &GElementRelation::predecessors_) |
| 47 | .def_readonly("successors", &GElementRelation::successors_) |
| 48 | .def_readonly("children", &GElementRelation::children_) |
| 49 | .def_readonly("belong", &GElementRelation::belong_); |
| 50 | |
| 51 | py::class_<UThreadPool>(cg, "UThreadPool") |
| 52 | .def(py::init<CBool, const UThreadPoolConfig&>(), |
| 53 | py::arg("autoInit") = true, |
| 54 | py::arg("config") = UThreadPoolConfig{}) |
| 55 | .def("setConfig", &UThreadPool::setConfig, |
| 56 | py::arg("config"), |
| 57 | py::keep_alive<1, 2>()) |
| 58 | .def("getConfig", &UThreadPool::getConfig) |
| 59 | .def("init", &UThreadPool::init) |
| 60 | .def("destroy", &UThreadPool::destroy) |
| 61 | .def("isInit", &UThreadPool::isInit); |
| 62 | |
| 63 | py::register_exception<CException>(cg, "CException"); |
| 64 | |
| 65 | py::enum_<GEngineType>(cg, "GEngineType") |
| 66 | .value("DYNAMIC", GEngineType::DYNAMIC) |
| 67 | .value("TOPO", GEngineType::TOPO) |
| 68 | .value("STATIC", GEngineType::STATIC) |
| 69 | .export_values(); |
| 70 | |
| 71 | py::enum_<GElementTimeoutStrategy>(cg, "GElementTimeoutStrategy") |
| 72 | .value("AS_ERROR", GElementTimeoutStrategy::AS_ERROR) |
| 73 | .value("HOLD_BY_PIPELINE", GElementTimeoutStrategy::HOLD_BY_PIPELINE) |
| 74 | .value("NO_HOLD", GElementTimeoutStrategy::NO_HOLD) |
| 75 | .export_values(); |
| 76 | |