Thread.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2005 Palmsource, Inc.
00003  * 
00004  * This software is licensed as described in the file LICENSE, which
00005  * you should have received as part of this distribution. The terms
00006  * are also available at http://www.openbinder.org/license.html.
00007  * 
00008  * This software consists of voluntary contributions made by many
00009  * individuals. For the exact contribution history, see the revision
00010  * history and logs, available at http://www.openbinder.org
00011  */
00012 
00013 #ifndef _SUPPORT_THREAD_H_
00014 #define _SUPPORT_THREAD_H_
00015 
00021 #include <support/Atom.h>
00022 #include <support/Locker.h>
00023 
00024 #if _SUPPORTS_NAMESPACE
00025 namespace palmos {
00026 namespace support {
00027 #endif
00028 
00033 /*-------------------------------------------------------------*/
00034 /*------- SThread Implementation ------------------------------*/
00035 
00037 
00045 class SThread : public virtual SAtom
00046 {
00047 public:
00048 
00049                                 SThread();
00050 
00052 
00055     virtual status_t            Run(const char* name, int32_t priority, size_t stackSize);
00056 
00058 
00061     virtual void                RequestExit();
00063             void                WaitForExit();
00064 
00065 protected:
00066     virtual                     ~SThread();
00067 
00069     
00081     virtual bool                ThreadEntry() = 0;
00083     virtual status_t            AboutToRun(SysHandle thread);
00084 
00086             bool                ExitRequested() const;
00087 
00088 private:
00089 #if TARGET_HOST == TARGET_HOST_PALMOS
00090     static  void                top_entry(void* object);
00091 #else
00092     static  int32_t             top_entry(void* object);
00093 #endif
00094 
00095             status_t            m_status;
00096             SysHandle           m_thread;
00097 
00098             SLocker             m_lock;
00099 #if 0 // FIXME: Linux
00100             SysConditionVariableType    m_ended;    // condition var
00101 #else
00102             void*               m_ended;    // condition var
00103 #endif
00104             bool                m_ending : 1;
00105 };
00106 
00109 #if _SUPPORTS_NAMESPACE
00110 } } // end namespace palmos::support
00111 #endif
00112 
00113 #endif  /* _SUPPORT_THREAD_H_ */