HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UT_SharedMemoryManager.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_SharedMemoryManager.h ( UT Library, C++)
7  *
8  * COMMENTS:
9  *
10  */
11 
12 #ifndef __UT_SharedMemoryManager__
13 #define __UT_SharedMemoryManager__
14 
15 #include "UT_API.h"
16 
17 #include "UT_Map.h"
18 #include "UT_StringMap.h"
19 #include "UT_SpinLock.h"
20 
21 class SYS_SharedMemory;
22 
24 {
25 public:
26  static UT_SharedMemoryManager &get();
27 
28 
29  // Retrievs an existing memory block, or creates an empty one and marks
30  // it as being used.
31  SYS_SharedMemory *get(const char *key);
32 
33  // Mark all shared memory blocks with keys matching the pattern as being
34  // unused. If a block is retrieved with get() it gets marked as used. Any
35  // blocks remaining unused after an operation can be erased by calling
36  // erase() with 'only_unused' set to true.
37  void setUnused(const char *pattern);
38 
39  // Destroys all shared memory blocks with keys matching the given pattern.
40  //
41  void erase(const char *pattern, bool only_unused = false);
42 
43  // Exit callback to destroy all known shared memory blocks, so they don't
44  // linger on-disk or in page file after the owning process dies.
45  static void exitCallback(void *);
46 private:
49 
50  // Finds a list of keys matching the pattern. If all keys match the pattern
51  // the array is empty but the function still returns true.
52  bool find(const char *pattern, UT_Array<const char *> &keys);
53 
54  static UT_SpinLock theInstanceLock;
55  static UT_SharedMemoryManager *theInstance;
56 
57  struct ut_AutoSharedMemory
58  {
59  ut_AutoSharedMemory() : mySharedMemory(0), myUsed(false) {}
60  ~ut_AutoSharedMemory();
61 
62  SYS_SharedMemory *mySharedMemory;
63  bool myUsed;
64  };
65 
67 
68  ut_SharedMemPool mySharedMemPool;
69 };
70 
71 #endif // __UT_SharedMemoryManager__
#define UT_API
Definition: UT_API.h:12