libmoldeo (Moldeo 1.0 Core)  1.0
libmoldeo is the group of objects and functions that executes the basic operations of Moldeo 1.0 Platform.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
moThread.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2 
3  moThread.cpp
4 
5  ****************************************************************************
6  * *
7  * This source is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 2 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This code is distributed in the hope that it will be useful, but *
13  * WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
15  * General Public License for more details. *
16  * *
17  * A copy of the GNU General Public License is available on the World *
18  * Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
19  * obtain it by writing to the Free Software Foundation, *
20  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21  * *
22  ****************************************************************************
23 
24  Copyright(C) 2006 Fabricio Costa
25 
26  Authors:
27  Fabricio Costa
28 
29 
30 *******************************************************************************/
31 
32 #include "moThread.h"
33 
35  m_handleThread = NULL;
36 }
37 
39  if(ThreadExists())
40  KillThread();
41 }
42 
44  //thread* pthread;
45  //pthread = new thread( boost::bind( moThread::InitialThreadFunction, (void*)this ) );
46  //m_handleThread = (void*) pthread;
47 
48  //m_handleThread = (void *)SDL_CreateThread( InitialThreadFunction,(void*)this);
49 #ifndef MO_WIN32
50  pthread_create( (pthread_t*)&m_handleThread , NULL, InitialThreadFunction, this);
51 #else
52  DWORD threadId;
53  m_handleThread = (void*) ::CreateThread( 0, 0, InitialThreadFunction, this, 0, &threadId );
54 #endif
55 
56  return(m_handleThread!=NULL);
57 }
58 
60  if(ThreadExists()) {
61  /*
62  SDL_KillThread( (SDL_Thread *) m_handleThread );//SDL_WaitThread ???
63  */
64 #ifndef MO_WIN32
65  pthread_cancel((pthread_t)m_handleThread);
66 #else
67  CloseHandle( m_handleThread );
68 #endif
69  //thread* pthread = (thread*)m_handleThread;
70  //delete pthread;
71  m_handleThread=NULL;
72  }
73  return(m_handleThread==NULL);
74 }
76  return(m_handleThread!=NULL);
77 }
78 
80  if (message<=0) return false;
81  return true;
82 }
83 
84 #ifndef WIN32
85 void* moThread::InitialThreadFunction( void *data ) {
86 #else
87 DWORD WINAPI moThread::InitialThreadFunction( LPVOID data ) {
88 #endif
89  moThread* m_pThreadClass;
90  m_pThreadClass =(moThread*)data;
91  int b = m_pThreadClass->ThreadUserFunction();
92  #ifndef WIN32
93  return (void*)0;
94  #else
95  return b;
96  #endif
97 }
98 
99 bool moThread::ProcessMessage() {
100  return true;
101 }
102 
103 
bool KillThread()
Definition: moThread.cpp:59
bool ThreadExists()
Definition: moThread.cpp:75
const char * message
virtual ~moThread()
Definition: moThread.cpp:38
bool SendThreadMessage(int message)
Definition: moThread.cpp:79
moThread()
Definition: moThread.cpp:34
bool CreateThread()
Definition: moThread.cpp:43