You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.7KB

  1. //
  2. // "$Id: threads.h 7913 2010-11-29 18:18:27Z greg.ercolano $"
  3. //
  4. // Simple threading API for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 1998-2010 by Bill Spitzak and others.
  7. //
  8. // This library is free software; you can redistribute it and/or
  9. // modify it under the terms of the GNU Library General Public
  10. // License as published by the Free Software Foundation; either
  11. // version 2 of the License, or (at your option) any later version.
  12. //
  13. // This library is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. // Library General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Library General Public
  19. // License along with this library; if not, write to the Free Software
  20. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  21. // USA.
  22. //
  23. // Please report all bugs and problems on the following page:
  24. //
  25. // http://www.fltk.org/str.php
  26. //
  27. // Inline classes to provide portable support for threads and mutexes.
  28. //
  29. // FLTK does not use this (it has an internal mutex implementation
  30. // that is used if Fl::lock() is called). This header file's only
  31. // purpose is so we can write portable demo programs. It may be useful
  32. // or an inspiration to people who want to try writing multithreaded
  33. // programs themselves.
  34. //
  35. // FLTK has no multithreaded support unless the main thread calls Fl::lock().
  36. // This main thread is the only thread allowed to call Fl::run() or Fl::wait().
  37. // From then on FLTK will be locked except when the main thread is actually
  38. // waiting for events from the user. Other threads must call Fl::lock() and
  39. // Fl::unlock() to surround calls to FLTK (such as to change widgets or
  40. // redraw them).
  41. #ifndef Threads_H
  42. # define Threads_H
  43. # if HAVE_PTHREAD_H
  44. // Use POSIX threading...
  45. # include <pthread.h>
  46. typedef pthread_t Fl_Thread;
  47. static int fl_create_thread(Fl_Thread& t, void *(*f) (void *), void* p) {
  48. return pthread_create((pthread_t*)&t, 0, f, p);
  49. }
  50. # elif defined(WIN32) && !defined(__WATCOMC__) // Use Windows threading...
  51. # include <windows.h>
  52. # include <process.h>
  53. typedef unsigned long Fl_Thread;
  54. static int fl_create_thread(Fl_Thread& t, void *(*f) (void *), void* p) {
  55. return t = (Fl_Thread)_beginthread((void( __cdecl * )( void * ))f, 0, p);
  56. }
  57. # elif defined(__WATCOMC__)
  58. # include <process.h>
  59. typedef unsigned long Fl_Thread;
  60. static int fl_create_thread(Fl_Thread& t, void *(*f) (void *), void* p) {
  61. return t = (Fl_Thread)_beginthread((void(* )( void * ))f, 32000, p);
  62. }
  63. # endif // !HAVE_PTHREAD_H
  64. #endif // !Threads_h
  65. //
  66. // End of "$Id: threads.h 7913 2010-11-29 18:18:27Z greg.ercolano $".
  67. //