Back to index

nux  3.0.0
AbstractThread.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright 2010 Inalogic® Inc.
00003  *
00004  * This program is free software: you can redistribute it and/or modify it
00005  * under the terms of the GNU Lesser General Public License, as
00006  * published by the  Free Software Foundation; either version 2.1 or 3.0
00007  * of the License.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranties of
00011  * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
00012  * PURPOSE.  See the applicable version of the GNU Lesser General Public
00013  * License for more details.
00014  *
00015  * You should have received a copy of both the GNU Lesser General Public
00016  * License along with this program. If not, see <http://www.gnu.org/licenses/>
00017  *
00018  * Authored by: Jay Taoko <jaytaoko@inalogic.com>
00019  *
00020  */
00021 
00022 #include "Nux.h"
00023 #include "AbstractThread.h"
00024 
00025 namespace nux
00026 {
00027   class WindowThread;
00028   class SystemThread;
00029 
00030   NUX_IMPLEMENT_OBJECT_TYPE(AbstractThread);
00031 
00032   AbstractThread::AbstractThread(AbstractThread *Parent)
00033     :   parent_(Parent)
00034     ,   user_init_func_(NULL)
00035     ,   user_exit_func_(NULL)
00036   {
00037 
00038   }
00039 
00040   AbstractThread::~AbstractThread()
00041   {
00042 
00043   }
00044 
00045   void AbstractThread::TerminateChildWindows()
00046   {
00047     std::list<AbstractThread*>::iterator it;
00048 
00049     for (it = children_thread_list_.begin(); it != children_thread_list_.end(); it++)
00050     {
00051       if ((*it)->Type().IsObjectType(WindowThread::StaticObjectType))
00052       {
00053         // Exit the main loop of a window.
00054         static_cast<WindowThread*>(*it)->ExitMainLoop();
00055       }
00056     }
00057   }
00058 
00059   void AbstractThread::JoinChildThreads()
00060   {
00061 #if defined(NUX_OS_WINDOWS)
00062     size_t sz = children_thread_list_.size();
00063 
00064     if (sz == 0)
00065     {
00066       return;
00067     }
00068 
00069     HANDLE *hdl = new HANDLE[sz];
00070 
00071     int i = 0;
00072     std::list<AbstractThread*>::iterator it;
00073     for (it = children_thread_list_.begin(); it != children_thread_list_.end(); ++it, ++i)
00074     {
00075       hdl[i] = (*it)->GetThreadHandle();
00076     }
00077 
00078     unsigned int result = WaitForMultipleObjects(sz, hdl, FALSE, INFINITE);
00079 #else
00080   //#error WindowThread::JoinChildThreads has not been implemented for this platform.
00081   // Todo
00082 #endif
00083 
00084     return;
00085   }
00086 
00087 }