threads.hpp

来自「FreeFem++可以生成高质量的有限元网格。可以用于流体力学」· HPP 代码 · 共 99 行

HPP
99
字号
// -*- Mode : c++ -*-//// SUMMARY  :      // USAGE    :        // ORG      : // AUTHOR   : Antoine Le Hyaric -// E-MAIL   : lehyaric@ann.jussieu.fr///*  This file is part of Freefem++  Freefem++ is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.  Freefem++  is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.  You should have received a copy of the GNU Lesser General Public License along with Freefem++; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */// Threads for Linux and Microsoft Win32// -------------------------------------// Antoine Le Hyaric - LJLL Paris 6 - lehyaric@ann.jussieu.fr - 21/10/04// $Id: threads.hpp,v 1.6 2006-09-29 20:30:15 hecht Exp $#ifndef THREADS_HPP#define THREADS_HPP#include <string>using namespace std;#ifdef __MINGW32__#include <windows.h>#else#include <pthread.h>#include <semaphore.h>#endifclass Thread{public:#ifdef __MINGW32__#define THREADFUNC(f,parm) unsigned int (__stdcall f)(Thread::Parm parm)  typedef LPVOID Parm;  typedef HANDLE Id;#else#define THREADFUNC(f,parm) void* f(Thread::Parm parm)  typedef void* Parm;  typedef pthread_t Id;#endif  // Mingw is a little puzzled if there are no brackets around  // __stdcall  static Id Start(THREADFUNC(f,),Parm p);  static void Wait(Id tid);  static void Exit(); // From inside the thread  static void Kill(Id tid);};class Mutex{public:  Mutex();  ~Mutex();  void Wait(#ifndef NDEBUG	    const char *f,const int l#endif	    );  void Free();  // Can only work in "assert(IsLocked())" (and even then only  // statistically), not in "assert(!IsLocked())". But this is the  // most useful format anyway.#ifndef NDEBUG  bool IsLocked() const;#endifprotected:#ifdef __MINGW32__    HANDLE mutex;#else    pthread_mutex_t mutex;#endif  // Just for checking.#ifndef NDEBUG  bool locked;  // Fichier et ligne o

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?