blob: 248d8834d524e5df6551850d944548af3477beba [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
24#include <pthread.h>
25#include "xcam_defs.h"
26#include "xcam_common.h"
27#include "xcam_mutex.h"
28
29namespace XCam {
30
31class Thread {
32public:
33 Thread (const char *name = NULL);
34 virtual ~Thread ();
35
36 bool start ();
37 bool stop ();
38 bool is_running ();
39
40protected:
41 // return true to start loop, else the thread stopped
42 virtual bool started ();
43 virtual void stopped ();
44 // return true to continue; false to stop
45 virtual bool loop () = 0;
46private:
47 XCAM_DEAD_COPY (Thread);
48
49
50private:
51 static int thread_func (void *user_data);
52
53private:
54 char *_name;
55 pthread_t _thread_id;
56 XCam::Mutex _mutex;
57 XCam::Cond _exit_cond;
58 bool _started;
59};
60
61};
62
63#endif //XCAM_THREAD_H