worker api 47/180947/8
authorMichal Kolodziejski <m.kolodziejs@samsung.com>
Wed, 6 Jun 2018 13:04:06 +0000 (15:04 +0200)
committerLukasz Stanislawski <l.stanislaws@samsung.com>
Thu, 14 Jun 2018 13:05:40 +0000 (13:05 +0000)
Change-Id: Iceca258e72a95267d4ab706603183e8712756260
Signed-off-by: Michal Kolodziejski <m.kolodziejs@samsung.com>
src/task.h
src/worker.c [new file with mode: 0644]
src/worker.h [new file with mode: 0644]

index 197e158..5b6d5b0 100644 (file)
@@ -30,16 +30,6 @@ typedef int(*task_init_cb)(task_t *task);
 typedef void(*task_shutdown_cb)(task_t *task);
 
 /**
- * @brief List of possible task frequencies.
- */
-typedef enum task_frequency {
-    FREQUENCY_LOW,
-    FREQUENCY_MEDIUM,
-    FREQUENCY_HIGH,
-    FREQUENCY_NO_WAIT
-} task_frequency_e;
-
-/**
  * @brief The task template.
  */
 typedef struct task
@@ -47,7 +37,7 @@ typedef struct task
     task_init_cb init;
     task_shutdown_cb shutdown;
     task_execute_cb execute;
-    task_frequency_e frequency;
+    int frequency;
     void *user_data;
 } task_t;
 
diff --git a/src/worker.c b/src/worker.c
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/src/worker.h b/src/worker.h
new file mode 100644 (file)
index 0000000..bdd53a1
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Flora License, Version 1.1 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __WORKER_H_
+#define __WORKER_H_
+
+#include "task.h"
+
+/**
+ * @brief Worker structure.
+ */
+typedef struct worker worker_t;
+
+/**
+ * @brief Worker mode enumeration.
+ */
+typedef enum worker_mode
+{
+    /**
+     * @brief In this mode worker busy to idle proportion is low.
+     */
+    MODE_LOW,
+
+    /**
+     * @brief In this mode worker busy to idle proportion is balanced.
+     */
+    MODE_MEDIUM,
+
+    /**
+     * @brief In this mode worker busy to idle proportion is high.
+     */
+    MODE_HIGH
+} worker_mode_e;
+
+/**
+ * @brief Creates worker.
+ */
+worker_t *worker_create();
+
+/**
+ * @brief Destroys worker.
+ */
+void worker_destroy();
+
+/**
+ * @brief Sets maximum number of threads that worker can use.
+ * @param[in] worker Worker reference.
+ * @param[in] max_threads Maximum number of threads that worker can use.
+ */
+void worker_set_max_num_of_threads(worker_t *worker, int max_threads);
+
+/**
+ * @brief Adds new task to task queue.
+ * @param[in] worker Worker reference.
+ * @param[in] task Task to do.
+ */
+int worker_enqueue_task(worker_t *worker, task_t task);
+
+/**
+ * @brief Sets worker mode.
+ * @param[in] worker Worker reference.
+ */
+void worker_set_mode(worker_t *worker, worker_mode_e mode);
+
+/**
+ * @brief Gets worker mode.
+ * @param[in] worker Worker reference.
+ */
+worker_mode_e worker_get_mode(worker_t *worker);
+
+#endif
\ No newline at end of file