ardour
semutils.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 Paul Davis
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18 
19 #ifndef __pbd_semutils_h__
20 #define __pbd_semutils_h__
21 
22 #ifdef PLATFORM_WINDOWS
23 #include <windows.h>
24 #else
25 #include <semaphore.h>
26 #endif
27 
28 #include "pbd/libpbd_visibility.h"
29 
30 namespace PBD {
31 
33  private:
34 #ifdef PLATFORM_WINDOWS
35  HANDLE _sem;
36 
37 #elif __APPLE__
38  sem_t* _sem;
39  sem_t* ptr_to_sem() const { return _sem; }
40 #else
41  mutable sem_t _sem;
42  sem_t* ptr_to_sem() const { return &_sem; }
43 #endif
44 
45  public:
46  ProcessSemaphore (const char* name, int val);
47  ~ProcessSemaphore ();
48 
49 #ifdef PLATFORM_WINDOWS
50 
51  int signal ();
52  int wait ();
53 
54 #else
55  int signal () { return sem_post (ptr_to_sem()); }
56  int wait () { return sem_wait (ptr_to_sem()); }
57 #endif
58 };
59 
60 }
61 
62 #endif /* __pbd_semutils_h__ */
#define LIBPBD_API
sem_t * ptr_to_sem() const
Definition: semutils.h:42
const char * name
Definition: debug.h:30
def signal
Definition: signals.py:53