|
a |
|
b/src/sysvshm.h |
|
|
1 |
/* Copyright (C) 2017-2018 J.F.Dockes
|
|
|
2 |
* This program is free software; you can redistribute it and/or modify
|
|
|
3 |
* it under the terms of the GNU General Public License as published by
|
|
|
4 |
* the Free Software Foundation; either version 2 of the License, or
|
|
|
5 |
* (at your option) any later version.
|
|
|
6 |
*
|
|
|
7 |
* This program is distributed in the hope that it will be useful,
|
|
|
8 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
9 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
10 |
* GNU General Public License for more details.
|
|
|
11 |
*
|
|
|
12 |
* You should have received a copy of the GNU General Public License
|
|
|
13 |
* along with this program; if not, write to the
|
|
|
14 |
* Free Software Foundation, Inc.,
|
|
|
15 |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
16 |
*/
|
|
|
17 |
|
|
|
18 |
#ifndef _SYSVIPC_H_INCLUDED_
|
|
|
19 |
#define _SYSVIPC_H_INCLUDED_
|
|
|
20 |
|
|
|
21 |
#include <sys/types.h>
|
|
|
22 |
#include <sys/ipc.h>
|
|
|
23 |
#include <sys/msg.h>
|
|
|
24 |
#include <sys/sem.h>
|
|
|
25 |
#include <sys/shm.h>
|
|
|
26 |
|
|
|
27 |
class ShmSeg {
|
|
|
28 |
public:
|
|
|
29 |
ShmSeg(key_t ky, size_t size, bool create = false, int perms = 0600);
|
|
|
30 |
ShmSeg(const char*pathname, int proj_id, size_t size, bool create = false, int perms = 0600);
|
|
|
31 |
ShmSeg(int size) : ShmSeg(IPC_PRIVATE, size) {}
|
|
|
32 |
virtual ~ShmSeg();
|
|
|
33 |
virtual void setremove(bool onoff = true);
|
|
|
34 |
virtual void *getseg();
|
|
|
35 |
virtual size_t getsize();
|
|
|
36 |
virtual bool ok();
|
|
|
37 |
|
|
|
38 |
class Internal;
|
|
|
39 |
protected:
|
|
|
40 |
Internal *m;
|
|
|
41 |
};
|
|
|
42 |
|
|
|
43 |
// Shm segment with integrated lock. Note that the lock initialization
|
|
|
44 |
// is not protected, and that an external method is needed for the
|
|
|
45 |
// creating process to be left alone while it is creating the segment
|
|
|
46 |
// and initializing the lock.
|
|
|
47 |
//
|
|
|
48 |
// You need to use an Accessor object to get to the segment. This
|
|
|
49 |
// takes the lock on construction and releases it on deletion
|
|
|
50 |
class LockableShmSeg : public ShmSeg {
|
|
|
51 |
public:
|
|
|
52 |
LockableShmSeg(key_t ky, size_t size, bool create = false, int perms = 0600);
|
|
|
53 |
LockableShmSeg(const char*pathname, int proj_id, size_t size,
|
|
|
54 |
bool create = false, int perms = 0600);
|
|
|
55 |
LockableShmSeg(int size) : LockableShmSeg(IPC_PRIVATE, size) {}
|
|
|
56 |
virtual ~LockableShmSeg();
|
|
|
57 |
class Accessor {
|
|
|
58 |
public:
|
|
|
59 |
Accessor(LockableShmSeg&);
|
|
|
60 |
~Accessor();
|
|
|
61 |
void *getseg();
|
|
|
62 |
private:
|
|
|
63 |
LockableShmSeg& lss;
|
|
|
64 |
};
|
|
|
65 |
friend class Accessor;
|
|
|
66 |
private:
|
|
|
67 |
virtual void *getseg();
|
|
|
68 |
};
|
|
|
69 |
|
|
|
70 |
#endif /* _SYSVIPC_H_INCLUDED_ */
|