Mercurial > ~dholland > hg > ag > index.cgi
comparison anagram/guisupport/resource.h @ 0:13d2b8934445
Import AnaGram (near-)release tree into Mercurial.
author | David A. Holland |
---|---|
date | Sat, 22 Dec 2007 17:52:45 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:13d2b8934445 |
---|---|
1 /* | |
2 * AnaGram, A System for Syntax Directed Programming | |
3 * Copyright 1993-2002 Parsifal Software. All Rights Reserved. | |
4 * See the file COPYING for license and usage terms. | |
5 * | |
6 * resource.h | |
7 */ | |
8 | |
9 #ifndef RESOURCE_H | |
10 #define RESOURCE_H | |
11 | |
12 #ifdef __IBMCPP__ | |
13 #include <ireslock.hpp> | |
14 #endif | |
15 | |
16 | |
17 #ifdef __IBMCPP__ | |
18 | |
19 class AgResource { | |
20 private: | |
21 class Resource : public IPrivateResource { | |
22 public: | |
23 void *operator new (size_t, void *s) { return s; } | |
24 }; | |
25 | |
26 void *storage; | |
27 IPrivateResource *resource; | |
28 | |
29 public: | |
30 AgResource() : storage(0), resource(0) {} | |
31 ~AgResource() { if (storage == 0) delete resource; } | |
32 void lock() { | |
33 if (resource == 0) { | |
34 resource = new IPrivateResource; | |
35 } | |
36 resource->lock(); | |
37 } | |
38 void lock(void *s) { | |
39 if (resource == 0) { | |
40 resource = new(storage = s) Resource; | |
41 } | |
42 resource->lock(); | |
43 } | |
44 void unlock() { | |
45 resource->unlock(); | |
46 } | |
47 }; | |
48 | |
49 #endif /* __IBMCPP__ */ | |
50 | |
51 | |
52 class AgLock { | |
53 private: | |
54 AgResource &resource; | |
55 | |
56 public: | |
57 AgLock(AgResource &r) : resource(r) { | |
58 resource.lock(); | |
59 } | |
60 AgLock(AgResource &r, void *s) : resource(r) { | |
61 resource.lock(s); | |
62 } | |
63 ~AgLock() {resource.unlock();} | |
64 }; | |
65 | |
66 | |
67 #endif /* RESOURCE_H */ |