1 /* 2 * thread.h, thread class 3 * 4 * Copyright (c) 2009-2010 Wind River Systems, Inc. 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 19 #ifndef __THREAD_H 20 #define __THREAD_H 21 22 #include <pthread.h> 23 24 class RunnableInterface { 25 public: RunnableInterface()26 RunnableInterface() {}; ~RunnableInterface()27 virtual ~RunnableInterface() {}; 28 29 virtual void Run(void) = 0; 30 }; 31 32 class Thread : public RunnableInterface { 33 public: 34 Thread(); 35 Thread(RunnableInterface *r); 36 ~Thread(); 37 38 int Start(void); 39 int Join(void); 40 41 protected: 42 /* 43 * overriden by the derived class 44 * when the class is derived from Thread class 45 */ 46 virtual void Run(void); 47 48 private: 49 static void *Instance(void *); 50 51 RunnableInterface *r; 52 pthread_t id; 53 bool created; 54 55 pthread_mutex_t lock; 56 }; 57 58 #endif /* __THREAD_H */ 59