as2js: as2js::NodeLock Class Reference

as2js::NodeLock Class Reference

#include <node.h>

Public Member Functions  NodeLock (Node::pointer_t node)  Safely lock a node. More...
   ~NodeLock ()  Destroy the NodeLock object. More...
  void unlock ()  Prematurely unlock the node. More...
  Private Attributes Node::pointer_t f_node = Node::pointer_t()   Detailed Description

Definition at line 641 of file node.h.

Constructor & Destructor Documentation
as2js::NodeLock::NodeLock ( Node::pointer_t  node)

This constructor is used to lock a node within a scope.

{
NodeLock lock(my_node);
...code...
} // auto-unlock here

Note that the unlock() function can be used to prematuraly unlock a node. It is very important to use the unlock() function of the NodeLock() otherwise it will attempt to unlock the node again when it gets out of scope (although that bug will be caught).

{
NodeLock lock(my_node);
...code...
lock.unlock();
...code...
} // already unlocked...

The function accepts a null pointer as parameter. This is useful in many situation where we do not know whether the node is null and it would make it complicated to have to check.

Parameters
[in]nodeThe node to be locked.
See also
Node::lock()
unlock()

Definition at line 247 of file node_lock.cpp.

References f_node.

as2js::NodeLock::~NodeLock ( )

The destructor of the NodeLock object ensures that the node passed as a parameter to the constructor gets unlocked.

If the pointer was null or the unlock() function was called early, nothing happens.

See also
unlock()

Definition at line 267 of file node_lock.cpp.

References unlock().

Member Function Documentation
void as2js::NodeLock::unlock ( )

This function can be used to unlock a node before the end of a scope is reached. There are cases where that may be necessary.

Note that this function is also called by the destructor. To avoid a double unlock on a node, the function sets the node pointer to null before returning. This means this function can safely be called any number of times and the lock counter of the node will remain valid.

See also
Node::unlock()

Definition at line 293 of file node_lock.cpp.

References f_node.

Referenced by as2js::Compiler::define_function_type(), as2js::Compiler::resolve_call(), as2js::Compiler::variable(), and ~NodeLock().

Member Data Documentation
Node::pointer_t as2js::NodeLock::f_node = Node::pointer_t() private

Definition at line 651 of file node.h.

Referenced by NodeLock(), and unlock().


The documentation for this class was generated from the following files:
  • /home/snapwebsites/snapcpp/contrib/as2js/include/as2js/node.h
  • /home/snapwebsites/snapcpp/contrib/as2js/lib/node_lock.cpp

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