blob: fdb8382d8f059dbc4a90daf76ca410fdc75a880d [file] [log] [blame]
Wind Yuan75564b12015-01-15 06:51:15 -05001/*
2 * xcam_thread.h - Thread
3 *
4 * Copyright (c) 2014 Intel Corporation
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 * Author: Wind Yuan <feng.yuan@intel.com>
19 */
20
21#ifndef XCAM_THREAD_H
22#define XCAM_THREAD_H
23
Wind Yuan8810a792015-01-22 15:20:23 +080024#include "xcam_utils.h"
Wind Yuan75564b12015-01-15 06:51:15 -050025#include "xcam_mutex.h"
26
27namespace XCam {
28
29class Thread {
30public:
31 Thread (const char *name = NULL);
32 virtual ~Thread ();
33
34 bool start ();
35 bool stop ();
36 bool is_running ();
37
38protected:
39 // return true to start loop, else the thread stopped
40 virtual bool started ();
41 virtual void stopped ();
42 // return true to continue; false to stop
43 virtual bool loop () = 0;
44private:
45 XCAM_DEAD_COPY (Thread);
46
47
48private:
49 static int thread_func (void *user_data);
50
51private:
52 char *_name;
53 pthread_t _thread_id;
54 XCam::Mutex _mutex;
55 XCam::Cond _exit_cond;
56 bool _started;
57};
58
59};
60
61#endif //XCAM_THREAD_H