RexxVariable.cpp
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.oorexx.org/license.html */
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 /****************************************************************************/
39 /* REXX Kernel RexxVariable.c */
40 /* */
41 /* Primitive Variable Class */
42 /* */
43 /****************************************************************************/
44 #include "RexxCore.h"
45 #include "RexxVariable.hpp"
46 #include "RexxActivity.hpp"
47 #include "ActivityManager.hpp"
48 
49 void RexxVariable::live(size_t liveMark)
50 /******************************************************************************/
51 /* Function: Normal garbage collection live marking */
52 /******************************************************************************/
53 {
56  memory_mark(this->dependents);
57 }
58 
59 void RexxVariable::liveGeneral(int reason)
60 /******************************************************************************/
61 /* Function: Normal garbage collection live marking */
62 /******************************************************************************/
63 {
67 }
68 
70 /******************************************************************************/
71 /* Function: Flatten an object */
72 /******************************************************************************/
73 {
75 
76  flatten_reference(newThis->variableValue, envelope);
77  flatten_reference(newThis->variable_name, envelope);
78  flatten_reference(newThis->dependents, envelope);
79 
81 }
82 
84  RexxActivity *informee) /* activity to inform of changes */
85 /****************************************************************************/
86 /* Function: Set up an activity notification for a variable change */
87 /****************************************************************************/
88 {
89  if (this->dependents == OREF_NULL) /* no dependents yet? */
90  {
91  /* set this up as an object table */
92  OrefSet(this, this->dependents, new_identity_table());
93  }
94  /* add this to the table */
95  this->dependents->put(TheNilObject, (RexxObject *)informee);
96 }
97 
99  RexxActivity *informee) /* activity to inform of changes */
100 /****************************************************************************/
101 /* Function: Remove a dependent from the notification list */
102 /****************************************************************************/
103 {
104  /* remove the entry */
105  this->dependents->remove((RexxObject *)informee);
106  if (this->dependents->items() == 0) /* last one? */
107  {
108  /* drop the dependents list */
109  OrefSet(this, this->dependents, OREF_NULL);
110  }
111 }
112 
114 /****************************************************************************/
115 /* Function: Drop a variable */
116 /****************************************************************************/
117 {
118  /* clear out the value */
119  OrefSet(this, this->variableValue, OREF_NULL);
120  if (this->dependents != OREF_NULL) /* have notifications to process? */
121  {
122  this->notify(); /* notify any dependents */
123  }
124 }
125 
127 /****************************************************************************/
128 /* Function: Process all variable notifications */
129 /****************************************************************************/
130 {
131  if (this->dependents != OREF_NULL)
132  { /* any dependents? */
133  /* loop through the table */
134  for (HashLink i = this->dependents->first(); this->dependents->available(i); i = this->dependents->next(i))
135  {
136  /* post the event to the dependent */
137  ((RexxActivity *)this->dependents->index(i))->guardPost();
138  }
139  /* yield control and allow the */
140  /* waiting guard to run too */
141  /* get the current activity */
143  activity->releaseAccess(); /* release the lock */
144  activity->requestAccess(); /* get it back again */
145  }
146 }
147 
148 
150  RexxString *name) /* the name of the variable */
151 /****************************************************************************/
152 /* Function: Create a new REXX variable object */
153 /****************************************************************************/
154 {
155  /* Get new object */
157  newObj->variableValue = OREF_NULL; /* clear out the hash value */
158  newObj->creator = OREF_NULL; /* clear out creator field */
159  newObj->variable_name = name; /* fill in the name */
160  newObj->dependents = OREF_NULL; /* and the dependents */
161  return newObj; /* return the new object */
162 }
163 
@ T_Variable
RexxIdentityTable * new_identity_table()
#define OREF_NULL
Definition: RexxCore.h:60
#define OrefSet(o, r, v)
Definition: RexxCore.h:94
#define TheNilObject
Definition: RexxCore.h:181
size_t HashLink
#define memory_mark(oref)
Definition: RexxMemory.hpp:445
RexxObject * new_object(size_t s)
Definition: RexxMemory.hpp:431
#define flatten_reference(oref, envel)
Definition: RexxMemory.hpp:493
#define memory_mark_general(oref)
Definition: RexxMemory.hpp:446
#define cleanUpFlatten
Definition: RexxMemory.hpp:479
#define setUpFlatten(type)
Definition: RexxMemory.hpp:473
static RexxActivity *volatile currentActivity
void requestAccess()
void releaseAccess()
RexxObject * index(HashLink pos)
virtual RexxObject * put(RexxObject *, RexxObject *)
virtual RexxObject * remove(RexxObject *key)
void liveGeneral(int reason)
static RexxVariable * newInstance(RexxString *name)
RexxObject * variableValue
void uninform(RexxActivity *)
void flatten(RexxEnvelope *)
RexxActivation * creator
void inform(RexxActivity *)
void live(size_t)
RexxString * variable_name
RexxIdentityTable * dependents