Add LCOV remarkers to increase line coverage rate
[platform/core/api/maps-service.git] / src / session / thread.cpp
1 /* Copyright (c) 2010-2014 Samsung Electronics Co., Ltd. All rights reserved.
2  *
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <unistd.h>
18 #include "thread.h"
19 #include "command_queue.h"
20 #include "command.h"
21
22 //LCOV_EXCL_START
23 session::thread::thread()
24 {
25 }
26
27 session::thread::~thread()
28 {
29 }
30
31 /* Thread function: pops the item from the queue and performs the command */
32 void *session::thread::queue_thread(void *data)
33 {
34         sleep(0);               /* Just switch the thread to accomplish previous
35                                    initialization routines */
36
37         if (!data)
38                 return NULL;
39         plugin::plugin_s *p = (plugin::plugin_s *) data;
40
41         command_queue *cq = session::command_queue::interface();
42         while (p->is_working)
43                 cq->process(p); /* Continuously perform queue processing */
44
45         return NULL;
46 }
47
48 void session::thread::run(plugin::plugin_s *p)
49 {
50         if (!p)
51                 return;
52         if (p->thread)
53                 return;         /* Check whether the thread is already started, */
54         /* Start if needed */
55
56         p->is_working = true;
57
58         p->thread = g_thread_new("queue_thread", &queue_thread, p);
59         if(p->thread)
60                 g_thread_unref(p->thread);
61 }
62
63 void session::thread::stop(plugin::plugin_s *p)
64 {
65         if (!p)
66                 return;
67
68         p->is_working = false;
69
70         command_queue *cq = session::command_queue::interface();
71         cq->clear(p);
72 }
73 //LCOV_EXCL_STOP