|
| 1 | +/******************************************************************************** |
| 2 | + * Copyright (c) 2026 Contributors to the Eclipse Foundation |
| 3 | + * |
| 4 | + * See the NOTICE file(s) distributed with this work for additional |
| 5 | + * information regarding copyright ownership. |
| 6 | + * |
| 7 | + * This program and the accompanying materials are made available under the |
| 8 | + * terms of the Apache License Version 2.0 which is available at |
| 9 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * SPDX-License-Identifier: Apache-2.0 |
| 12 | + ********************************************************************************/ |
| 13 | +#ifndef SCORE_HM_THREAD_H |
| 14 | +#define SCORE_HM_THREAD_H |
| 15 | + |
| 16 | +#include "common.h" |
| 17 | +#include <cstdint> |
| 18 | +#include <vector> |
| 19 | + |
| 20 | +namespace score::hm |
| 21 | +{ |
| 22 | + |
| 23 | +class HealthMonitorBuilder; |
| 24 | + |
| 25 | +/// Scheduler policy. |
| 26 | +enum class SchedulerPolicy : int32_t |
| 27 | +{ |
| 28 | + Other, |
| 29 | + Fifo, |
| 30 | + RoundRobin, |
| 31 | +}; |
| 32 | + |
| 33 | +/// Get min thread priority for given policy. |
| 34 | +int32_t scheduler_policy_priority_min(SchedulerPolicy scheduler_policy); |
| 35 | + |
| 36 | +/// Get max thread priority for given policy. |
| 37 | +int32_t scheduler_policy_priority_max(SchedulerPolicy scheduler_policy); |
| 38 | + |
| 39 | +class SchedulerParameters final |
| 40 | +{ |
| 41 | + public: |
| 42 | + /// Create a new `SchedulerParameters`. |
| 43 | + /// Priority must be in allowed range for the scheduler policy. |
| 44 | + SchedulerParameters(SchedulerPolicy policy, int32_t priority); |
| 45 | + |
| 46 | + /// Scheduler policy. |
| 47 | + SchedulerPolicy policy() const; |
| 48 | + |
| 49 | + /// Thread priority. |
| 50 | + int32_t priority() const; |
| 51 | + |
| 52 | + private: |
| 53 | + SchedulerPolicy policy_; |
| 54 | + int32_t priority_; |
| 55 | +}; |
| 56 | + |
| 57 | +/// Thread parameters. |
| 58 | +class ThreadParameters final : public internal::RustDroppable<ThreadParameters> |
| 59 | +{ |
| 60 | + public: |
| 61 | + /// Create a new `ThreadParameters` containing default values. |
| 62 | + ThreadParameters(); |
| 63 | + |
| 64 | + /// Scheduler parameters, including scheduler policy and thread priority. |
| 65 | + ThreadParameters scheduler_parameters(SchedulerParameters scheduler_parameters) &&; |
| 66 | + |
| 67 | + /// Set thread affinity - array of CPU core IDs that the thread can run on. |
| 68 | + ThreadParameters affinity(const std::vector<size_t>& affinity) &&; |
| 69 | + |
| 70 | + /// Set stack size. |
| 71 | + ThreadParameters stack_size(size_t stack_size) &&; |
| 72 | + |
| 73 | + protected: |
| 74 | + std::optional<internal::FFIHandle> _drop_by_rust_impl() |
| 75 | + { |
| 76 | + return thread_parameters_handle_.drop_by_rust(); |
| 77 | + } |
| 78 | + |
| 79 | + private: |
| 80 | + internal::DroppableFFIHandle thread_parameters_handle_; |
| 81 | + |
| 82 | + // Allow to hide `drop_by_rust` implementation. |
| 83 | + friend class internal::RustDroppable<ThreadParameters>; |
| 84 | + |
| 85 | + // Allow `HealthMonitorBuilder` to access `drop_by_rust` implementation. |
| 86 | + friend class score::hm::HealthMonitorBuilder; |
| 87 | +}; |
| 88 | + |
| 89 | +} // namespace score::hm |
| 90 | + |
| 91 | +#endif // SCORE_HM_THREAD_H |
0 commit comments