4 * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
23 * email-core-task-manager.c
25 * Created on: 2012. 11. 1.
26 * Author: kyuho.jo@samsung.com
32 #include <dbus/dbus.h>
34 #include "email-internal-types.h"
35 #include "email-utilities.h"
36 #include "email-core-tasks.h"
37 #include "email-core-task-manager.h"
38 #include "email-core-signal.h"
39 #include "email-core-global.h"
40 #include "email-core-utils.h"
41 #include "email-debug-log.h"
43 /* TODO : implement a function for removing a task from task pool */
44 /* TODO : after fetching a task from DB, update status of the task. */
47 #define REGISTER_TASK_BINDER(TASK_NAME) emcore_register_task_handler(TASK_NAME, task_handler_##TASK_NAME, email_encode_task_parameter_##TASK_NAME, email_decode_task_parameter_##TASK_NAME)
49 /*- variables - begin --------------------------------------------------------*/
50 static pthread_cond_t _task_available_signal = PTHREAD_COND_INITIALIZER;
51 static pthread_mutex_t _task_available_lock = PTHREAD_MUTEX_INITIALIZER;
52 static pthread_mutex_t _task_manager_loop_lock = PTHREAD_MUTEX_INITIALIZER;
53 static pthread_mutex_t _active_task_pool_lock = PTHREAD_MUTEX_INITIALIZER;
55 static email_active_task_t _active_task_pool[MAX_ACTIVE_TASK];
56 static thread_t _thread_task_manager_loop;
57 static int _task_manager_loop_availability = 1;
58 /*- variables - end ----------------------------------------------------------*/
59 static int emcore_insert_task_to_active_task_pool(int input_task_slot_index, int input_task_id, email_task_type_t input_task_type, thread_t input_thread_id);
60 static int emcore_remove_task_from_active_task_pool(int input_task_id);
61 static int emcore_find_available_slot_in_active_task_pool(int *result_index);
62 static int emcore_update_task_status_on_task_table(char *multi_user_name, int input_task_id, email_task_status_type_t task_status);
63 static int emcore_get_task_handler_reference(email_task_type_t input_task_type, email_task_handler_t **output_task_handler);
65 /*- task handlers helpers - begin --------------------------------------------*/
66 static int emcore_initialize_async_task_handler(email_task_t *input_task)
68 EM_DEBUG_FUNC_BEGIN("input_task [%p]", input_task);
69 int err = EMAIL_ERROR_NONE;
71 if (input_task == NULL) {
72 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
73 err = EMAIL_ERROR_INVALID_PARAM;
77 /* insert task to _active_task_pool */
78 emcore_insert_task_to_active_task_pool(input_task->active_task_id
80 , input_task->task_type
83 /* send notification for 'task start */
84 if ((err = emcore_send_task_status_signal(input_task->task_type, input_task->task_id, EMAIL_TASK_STATUS_STARTED, EMAIL_ERROR_NONE, 0)) != EMAIL_ERROR_NONE) {
85 EM_DEBUG_EXCEPTION("emcore_send_task_status_signal failed [%d]", err);
91 EM_DEBUG_FUNC_END("err [%d]", err);
95 static int emcore_finalize_async_task_handler(email_task_t *input_task, int input_error_code)
97 EM_DEBUG_FUNC_BEGIN("input_task [%p] input_error_code [%d]", input_task, input_error_code);
98 int err = EMAIL_ERROR_NONE;
99 email_task_status_type_t task_status = EMAIL_TASK_STATUS_FINISHED;
101 if (input_task == NULL) {
102 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
103 err = EMAIL_ERROR_INVALID_PARAM;
107 if (input_error_code != EMAIL_ERROR_NONE) {
108 task_status = EMAIL_TASK_STATUS_FAILED;
111 /* remove task from task table */
112 if ((err = emcore_remove_task_from_task_table(NULL, input_task->task_id)) != EMAIL_ERROR_NONE) {
113 EM_DEBUG_EXCEPTION("emcore_remove_task_from_active_task_pool failed [%d]", err);
117 /* remove task id from active task id array */
118 if ((err = emcore_remove_task_from_active_task_pool(input_task->task_id)) != EMAIL_ERROR_NONE) {
119 EM_DEBUG_EXCEPTION("emcore_remove_task_from_active_task_pool failed [%d]", err);
123 /* send signal for 'task finish or failure */
124 if ((err = emcore_send_task_status_signal(input_task->task_type, input_task->task_id, task_status, input_error_code, 0)) != EMAIL_ERROR_NONE) {
125 EM_DEBUG_EXCEPTION("emcore_send_task_status_signal failed [%d]", err);
129 ENTER_CRITICAL_SECTION(_task_available_lock);
130 WAKE_CONDITION_VARIABLE(_task_available_signal);
131 LEAVE_CRITICAL_SECTION(_task_available_lock);
134 EM_DEBUG_FUNC_END("err [%d]", err);
138 INTERNAL_FUNC void* emcore_default_async_task_handler(void *input_param)
140 EM_DEBUG_FUNC_BEGIN("intput_param [%p]", input_param);
141 int err = EMAIL_ERROR_NONE;
142 email_task_t *task = input_param;
143 email_task_handler_t *task_handler = NULL;
144 void *decoded_task_parameter = NULL;
146 if ((err = emcore_initialize_async_task_handler(task)) != EMAIL_ERROR_NONE) {
147 EM_DEBUG_EXCEPTION("emcore_initialize_async_task_handler failed. [%d]", err);
151 /* create a thread to do this task */
152 if ((err = emcore_get_task_handler_reference(task->task_type, &task_handler)) != EMAIL_ERROR_NONE) {
153 EM_DEBUG_LOG("emcore_get_task_handler_reference returns [%d]", err);
155 /* Decode parameter */
156 emcore_decode_task_parameter(task->task_type,
157 task->task_parameter,
158 task->task_parameter_length,
159 &decoded_task_parameter);
161 task_handler->task_handler_function(decoded_task_parameter);
166 emcore_finalize_async_task_handler(task, err);
168 EM_DEBUG_FUNC_END("err [%d]", err);
172 INTERNAL_FUNC int emcore_default_sync_task_handler(void *intput_param)
174 EM_DEBUG_FUNC_BEGIN("intput_param [%p]", intput_param);
175 int err = EMAIL_ERROR_NONE;
176 int *return_err = NULL;
177 email_task_t *task = intput_param;
178 email_task_handler_t *task_handler = NULL;
179 void *decoded_task_parameter = NULL;
181 /* create a thread to do this task */
182 if ((err = emcore_get_task_handler_reference(task->task_type, &task_handler)) != EMAIL_ERROR_NONE) {
183 EM_DEBUG_LOG("emcore_get_task_handler_reference returns [%d]", err);
185 /* Decode parameter */
186 emcore_decode_task_parameter(task->task_type,
187 task->task_parameter,
188 task->task_parameter_length,
189 &decoded_task_parameter);
191 return_err = (int *)task_handler->task_handler_function(decoded_task_parameter);
199 EM_DEBUG_FUNC_END("err [%d]", err);
202 /*- task handlers helpers - end --------------------------------------------*/
204 int _task_handler_array_size;
205 email_task_handler_t **_task_handler_array;
207 static int emcore_register_task_handler(email_task_type_t input_task_type,
208 void* (*input_task_handler)(void *),
209 int (*input_task_parameter_encoder)(void*, char**, int*),
210 int (*input_task_parameter_decoder)(char*, int, void**))
212 EM_DEBUG_FUNC_BEGIN("input_task_type [%d] input_task_handler [%p] "
213 "input_task_parameter_encoder [%p] input_task_parameter_decoder [%p]",
214 input_task_type, input_task_handler,
215 input_task_parameter_encoder, input_task_parameter_decoder);
217 int err = EMAIL_ERROR_NONE;
218 email_task_handler_t *new_task_handler = NULL;
220 new_task_handler = malloc(sizeof(email_task_handler_t));
222 if (new_task_handler == NULL) {
223 err = EMAIL_ERROR_OUT_OF_MEMORY;
224 EM_DEBUG_EXCEPTION("EMAIL_ERROR_OUT_OF_MEMORY");
228 new_task_handler->task_type = input_task_type;
229 new_task_handler->task_handler_function = input_task_handler;
230 new_task_handler->task_parameter_encoder = input_task_parameter_encoder;
231 new_task_handler->task_parameter_decoder = input_task_parameter_decoder;
233 _task_handler_array_size++;
235 if (_task_handler_array) {
237 email_task_handler_t **_new_task_handler_array = NULL;
239 _new_task_handler_array = realloc(_task_handler_array, sizeof(email_task_handler_t*) * _task_handler_array_size);
240 if (NULL == _new_task_handler_array) {
241 EM_DEBUG_EXCEPTION("memory reallocation failed");
242 err = EMAIL_ERROR_OUT_OF_MEMORY;
243 EM_SAFE_FREE(new_task_handler);
244 EM_SAFE_FREE(_task_handler_array);
248 _task_handler_array = _new_task_handler_array;
250 _task_handler_array = malloc(sizeof(email_task_handler_t*) * _task_handler_array_size);
252 if (_task_handler_array == NULL) {
253 err = EMAIL_ERROR_OUT_OF_MEMORY;
254 EM_SAFE_FREE(new_task_handler);
260 _task_handler_array[_task_handler_array_size - 1] = new_task_handler;
264 EM_DEBUG_FUNC_END("err [%d]", err);
268 INTERNAL_FUNC int emcore_init_task_handler_array()
270 EM_DEBUG_FUNC_BEGIN();
272 if (_task_handler_array == NULL) {
273 _task_handler_array = NULL;
274 _task_handler_array_size = 0;
276 REGISTER_TASK_BINDER(EMAIL_ASYNC_TASK_MOVE_MAILS_TO_MAILBOX_OF_ANOTHER_ACCOUNT);
277 REGISTER_TASK_BINDER(EMAIL_ASYNC_TASK_DELETE_MAILBOX_EX);
278 REGISTER_TASK_BINDER(EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL);
279 REGISTER_TASK_BINDER(EMAIL_SYNC_TASK_SCHEDULE_SENDING_MAIL);
280 REGISTER_TASK_BINDER(EMAIL_SYNC_TASK_UPDATE_ATTRIBUTE);
284 return EMAIL_ERROR_NONE;
287 INTERNAL_FUNC int emcore_free_task_handler_array()
289 EM_DEBUG_FUNC_BEGIN();
293 for (i = 0; i < _task_handler_array_size; i++) {
294 EM_SAFE_FREE(_task_handler_array[i]);
297 EM_SAFE_FREE(_task_handler_array);
298 _task_handler_array_size = 0;
301 return EMAIL_ERROR_NONE;
304 static int emcore_get_task_handler_reference(email_task_type_t input_task_type, email_task_handler_t **output_task_handler)
306 EM_DEBUG_FUNC_BEGIN("input_task_type [%d] output_task_handler [%p]", input_task_type, output_task_handler);
308 int err = EMAIL_ERROR_NONE;
310 if (output_task_handler == NULL) {
311 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
312 err = EMAIL_ERROR_INVALID_PARAM;
316 *output_task_handler = NULL;
317 for (i = 0; i < _task_handler_array_size; i++) {
318 if (_task_handler_array[i]->task_type == input_task_type) {
319 *output_task_handler = _task_handler_array[i];
324 if (*output_task_handler == NULL) {
325 EM_DEBUG_EXCEPTION("EMAIL_ERROR_TASK_BINDER_NOT_FOUND");
326 err = EMAIL_ERROR_TASK_BINDER_NOT_FOUND;
331 EM_DEBUG_FUNC_END("err [%d]", err);
335 INTERNAL_FUNC int emcore_encode_task_parameter(email_task_type_t input_task_type, void *input_task_parameter_struct, char **output_byte_stream, int *output_stream_size)
337 EM_DEBUG_FUNC_BEGIN("input_task_type [%d] input_task_parameter_struct [%p] output_byte_stream [%p] output_stream_size [%p]", input_task_type, input_task_parameter_struct, output_byte_stream, output_stream_size);
338 int err = EMAIL_ERROR_NONE;
339 email_task_handler_t *task_handler = NULL;
340 int (*task_parameter_encoder)(void*, char**, int*);
342 if (input_task_parameter_struct == NULL || output_byte_stream == NULL || output_stream_size == NULL) {
343 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
344 err = EMAIL_ERROR_INVALID_PARAM;
348 if ((err = emcore_get_task_handler_reference(input_task_type, &task_handler)) != EMAIL_ERROR_NONE) {
349 EM_DEBUG_EXCEPTION("emcore_get_task_handler_reference failed [%d]", err);
353 task_parameter_encoder = task_handler->task_parameter_encoder;
355 if ((err = task_parameter_encoder(input_task_parameter_struct, output_byte_stream, output_stream_size)) != EMAIL_ERROR_NONE) {
356 EM_DEBUG_EXCEPTION("task_parameter_encoder failed [%d]", err);
361 EM_DEBUG_FUNC_END("err [%d]", err);
365 INTERNAL_FUNC int emcore_decode_task_parameter(email_task_type_t input_task_type, char *input_byte_stream, int input_stream_size, void **output_task_parameter_struct)
367 EM_DEBUG_FUNC_BEGIN("input_task_type [%d] input_byte_stream [%p] input_stream_size [%d] output_task_parameter_struct [%p]", input_task_type, input_byte_stream, input_stream_size, output_task_parameter_struct);
368 int err = EMAIL_ERROR_NONE;
369 email_task_handler_t *task_handler = NULL;
370 int (*task_parameter_decoder)(char*, int, void**);
372 if (input_byte_stream == NULL || output_task_parameter_struct == NULL) {
373 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
374 err = EMAIL_ERROR_INVALID_PARAM;
378 if ((err = emcore_get_task_handler_reference(input_task_type, &task_handler)) != EMAIL_ERROR_NONE) {
379 EM_DEBUG_EXCEPTION("emcore_get_task_handler_reference failed [%d]", err);
383 task_parameter_decoder = task_handler->task_parameter_decoder;
385 if ((err = task_parameter_decoder(input_byte_stream,
387 output_task_parameter_struct)) != EMAIL_ERROR_NONE) {
388 EM_DEBUG_EXCEPTION("task_parameter_decoder failed [%d]", err);
393 EM_DEBUG_FUNC_END("err [%d]", err);
397 int emcore_fetch_task_from_task_pool(email_task_t **output_task)
399 EM_DEBUG_FUNC_BEGIN("output_task [%p]", output_task);
400 int err = EMAIL_ERROR_NONE;
401 int output_task_count;
403 if ((err = emstorage_query_task(NULL,
404 "WHERE task_status == 1",
405 "ORDER BY date_time ASC, task_priority ASC LIMIT 0, 1",
407 &output_task_count)) != EMAIL_ERROR_NONE) {
408 EM_DEBUG_EXCEPTION("emstorage_query_task failed [%d]", err);
414 EM_DEBUG_FUNC_END("err [%d]", err);
419 /*-Task manager loop - begin -------------------------------------------------------------*/
422 static int emcore_insert_task_to_active_task_pool(int input_task_slot_index, int input_task_id, email_task_type_t input_task_type, thread_t input_thread_id)
424 EM_DEBUG_FUNC_BEGIN("input_task_slot_index [%d] input_task_id [%d] input_task_type [%d] input_thread_id [%d]", input_task_slot_index, input_task_id, input_task_type, input_thread_id);
425 int err = EMAIL_ERROR_NONE;
427 ENTER_CRITICAL_SECTION(_active_task_pool_lock);
428 _active_task_pool[input_task_slot_index].task_id = input_task_id;
429 _active_task_pool[input_task_slot_index].task_type = input_task_type;
430 _active_task_pool[input_task_slot_index].thread_id = input_thread_id;
431 LEAVE_CRITICAL_SECTION(_active_task_pool_lock);
433 EM_DEBUG_LOG("_active_task_pool[%d].task_id [%d]", input_task_slot_index, _active_task_pool[input_task_slot_index].task_id);
435 EM_DEBUG_FUNC_END("err [%d]", err);
439 static int emcore_remove_task_from_active_task_pool(int input_task_id)
441 EM_DEBUG_FUNC_BEGIN(" input_task_id [%d]", input_task_id);
442 int err = EMAIL_ERROR_NONE;
445 ENTER_CRITICAL_SECTION(_active_task_pool_lock);
446 for (i = 0; i < MAX_ACTIVE_TASK; i++) {
447 if (_active_task_pool[i].task_id == input_task_id) {
448 _active_task_pool[i].task_id = 0;
449 _active_task_pool[i].task_type = 0;
450 _active_task_pool[i].thread_id = 0;
454 LEAVE_CRITICAL_SECTION(_active_task_pool_lock);
456 if (i >= MAX_ACTIVE_TASK) {
457 EM_DEBUG_LOG("couldn't find proper task in active task pool [%d]", input_task_id);
458 err = EMAIL_ERROR_TASK_NOT_FOUND;
461 EM_DEBUG_FUNC_END("err [%d]", err);
465 INTERNAL_FUNC int emcore_get_active_task_by_thread_id(thread_t input_thread_id, email_active_task_t **output_active_task)
467 EM_DEBUG_FUNC_BEGIN(" input_thread_id [%d] output_active_task [%p]", input_thread_id, output_active_task);
468 int err = EMAIL_ERROR_NONE;
471 if (output_active_task == NULL) {
472 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
473 err = EMAIL_ERROR_INVALID_PARAM;
477 for (i = 0; i < MAX_ACTIVE_TASK; i++) {
478 if (_active_task_pool[i].thread_id == input_thread_id) {
479 *output_active_task = _active_task_pool + i;
484 if (i >= MAX_ACTIVE_TASK) {
485 EM_DEBUG_LOG("couldn't find proper task in active task pool [%lu]", input_thread_id);
486 err = EMAIL_ERROR_TASK_NOT_FOUND;
491 EM_DEBUG_FUNC_END("err [%d]", err);
496 static int emcore_find_available_slot_in_active_task_pool(int *result_index)
498 EM_DEBUG_FUNC_BEGIN("result_index [%p]", result_index);
500 int err = EMAIL_ERROR_NONE;
502 if (result_index == NULL) {
503 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
504 err = EMAIL_ERROR_INVALID_PARAM;
508 ENTER_CRITICAL_SECTION(_active_task_pool_lock);
509 for (i = 0; i < MAX_ACTIVE_TASK; i++) {
510 if (_active_task_pool[i].task_id == 0) {
515 if (i >= MAX_ACTIVE_TASK) {
516 EM_DEBUG_EXCEPTION("There is no available task slot");
517 err = EMAIL_NO_AVAILABLE_TASK_SLOT;
519 _active_task_pool[i].task_id = -1;
522 LEAVE_CRITICAL_SECTION(_active_task_pool_lock);
525 EM_DEBUG_FUNC_END("err [%d]", err);
529 void* thread_func_task_manager_loop(void *arg)
531 EM_DEBUG_FUNC_BEGIN();
532 int err = EMAIL_ERROR_NONE;
534 int available_slot_index = 0;
535 email_task_t *new_task = NULL;
538 while (_task_manager_loop_availability) {
539 /* fetch task from DB */
540 if (((err = emcore_fetch_task_from_task_pool(&new_task)) == EMAIL_ERROR_NONE) &&
541 ((err = emcore_find_available_slot_in_active_task_pool(&available_slot_index)) == EMAIL_ERROR_NONE)) {
543 /* update task status as STARTED */
544 if ((err = emcore_update_task_status_on_task_table(NULL, new_task->task_id, EMAIL_TASK_STATUS_STARTED)) != EMAIL_ERROR_NONE) {
545 EM_DEBUG_EXCEPTION("emcore_update_task_status_on_task_table failed [%d]", err);
547 new_task->active_task_id = available_slot_index;
549 /* create a thread to do this task */
550 THREAD_CREATE(new_task->thread_id, emcore_default_async_task_handler, new_task, thread_error);
551 EM_DEBUG_LOG("pthread_create returns [%d]", thread_error);
553 /* new_task and task_parameter will be free in task handler. */
554 EM_SAFE_FREE(new_task->task_parameter);
555 EM_SAFE_FREE(new_task);
557 /* If there is no task or no available slot, sleep until someone wake you up. */
558 /* Wake up case 1 : by emcore_add_task_to_task_table */
559 /* Wake up case 2 : when some task terminated */
560 ENTER_CRITICAL_SECTION(_task_available_lock);
561 SLEEP_CONDITION_VARIABLE(_task_available_signal, _task_available_lock);
562 LEAVE_CRITICAL_SECTION(_task_available_lock);
563 EM_DEBUG_LOG("thread_func_task_manager_loop wake up!");
571 INTERNAL_FUNC int emcore_start_task_manager_loop()
573 EM_DEBUG_FUNC_BEGIN();
575 int err = EMAIL_ERROR_NONE;
577 memset(&_active_task_pool, 0, sizeof(email_active_task_t) * MAX_ACTIVE_TASK);
579 if (_thread_task_manager_loop) {
580 EM_DEBUG_EXCEPTION("service thread is already running...");
581 err = EMAIL_ERROR_ALREADY_INITIALIZED;
585 _task_manager_loop_availability = 10;
588 THREAD_CREATE(_thread_task_manager_loop, thread_func_task_manager_loop, NULL, thread_error);
590 if (thread_error != 0) {
591 EM_DEBUG_EXCEPTION("cannot create thread [%d]", thread_error);
592 err = EMAIL_ERROR_SYSTEM_FAILURE;
598 EM_DEBUG_FUNC_END("err [%d]", err);
602 INTERNAL_FUNC int emcore_stop_task_manager_loop()
604 EM_DEBUG_FUNC_BEGIN();
606 int err = EMAIL_ERROR_NONE;
608 if (!_thread_task_manager_loop) {
609 EM_DEBUG_LOG("_thread_task_manager_loop is NULL ");
610 err = EMAIL_ERROR_UNKNOWN;
614 /* TODO : cancel tasks */
616 /* stop event_data loop */
617 _task_manager_loop_availability = 0;
619 ENTER_CRITICAL_SECTION(_task_manager_loop_lock);
620 WAKE_CONDITION_VARIABLE(_task_available_signal);
621 LEAVE_CRITICAL_SECTION(_task_manager_loop_lock);
623 /* wait for thread finished */
624 THREAD_JOIN(_thread_task_manager_loop);
626 _thread_task_manager_loop = 0;
628 DELETE_CRITICAL_SECTION(_task_manager_loop_lock);
629 DELETE_CONDITION_VARIABLE(_task_available_signal);
631 /* Free _active_task_pool */
635 EM_DEBUG_FUNC_END("err [%d]", err);
639 INTERNAL_FUNC int emcore_add_task_to_task_table(char *multi_user_name, email_task_type_t input_task_type, email_task_priority_t input_task_priority, char *input_task_parameter, int input_task_parameter_length, int *output_task_id)
641 EM_DEBUG_FUNC_BEGIN("input_task_type [%d] input_task_priority [%d] input_task_parameter [%p] input_task_parameter_length [%d] output_task_id [%p]", input_task_type, input_task_priority, input_task_parameter, input_task_parameter_length, output_task_id);
642 int err = EMAIL_ERROR_NONE;
644 if ((err = emstorage_add_task(multi_user_name, input_task_type, input_task_priority, input_task_parameter, input_task_parameter_length, false, output_task_id)) != EMAIL_ERROR_NONE) {
645 EM_DEBUG_EXCEPTION("emstorage_add_task failed [%d]", err);
649 ENTER_CRITICAL_SECTION(_task_available_lock);
650 WAKE_CONDITION_VARIABLE(_task_available_signal);
651 LEAVE_CRITICAL_SECTION(_task_available_lock);
654 EM_DEBUG_FUNC_END("err [%d]", err);
658 INTERNAL_FUNC int emcore_remove_task_from_task_table(char *multi_user_name, int input_task_id)
660 EM_DEBUG_FUNC_BEGIN("input_task_id [%d]", input_task_id);
661 int err = EMAIL_ERROR_NONE;
663 if ((err = emstorage_delete_task(multi_user_name, input_task_id, true)) != EMAIL_ERROR_NONE) {
664 EM_DEBUG_EXCEPTION("emstorage_delete_task failed [%d]", err);
669 EM_DEBUG_FUNC_END("err [%d]", err);
673 static int emcore_update_task_status_on_task_table(char *multi_user_name, int input_task_id, email_task_status_type_t task_status)
675 EM_DEBUG_FUNC_BEGIN("input_task_id [%d] task_status [%d]", input_task_id, task_status);
676 int err = EMAIL_ERROR_NONE;
678 if ((err = emstorage_update_task_status(multi_user_name, input_task_id, task_status, true)) != EMAIL_ERROR_NONE) {
679 EM_DEBUG_EXCEPTION("emstorage_update_task_status failed [%d]", err);
684 EM_DEBUG_FUNC_END("err [%d]", err);
688 /*-Task manager loop - end-------------------------------------------------------------*/