Assists music production by grouping standalone programs into sessions. Community version of "Non Session Manager".
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.

63 lines
2.5KB

  1. /*******************************************************************************/
  2. /* Copyright (C) 2008-2020 Jonathan Moore Liles (as "Non-Session-Manager") */
  3. /* Copyright (C) 2020- Nils Hilbricht */
  4. /* */
  5. /* This file is part of New-Session-Manager */
  6. /* */
  7. /* New-Session-Manager 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 3 of the License, or */
  10. /* (at your option) any later version. */
  11. /* */
  12. /* New-Session-Manager is distributed in the hope that it will be useful, */
  13. /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
  14. /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
  15. /* GNU General Public License for more details. */
  16. /* */
  17. /* You should have received a copy of the GNU General Public License */
  18. /* along with New-Session-Manager. If not, see <https://www.gnu.org/licenses/>.*/
  19. /*******************************************************************************/
  20. #pragma once
  21. /* simple wrapper for pthreads with thread role checking */
  22. #include <pthread.h>
  23. #define THREAD_ASSERT( n ) ASSERT( Thread::is( #n ), "Function called from wrong thread! (is %s, should be %s)", Thread::current()->name(), #n )
  24. class Thread
  25. {
  26. static pthread_key_t _current;
  27. pthread_t _thread;
  28. const char * _name;
  29. volatile bool _running;
  30. static void * run_thread ( void *arg );
  31. public:
  32. static bool is ( const char *name );
  33. static void init ( void );
  34. static Thread *current ( void );
  35. Thread ( );
  36. Thread ( const char *name );
  37. const char *name ( void ) const { return _name; }
  38. void name ( const char *name ) { _name = name; }
  39. bool running ( void ) const { return _running; }
  40. void set ( const char *name );
  41. void set ( void ) { set( _name ); }
  42. bool clone ( void *(*entry_point)(void *), void *arg );
  43. void detach ( void );
  44. void join ( void );
  45. void cancel ( void );
  46. void exit ( void *retval = 0 );
  47. };