as2js: /home/snapwebsites/snapcpp/contrib/as2js/lib/node_lock.cpp Source File

as2js  0.1.14
AlexScript to JavaScript
node_lock.cpp
Go to the documentation of this file.
1 /* lib/node_lock.cpp
2 
3 Copyright (c) 2005-2019 Made to Order Software Corp. All Rights Reserved
4 
6 
7 Permission is hereby granted, free of charge, to any
8 person obtaining a copy of this software and
9 associated documentation files (the "Software"), to
10 deal in the Software without restriction, including
11 without limitation the rights to use, copy, modify,
12 merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom
14 the Software is furnished to do so, subject to the
15 following conditions:
16 
17 The above copyright notice and this permission notice
18 shall be included in all copies or substantial
19 portions of the Software.
20 
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
22 ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
23 LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
24 FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
25 EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
28 ARISING FROM, OUT OF OR IN CONNECTION WITH THE
29 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 SOFTWARE.
31 
32 */
33 
34 #include "as2js/node.h"
35 
36 #include "as2js/exceptions.h"
37 
38 
57 namespace as2js
58 {
59 
60 
61 /**********************************************************************/
62 /**********************************************************************/
63 /*** NODE LOCK ******************************************************/
64 /**********************************************************************/
65 /**********************************************************************/
66 
67 
91 void Node::modifying() const
92 {
93  if(is_locked())
94  {
95  // print the node in stderr so one can see what node generated a problem
96  std::cerr << "The following node is locked:" << std::endl
97  << *this << std::endl;
98  throw exception_locked_node("trying to modify a locked node.");
99  }
100 }
101 
102 
114 bool Node::is_locked() const
115 {
116  return f_lock != 0;
117 }
118 
119 
165 {
166  ++f_lock;
167 }
168 
169 
203 {
204  if(f_lock <= 0)
205  {
206  throw exception_internal_error("somehow the Node::unlock() function was called when the lock counter is zero");
207  }
208 
209  --f_lock;
210 }
211 
212 
248  : f_node(node)
249 {
250  if(f_node)
251  {
252  f_node->lock();
253  }
254 }
255 
256 
268 {
269  try
270  {
271  unlock();
272  }
273  catch(exception_internal_error const &)
274  {
275  // not much we can do here, we are in a destructor...
276  }
277 }
278 
279 
294 {
295  if(f_node)
296  {
297  f_node->unlock();
298  f_node.reset();
299  }
300 }
301 
302 }
303 // namespace as2js
304 
305 // vim: ts=4 sw=4 et
void unlock()
Prematurely unlock the node.
Definition: node_lock.cpp:293
void lock()
Lock this node.
Definition: node_lock.cpp:164
int32_t f_lock
Definition: node.h:602
void modifying() const
Test whether the node can be modified.
Definition: node_lock.cpp:91
std::shared_ptr< Node > pointer_t
Definition: node.h:67
void unlock()
Unlock a node that was previously locked.
Definition: node_lock.cpp:202
Node::pointer_t f_node
Definition: node.h:651
NodeLock(Node::pointer_t node)
Safely lock a node.
Definition: node_lock.cpp:247
~NodeLock()
Destroy the NodeLock object.
Definition: node_lock.cpp:267
The AlexScript to JavaScript namespace.
Definition: compiler.cpp:37
bool is_locked() const
Check whether a node is locked.
Definition: node_lock.cpp:114

This document is part of the Snap! Websites Project.

Copyright by Made to Order Software Corp.

Syndicate content

Snap! Websites
An Open Source CMS System in C++

Contact Us Directly