synthclone  0.3.0
semaphore.h
Go to the documentation of this file.
1 /*
2  * libsynthclone - a plugin API for `synthclone`
3  * Copyright (C) 2011-2012 Devin Anderson
4  *
5  * This library is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU Lesser General Public License as published by the
7  * Free Software Foundation; either version 2.1 of the License, or (at your
8  * option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13  * for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this library; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 #ifndef __SYNTHCLONE_SEMAPHORE_H__
21 #define __SYNTHCLONE_SEMAPHORE_H__
22 
23 #if defined(SYNTHCLONE_PLATFORM_MACX) || defined(SYNTHCLONE_PLATFORM_UNIX)
24 #include <semaphore.h>
25 #elif defined(SYNTHCLONE_PLATFORM_WIN32)
26 #include <unistd.h>
27 #include <windows.h>
28 #else
29 #error "A semaphore implementation has not been defined for your platform"
30 #endif
31 
32 #include <QtCore/QObject>
33 #include <QtCore/QString>
34 
35 namespace synthclone {
36 
42  class Semaphore: public QObject {
43 
44  Q_OBJECT
45 
46  public:
47 
55  explicit
56  Semaphore(QObject *parent=0);
57 
62  ~Semaphore();
63 
74  void
75  post();
76 
83  void
84  wait();
85 
86  private:
87 
88  QString
89  getErrorMessage();
90 
91 #if defined(SYNTHCLONE_PLATFORM_MACX)
92  QByteArray name;
93  sem_t *semaphore;
94 #elif defined(SYNTHCLONE_PLATFORM_UNIX)
95  sem_t semaphore;
96 #elif defined(SYNTHCLONE_PLATFORM_WIN32)
97  HANDLE semaphore;
98 #endif
99 
100  };
101 
102 }
103 
104 #endif
~Semaphore()
Destroys a Semaphore object.
A portable semaphore object, optimally including a realtime-safe &#39;post&#39; operation.
Definition: semaphore.h:42
Semaphore(QObject *parent=0)
Constructs a new Semaphore object.
Definition: component.h:26
void post()
Increments the semaphore.
void wait()
Decrements the semaphore if the semaphore&#39;s value is greater than zero; otherwise, the thread will wait until another thread performs a &#39;post&#39; operation on the semaphore.