GlobalProtectedObject.hpp
Go to the documentation of this file.
1 /*----------------------------------------------------------------------------*/
2 /* */
3 /* Copyright (c) 1995, 2004 IBM Corporation. All rights reserved. */
4 /* Copyright (c) 2005-2009 Rexx Language Association. All rights reserved. */
5 /* */
6 /* This program and the accompanying materials are made available under */
7 /* the terms of the Common Public License v1.0 which accompanies this */
8 /* distribution. A copy is also available at the following address: */
9 /* http://www.ibm.com/developerworks/oss/CPLv1.0.htm */
10 /* */
11 /* Redistribution and use in source and binary forms, with or */
12 /* without modification, are permitted provided that the following */
13 /* conditions are met: */
14 /* */
15 /* Redistributions of source code must retain the above copyright */
16 /* notice, this list of conditions and the following disclaimer. */
17 /* Redistributions in binary form must reproduce the above copyright */
18 /* notice, this list of conditions and the following disclaimer in */
19 /* the documentation and/or other materials provided with the distribution. */
20 /* */
21 /* Neither the name of Rexx Language Association nor the names */
22 /* of its contributors may be used to endorse or promote products */
23 /* derived from this software without specific prior written permission. */
24 /* */
25 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */
26 /* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */
27 /* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS */
28 /* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */
29 /* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
30 /* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
31 /* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */
32 /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY */
33 /* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */
34 /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
35 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
36 /* */
37 /*----------------------------------------------------------------------------*/
38 #ifndef GlobalProtectedObject_Included
39 #define GlobalProtectedObject_Included
40 
41 #include "RexxMemory.hpp"
42 #include "ActivityManager.hpp"
43 
44 class RexxInstruction;
45 
47 {
48 friend class RexxMemory;
49 public:
51  {
52  // because this is global to all threads, we might not be at the
53  // head of the list when the destructor is run, so we need to
54  // maintain a double linked list.
56  if (next != NULL)
57  {
58  next->previous = this;
59  }
61  }
62 
64  {
65  // because this is global to all threads, we might not be at the
66  // head of the list when the destructor is run, so we need to
67  // maintain a double linked list.
69  if (next != NULL)
70  {
71  next->previous = this;
72  }
74  }
75 
77  {
78  // because this is global to all threads, we might not be at the
79  // head of the list when the destructor is run, so we need to
80  // maintain a double linked list.
82  if (next != NULL)
83  {
84  next->previous = this;
85  }
87  }
88 
90  {
91  // if at the head of the chain, we just update the master pointer
92  if (previous == NULL)
93  {
95  // the next element has no predecessor
96  if (next != NULL)
97  {
98  next->previous = NULL;
99  }
100  }
101  else
102  {
103  // dechain
104  previous->next = next;
105  if (next != NULL)
106  {
108  }
109  }
110  if (protectedObject != OREF_NULL)
111  {
113  }
114  }
115 
117  {
118  protectedObject = o;
119  return *this;
120  }
121 
122  inline bool operator == (RexxObject *o)
123  {
124  return protectedObject == o;
125  }
126 
127  inline bool operator != (RexxObject *o)
128  {
129  return protectedObject != o;
130  }
131 
132  // cast conversion operators for some very common uses of protected object.
133  inline operator RexxObject *()
134  {
135  return protectedObject;
136  }
137 
138  inline operator RexxObjectPtr ()
139  {
141  }
142 
143 protected:
144  RexxObject *protectedObject; // next in the chain of protected object
145  GlobalProtectedObject *next; // the pointer protected by the object
146  GlobalProtectedObject *previous; // the previous object in the chain
147 };
148 #endif
#define OREF_NULL
Definition: RexxCore.h:61
RexxMemory memoryObject
Definition: RexxMemory.cpp:86
GlobalProtectedObject * next
GlobalProtectedObject & operator=(RexxObject *o)
bool operator!=(RexxObject *o)
bool operator==(RexxObject *o)
GlobalProtectedObject * previous
GlobalProtectedObject(RexxObject *o)
GlobalProtectedObject(RexxInternalObject *o)
RexxObject * holdObject(RexxInternalObject *obj)
GlobalProtectedObject * protectedObjects
Definition: RexxMemory.hpp:307
struct _RexxObjectPtr * RexxObjectPtr
Definition: rexx.h:127