extern "C" {
#endif
+/**
+ * @brief Enumeration for the tizen core cpu boosting level.
+ * @since_tizen 9.0
+ */
+typedef enum {
+ TIZEN_CORE_CPU_BOOSTING_LEVEL_NONE, /**< None level */
+ TIZEN_CORE_CPU_BOOSTING_LEVEL_STRONG, /**< Strong level */
+ TIZEN_CORE_CPU_BOOSTING_LEVEL_MEDIUM, /**< Medium level */
+ TIZEN_CORE_CPU_BOOSTING_LEVEL_WEAK, /**< Weak level */
+} tizen_core_cpu_boosting_level_e;
+
/**
* @brief Gets the glib context from the tizen core handle.
* @since_tizen 9.0
*/
void *tizen_core_get_glib_context(tizen_core_h h);
+/**
+ * @brief Sets cpu boosting level of the tizen core.
+ * @since_tizen 9.0
+ *
+ * @param[in] h The tizen core handle
+ * @param[in] level The cpu boosting level
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #TIZEN_CORE_ERROR_NONE Successful
+ * @retval #TIZEN_CORE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #TIZEN_CORE_ERROR_INVALID_CONTEXT The core is not running
+ * @see tizen_core_add_source()
+ */
+int tizen_core_set_cpu_boosting_level(tizen_core_h h,
+ tizen_core_cpu_boosting_level_e level);
+
#ifdef __cplusplus
}
#endif
return TIZEN_CORE_ERROR_NONE;
}
+API int tizen_core_set_cpu_boosting_level(tizen_core_h h,
+ tizen_core_cpu_boosting_level_e level) {
+ if (h == nullptr) {
+ _E("Invalid parameter");
+ return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+ }
+
+ auto* core = static_cast<tizen_base::tizen_core::Task*>(h);
+ if (!core->SetCpuBoostingLevel(level))
+ return TIZEN_CORE_ERROR_INVALID_CONTEXT;
+
+ return TIZEN_CORE_ERROR_NONE;
+}
+
API int tizen_core_source_create(tizen_core_source_h* h) {
if (h == nullptr) {
_E("Invalid parameter");
#include "tizen_base/task.h"
+#include <cpu-boosting.h>
#include <glib.h>
+#include <unistd.h>
#include <stdexcept>
#include <utility>
public:
EventSource(std::shared_ptr<Task> task,
std::shared_ptr<event::EventBroker<T>> broker)
- : Source(nullptr), task_(std::move(task)), broker_(std::move(broker)) {
- }
+ : Source(nullptr), task_(std::move(task)), broker_(std::move(broker)) {}
void Emit(std::shared_ptr<event::EventObject<T>> object) {
broker_->Emit(std::move(object));
auto source = task_->AddIdleJob([=]() {
- while (!broker_->Empty()) broker_->Process();
+ while (!broker_->Empty())
+ broker_->Process();
return false;
});
auto* idle_source = static_cast<IdleSource*>(source.get());
std::shared_ptr<event::EventBroker<T>> broker_;
};
+resource_cpu_boosting_level ConvertCpuBoostingLevel(
+ tizen_core_cpu_boosting_level_e level) {
+ switch (level) {
+ case TIZEN_CORE_CPU_BOOSTING_LEVEL_NONE:
+ return CPU_BOOSTING_LEVEL_NONE;
+ case TIZEN_CORE_CPU_BOOSTING_LEVEL_STRONG:
+ return CPU_BOOSTING_LEVEL_STRONG;
+ case TIZEN_CORE_CPU_BOOSTING_LEVEL_MEDIUM:
+ return CPU_BOOSTING_LEVEL_MEDIUM;
+ case TIZEN_CORE_CPU_BOOSTING_LEVEL_WEAK:
+ return CPU_BOOSTING_LEVEL_WEAK;
+ default:
+ return CPU_BOOSTING_LEVEL_NONE;
+ }
+}
+
+const char* CpuBoostingLevelToStr(tizen_core_cpu_boosting_level_e level) {
+ switch (level) {
+ case TIZEN_CORE_CPU_BOOSTING_LEVEL_NONE:
+ return "NONE";
+ case TIZEN_CORE_CPU_BOOSTING_LEVEL_STRONG:
+ return "STRONG";
+ case TIZEN_CORE_CPU_BOOSTING_LEVEL_MEDIUM:
+ return "MEDIUM";
+ case TIZEN_CORE_CPU_BOOSTING_LEVEL_WEAK:
+ return "WEAK";
+ default:
+ return "NONE";
+ }
+}
+
} // namespace
Task::Task(std::string name, bool use_thread)
}
void Task::Run() {
- if (use_thread_)
- thread_ = std::thread([&]() -> void { ThreadLoop(); });
- else
+ if (use_thread_) {
+ thread_ = std::thread([&]() -> void {
+ tid_ = gettid();
+ ThreadLoop();
+ tid_ = -1;
+ cpu_boosting_level_ = TIZEN_CORE_CPU_BOOSTING_LEVEL_NONE;
+ });
+ } else {
+ tid_ = getpid();
g_main_loop_run(loop_);
+ tid_ = -1;
+ }
}
bool Task::IsRunning() const {
}
}
+bool Task::SetCpuBoostingLevel(tizen_core_cpu_boosting_level_e level) {
+ std::lock_guard<std::recursive_mutex> lock(mutex_);
+ if (tid_ == -1) {
+ _E("Not running yet.");
+ return false;
+ }
+
+ if (cpu_boosting_level_ == level)
+ return true;
+
+ resource_pid_t res_pid = {
+ .pid = 0,
+ .tid = &tid_,
+ .tid_count = 1,
+ };
+
+ resource_cpu_boosting_level native_level = ConvertCpuBoostingLevel(level);
+ int ret = resource_set_cpu_boosting(res_pid, native_level,
+ static_cast<cpu_boosting_flag_e>(0), -1);
+ if (ret != 0) {
+ _E("Failed to set cpu boosting. ret(%d)", ret);
+ return false;
+ }
+
+ _I("Set cpu boosting level(%s -> %s).",
+ CpuBoostingLevelToStr(cpu_boosting_level_), CpuBoostingLevelToStr(level));
+ cpu_boosting_level_ = level;
+ return true;
+}
+
void Task::ThreadLoop() {
g_main_context_push_thread_default(context_->GetHandle());
g_main_loop_run(loop_);