blocxx
IPCMutex.hpp
Go to the documentation of this file.
1/*******************************************************************************
2* Copyright (C) 2005 Novell, Inc. All rights reserved.
3*
4* Redistribution and use in source and binary forms, with or without
5* modification, are permitted provided that the following conditions are met:
6*
7* - Redistributions of source code must retain the above copyright notice,
8* this list of conditions and the following disclaimer.
9*
10* - Redistributions in binary form must reproduce the above copyright notice,
11* this list of conditions and the following disclaimer in the documentation
12* and/or other materials provided with the distribution.
13*
14* - Neither the name of Novell, Inc., nor the names of its
15* contributors may be used to endorse or promote products derived from this
16* software without specific prior written permission.
17*
18* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
19* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21* ARE DISCLAIMED. IN NO EVENT SHALL Novell, Inc., OR THE
22* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29*******************************************************************************/
30
35#ifndef _BLOCXX_IPCMUTEX_HPP_INCLUDE_GUARD_
36#define _BLOCXX_IPCMUTEX_HPP_INCLUDE_GUARD_
37
38#include "blocxx/BLOCXX_config.h"
39// This class only works on Linux.
40#ifdef BLOCXX_GNU_LINUX
41#if !defined (BLOCXX_HAVE_SYS_IPC_H) && !defined (BLOCXX_HAVE_SYS_SEM_H)
42 #error "Port me!"
43#else
44
45#include "blocxx/Exception.hpp"
46
47#include <sys/types.h>
48#include <sys/ipc.h>
49#include <sys/sem.h>
50
51
52namespace BLOCXX_NAMESPACE
53{
54
55BLOCXX_DECLARE_APIEXCEPTION(IPCMutex, BLOCXX_COMMON_API);
56
61class IPCMutex
62{
63public:
74 IPCMutex(int semId);
75 ~IPCMutex() {};
76
80 void wait();
81
85 void signal();
90 int getId() { return m_semid;}
91
96 static void free(int semKey);
97private:
98 int m_semid;
99 struct sembuf m_sbuf;
100 union semun
101 {
102 int val;
103 struct sumid_ds* buf;
104 unsigned short* array;
105 } m_arg;
106
107};
108
110
124class IPCMutexLock
125{
126public:
127 IPCMutexLock(IPCMutex& sem);
128 ~IPCMutexLock();
129private:
130 IPCMutex& m_sem;
131};
132
133} // end namespace
134
135#endif // #if !defined (BLOCXX_HAVE_SYS_IPC_H) && !defined (BLOCXX_HAVE_SYS_SEM_H)
136#endif // #ifdef BLOCXX_GNU_LINUX
137#endif // #ifndef _IPCMUTEXLOCK_HPP_INCLUDE_GUARD_
138
#define BLOCXX_DECLARE_APIEXCEPTION(NAME, LINKAGE_SPEC)
Declare a new exception class named <NAME>Exception that derives from Exception This macro is typical...
Taken from RFC 1321.