Codemesh Runtime v3 C++ API Reference  3.9.205
xmog_lock_holder.h
1 //
2 // Copyright (c) 1999-2020 by Codemesh, Inc.. ALL RIGHTS RESERVED.
3 //
4 
5 
6 #ifndef xmogLockHolder_inc
7 #define xmogLockHolder_inc
8 
9 
10 #include "xmog_base.h"
11 #include "xmog_java_ref.h"
12 #include "xmog_java_class.h"
13 
14 
49 {
50 private:
51 
52  xmog_java_ref & toLock_;
53 
54  int holding_;
55 
57  xmog_lock_holder & operator = ( const xmog_lock_holder & );
58 
59 public:
60 
65  toLock_( _toLock ),
66  holding_( 0 )
67  {
68  try
69  {
70 # if !defined(XMOG_NULL_NAME)
71  if( toLock_ != null )
72  {
73  toLock_.xmog_monitor_enter();
74  holding_ = 1;
75  }
76 # else
77  if( toLock_ != XMOG_NULL_NAME )
78  {
79  toLock_.xmog_monitor_enter();
80  holding_ = 1;
81  }
82 # endif
83  }
84  catch( xmog_exception & )
85  {
86  throw;
87  }
88  }
89 
94  {
95  if( holding_ )
96  {
97  toLock_.xmog_monitor_exit();
98  }
99  }
100 };
101 
102 
103 #endif /* xmogLockHolder_inc */
xmog_lock_holder
A utility class used for synchronizing access to a Java object.
Definition: xmog_lock_holder.h:48
xmog_java_ref::xmog_monitor_exit
virtual void xmog_monitor_exit(xmog_localenv *env=NULL) const
Leaves a lock in the object.
xmog_java_ref::xmog_monitor_enter
virtual void xmog_monitor_enter(xmog_localenv *env=NULL) const
Attempts to enter into a lock on the object.
xmog_java_ref
The wrapper base type representing C++ proxy instances for Java objects.
Definition: xmog_java_ref.h:19
xmog_exception
The wrapper for exceptions that occur on the Java side.
Definition: xmog_exception.h:46
xmog_lock_holder::xmog_lock_holder
xmog_lock_holder(xmog_java_ref &_toLock)
Attempts to lock the given proxy object on the Java side.
Definition: xmog_lock_holder.h:64
xmog_lock_holder::~xmog_lock_holder
~xmog_lock_holder()
Unlocks the proxy object on the Java side.
Definition: xmog_lock_holder.h:93

Copyright (c) 1999-2020 by Codemesh, Inc., ALL RIGHTS RESERVED.