1 // SUMMARY  : Threads for Linux and Microsoft Win32
2 // USAGE    :
3 // ORG      :
4 // AUTHOR   : Antoine Le Hyaric, Modif F. hecht
5 // E-MAIL   : lehyaric@ann.jussieu.fr
6 
7 // This file is part of Freefem++
8 //
9 // Freefem++ is free software; you can redistribute it and/or modify
10 // it under the terms of the GNU Lesser General Public License as published by
11 // the Free Software Foundation; either version 2.1 of the License, or
12 // (at your option) any later version.
13 //
14 // Freefem++  is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 // GNU Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public License
20 // along with Freefem++; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22 // from:
23 // Antoine Le Hyaric - LJLL Paris 6 - lehyaric@ann.jussieu.fr - 21/10/04
24 //  simplify by F. Hecht
25 // Antoine Le Hyaric - LJLL Paris 6 - hect@ann.jussieu.fr - 22/11/08
26 
27 #ifndef FFTHREADS_HPP
28 #define FFTHREADS_HPP
29 #include "mode_open.hpp"
30 #include <string>
31 using namespace std;
32 #ifdef __MINGW32__
33 #include <windows.h>
34 #else
35 #include <pthread.h>
36 #endif
37 
38 // Just check that we are in a known environment (otherwise it may be
39 // difficult to recognise that the simple cause is an ifdef problem).
40 
41 class Thread{
42 public:
43 
44 #ifdef __MINGW32__
45 #define THREADFUNC(f,parm) unsigned int (__stdcall f)(Thread::Parm parm)
46   typedef LPVOID Parm;
47   typedef HANDLE Id;
48 #else
49 #define THREADFUNC(f,parm) void* f(Thread::Parm parm)
50   typedef void* Parm;
51   typedef pthread_t Id;
52 #endif
53 
54   // Mingw is a little puzzled if there are no brackets around
55   // __stdcall
56   static Id Start(THREADFUNC(f,),Parm p);
57   static void Wait(Id tid);
58   static void Exit(); // From inside the thread
59   static void Kill(Id tid);
60 
61   static Id Current();
62 };
63 
64 
65 #endif // THREADS_HPP
66