MPQC  3.0.0-alpha
memshm.h
1 //
2 // memshm.h
3 //
4 // Copyright (C) 1996 Limit Point Systems, Inc.
5 //
6 // Author: Curtis Janssen <cljanss@limitpt.com>
7 // Maintainer: LPS
8 //
9 // This file is part of the SC Toolkit.
10 //
11 // The SC Toolkit is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU Library General Public License as published by
13 // the Free Software Foundation; either version 2, or (at your option)
14 // any later version.
15 //
16 // The SC Toolkit is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU Library General Public License for more details.
20 //
21 // You should have received a copy of the GNU Library General Public License
22 // along with the SC Toolkit; see the file COPYING.LIB. If not, write to
23 // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24 //
25 // The U.S. Government is granted a limited license as per AL 91-7.
26 //
27 
28 #ifndef _util_group_memshm_h
29 #define _util_group_memshm_h
30 
31 #include <sys/types.h>
32 #include <sys/ipc.h>
33 #include <sys/shm.h>
34 #include <iostream>
35 
36 #include <util/group/globcnt.h>
37 #include <util/group/memmsg.h>
38 
39 #include <util/group/rnglock.h>
40 
41 namespace sc {
42 
46 class ShmMemoryGrp: public MsgMemoryGrp {
47  private:
48  int nregion_;
49  int *shmid_;
50  void **attach_address_;
51  GlobalCounter lock_;
52  GlobalCounter *update_;
53  void *data_;
54  void *memory_;
55  Pool *pool_;
56  RangeLock *rangelock_; // the locks_ member of the base class is ignored
57 
58  void clear_release_count();
59  void wait_for_release();
60  void note_release();
61  void obtain_lock();
62  void release_lock();
63 
64  void cleanup();
65  int attach_memory(void *ataddress, int size);
66  void detach_memory();
67  public:
68  ShmMemoryGrp(const Ref<MessageGrp>& msg);
69  ShmMemoryGrp(const Ref<KeyVal>&);
70  ~ShmMemoryGrp();
71 
72  void set_localsize(size_t);
73  void *localdata();
74 
75  void *obtain_readwrite(distsize_t offset, size_t size);
76  void *obtain_readonly(distsize_t offset, size_t size);
77  void *obtain_writeonly(distsize_t offset, size_t size);
78  void release_readonly(void *data, distsize_t offset, size_t size);
79  void release_writeonly(void *data, distsize_t offset, size_t size);
80  void release_readwrite(void *data, distsize_t offset, size_t size);
81 
82  void print(std::ostream &o = ExEnv::out0()) const;
83 };
84 
85 }
86 
87 #endif
88 
89 // Local Variables:
90 // mode: c++
91 // c-file-style: "CLJ"
92 // End:
sc::ShmMemoryGrp::localdata
void * localdata()
Returns a pointer to the local data.
sc::MemoryGrp::offset
distsize_t offset(int node)
Returns the global offset to node's memory.
Definition: memory.h:164
sc::ShmMemoryGrp::obtain_readonly
void * obtain_readonly(distsize_t offset, size_t size)
This gives read access to the memory location. No locking is done.
sc::Ref
A template class that maintains references counts.
Definition: ref.h:361
sc::ShmMemoryGrp::obtain_writeonly
void * obtain_writeonly(distsize_t offset, size_t size)
This gives write access to the memory location. No locking is done.
sc::ShmMemoryGrp::set_localsize
void set_localsize(size_t)
Set the size of locally held memory.
sc::ShmMemoryGrp
The ShmMemoryGrp concrete class provides an implementation of MsgMemoryGrp.
Definition: memshm.h:46
sc::RangeLock
Definition: rnglock.h:55
sc::ShmMemoryGrp::print
void print(std::ostream &o=ExEnv::out0()) const
Prints out information about the object.
sc::MemoryGrp::size
int size(int node)
Returns the amount of memory residing on node.
Definition: memory.h:161
sc::ShmMemoryGrp::release_readonly
void release_readonly(void *data, distsize_t offset, size_t size)
This is called when read access is no longer needed.
sc::Pool
Definition: pool.h:262
sc::GlobalCounter
The GlobalCounter class allows processes on the same SMP node to share a counter using SysV IPC semap...
Definition: globcnt.h:40
sc::ShmMemoryGrp::obtain_readwrite
void * obtain_readwrite(distsize_t offset, size_t size)
Only one thread can have an unreleased obtain_readwrite at a time.
sc::ExEnv::out0
static std::ostream & out0()
Return an ostream that writes from node 0.
sc::ShmMemoryGrp::release_writeonly
void release_writeonly(void *data, distsize_t offset, size_t size)
This is called when write access is no longer needed.
sc::MsgMemoryGrp
A MsgMemoryGrp that initializes its data using a messagegrp.
Definition: memmsg.h:37
sc
Contains all MPQC code up to version 3.
Definition: mpqcin.h:14
sc::ShmMemoryGrp::release_readwrite
void release_readwrite(void *data, distsize_t offset, size_t size)
This is called when read/write access is no longer needed.

Generated at Sun Jan 26 2020 23:24:01 for MPQC 3.0.0-alpha using the documentation package Doxygen 1.8.16.