Modify cpu boosting api 87/307387/3
authorChanggyu Choi <changyu.choi@samsung.com>
Fri, 8 Mar 2024 01:49:41 +0000 (10:49 +0900)
committerChanggyu Choi <changyu.choi@samsung.com>
Fri, 8 Mar 2024 03:56:39 +0000 (12:56 +0900)
Adds:
 - tizen_core_clear_cpu_boosting()

Modifies:
 - tizen_core_set_cpu_boosting_level()
   -> tizen_core_set_cpu_boosting()

Change-Id: I26a583e68a4710a4316b982b5c78c1c352998143
Signed-off-by: Changgyu Choi <changyu.choi@samsung.com>
include/tizen_core_internal.h
tizen_base/stub.cc
tizen_base/task.cc
tizen_base/task.h

index 86b85e44f1e90bfc22d39a3d6026907c9a3f2c7c..e62d5876ae5b97861abc33c99ffcfb39129f83cc 100644 (file)
@@ -38,27 +38,81 @@ typedef enum {
  * @brief Gets the glib context from the tizen core handle.
  * @since_tizen 9.0
  *
- * @param[in] h The tizen core handle
+ * @param[in] core The tizen core handle
  * @return @c the glib context on success,
  *         otherwise a nullptr
  */
-void *tizen_core_get_glib_context(tizen_core_h h);
+void *tizen_core_get_glib_context(tizen_core_h core);
 
 /**
- * @brief Sets cpu boosting level of the tizen core.
+ * @brief Sets cpu boosting of the tizen core.
  * @since_tizen 9.0
  *
- * @param[in] h The tizen core handle
+ * @param[in] core 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()
+ *
+ * @code
+#include <tizen_core_internal.h>
+{
+  tizen_core_h core = NULL;
+  int ret;
+
+  ret = tizen_core_find("main", &core);
+  if (ret != TIZEN_CORE_ERROR_NONE) {
+    return -1;
+  }
+
+  ret = tizen_core_set_cpu_boosting(core, TIZEN_CORE_CPU_BOOSTING_LEVEL_STRONG);
+  if (ret != TIZEN_CORE_ERROR_NONE) {
+    return -1;
+  }
+
+  return 0;
+}
+ * @endcode
+ * @see tizen_core_clear_cpu_boosting()
+ */
+int tizen_core_set_cpu_boosting(tizen_core_h core,
+                                tizen_core_cpu_boosting_level_e level);
+
+/**
+ * @brief Clears cpu boosting of the tizen core.
+ * @since_tizen 9.0
+ *
+ * @param[in] core The tizen core handle
+ * @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
+ *
+ * @code
+#include <tizen_core_internal.h>
+{
+  tizen_core_h core = NULL;
+  int ret;
+
+  ret = tizen_core_find("main", &core);
+  if (ret != TIZEN_CORE_ERROR_NONE) {
+    return -1;
+  }
+
+  ret = tizen_core_clear_cpu_boosting(core);
+  if (ret != TIZEN_CORE_ERROR_NONE) {
+    return -1;
+  }
+
+  return 0;
+}
+ * @endcode
+ * @see tizen_core_set_cpu_boosting()
  */
-int tizen_core_set_cpu_boosting_level(tizen_core_h h,
-                                      tizen_core_cpu_boosting_level_e level);
+int tizen_core_clear_cpu_boosting(tizen_core_h core);
 
 #ifdef __cplusplus
 }
index ea24de41ba266788e278f0f7478d066515b4fa8f..773c805d5d522a3220dd31620f1b9f8991c04829 100644 (file)
@@ -372,7 +372,7 @@ API int tizen_core_remove_source(tizen_core_h core,
   return TIZEN_CORE_ERROR_NONE;
 }
 
-API int tizen_core_set_cpu_boosting_level(
+API int tizen_core_set_cpu_boosting(
     tizen_core_h core, tizen_core_cpu_boosting_level_e level) {
   if (core == nullptr) {
     _E("Invalid parameter");
@@ -380,7 +380,20 @@ API int tizen_core_set_cpu_boosting_level(
   }
 
   auto* task = static_cast<tizen_base::tizen_core::Task*>(core);
-  if (!task->SetCpuBoostingLevel(level))
+  if (!task->SetCpuBoosting(level))
+    return TIZEN_CORE_ERROR_INVALID_CONTEXT;
+
+  return TIZEN_CORE_ERROR_NONE;
+}
+
+API int tizen_core_clear_cpu_boosting(tizen_core_h core) {
+  if (core == nullptr) {
+    _E("Invalid parameter");
+    return TIZEN_CORE_ERROR_INVALID_PARAMETER;
+  }
+
+  auto* task = static_cast<tizen_base::tizen_core::Task*>(core);
+  if (!task->ClearCpuBoosting())
     return TIZEN_CORE_ERROR_INVALID_CONTEXT;
 
   return TIZEN_CORE_ERROR_NONE;
index 4b6abf1e2384bd6b9cdf059c231f0196d49070cf..d09b8585b46c74f5c20a40a1811989de25701cbc 100644 (file)
@@ -273,7 +273,7 @@ void Task::EmitEvent(std::shared_ptr<event::EventObject<T>> object) {
   }
 }
 
-bool Task::SetCpuBoostingLevel(tizen_core_cpu_boosting_level_e level) {
+bool Task::SetCpuBoosting(tizen_core_cpu_boosting_level_e level) {
   std::lock_guard<std::recursive_mutex> lock(mutex_);
   if (tid_ == -1) {
     _E("Not running yet.");
@@ -303,6 +303,30 @@ bool Task::SetCpuBoostingLevel(tizen_core_cpu_boosting_level_e level) {
   return true;
 }
 
+bool Task::ClearCpuBoosting() {
+  std::lock_guard<std::recursive_mutex> lock(mutex_);
+  if (tid_ == -1) {
+    _E("Not running yet.");
+    return false;
+  }
+
+  resource_pid_t res_pid = {
+      .pid = 0,
+      .tid = &tid_,
+      .tid_count = 1,
+  };
+
+  int ret = resource_clear_cpu_boosting(res_pid);
+  if (ret != 0) {
+    _E("Failed to set cpu boosting. ret(%d)", ret);
+    return false;
+  }
+
+  _I("Clear cpu boosting");
+  cpu_boosting_level_ = TIZEN_CORE_CPU_BOOSTING_LEVEL_NONE;
+  return true;
+}
+
 void Task::ThreadLoop() {
   g_main_context_push_thread_default(context_->GetHandle());
   g_main_loop_run(loop_);
index 0f5f3f45d7508f8fc509cdd93e275279b46559b5..8c8683046ff16730fbca9e1684d1d4c795338e1b 100644 (file)
@@ -74,7 +74,8 @@ class EXPORT_API Task : public ILoop,
   template <typename T>
   void EmitEvent(std::shared_ptr<event::EventObject<T>> object);
 
-  bool SetCpuBoostingLevel(tizen_core_cpu_boosting_level_e level);
+  bool SetCpuBoosting(tizen_core_cpu_boosting_level_e level);
+  bool ClearCpuBoosting();
 
   void AddEventSource(std::shared_ptr<ISource> source);
   void RemoveEventSource(std::shared_ptr<ISource> source);