#include <xmog_lock_holder.h>
Collaboration diagram for xmog_lock_holder:

Public Member Functions | |
| xmog_lock_holder (xmog_java_ref &_toLock) | |
| Attempts to lock the given proxy object on the Java side. | |
| ~xmog_lock_holder () | |
| Unlocks the proxy object on the Java side. | |
In Java, you can write thread-safe code by protecting access to code blocks with the synchronized keyword, for example:
Object lock;
synchronized( lock )
{
// do something that must only be accessible to one thread at a time
}
In C++, you could directly use the xmog_java_ref.xmog_monitor_enter or xmog_java_ref.xmog_monitor_exit methods, but the xmog_lock_holder utility class is much more convenient.
The above code translates into C++ as follows:
Object lock( _use_java_ctor );
{
xmog_lock_holder( lock );
// do something that must only be accessible to one thread at a time
}
The scope defined by the parentheses defines the lifetime of the xmog_lock_holder instance. The constructor invokes the xmog_monitor_enter() method and the destructor invokes the xmog_monitor_exit() method.
1.4.1