//==============================================================================
// Copyright (c) 2006 Ryan Winter
//==============================================================================
#ifndef illuminate_threads_thread_thread_h
#define illuminate_threads_thread_thread_h

//==============================================================================
// Description
//   Summary     : ABC for a Threadable class
//   Description : Subclass and override the private run() method.
//   Assumptions : join() must be called otherwise the thread resources are not
//                 deallocated correctly and things will be broken
//==============================================================================

class SDL_Thread;

namespace Illuminate
{

class Thread
{
  public:
    Thread();
    virtual ~Thread();

    //--------------------------------------------------------------------------
    // Description : Start the thread
    //--------------------------------------------------------------------------
    void start();
    
    //--------------------------------------------------------------------------
    // Description : Join with the thread
    //--------------------------------------------------------------------------
    void join();

    //--------------------------------------------------------------------------
    // Description : Gracelessly terminate the thread. Don't use this unless
    //               there is no other option.
    //--------------------------------------------------------------------------
    void terminate();
    
    //--------------------------------------------------------------------------
    // Description : Returns the running state of the thread
    //--------------------------------------------------------------------------
    bool isRunning () const;
    
  private:
    //--------------------------------------------------------------------------
    // Description : Not allowed for this class
    //--------------------------------------------------------------------------
    Thread &operator=(const Thread &rhs);
    Thread(const Thread &rhs);
    
    //--------------------------------------------------------------------------
    // Description : Entry point for the thread
    // Parameters  : data - pointer to the Thread class to execute run()
    //--------------------------------------------------------------------------
    static int runThread(void *data);
    
    //--------------------------------------------------------------------------
    // Description : This method is executed in the newly created thread
    //--------------------------------------------------------------------------
    virtual void run() = 0;

    bool        m_running;

    SDL_Thread *m_thread;
};

}

#endif


