| 1 | /***************************************************************************** |
| 2 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | you may not use this file except in compliance with the License. |
| 4 | You may obtain a copy of the License at |
| 5 | |
| 6 | http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | |
| 8 | Unless required by applicable law or agreed to in writing, software |
| 9 | distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | See the License for the specific language governing permissions and |
| 12 | limitations under the License. |
| 13 | |
| 14 | See NOTICE file for details. |
| 15 | *****************************************************************************/ |
| 16 | #include "jpype.h" |
| 17 | #include "jp_monitor.h" |
| 18 | |
| 19 | JPMonitor::JPMonitor(jobject value) : m_Value(value) |
| 20 | { |
| 21 | } |
| 22 | |
| 23 | JPMonitor::~JPMonitor() |
| 24 | = default; |
| 25 | |
| 26 | void JPMonitor::enter() |
| 27 | { |
| 28 | // This can hold off for a while so we need to release resource |
| 29 | // so that we don't dead lock. |
| 30 | JPPyCallRelease call; |
| 31 | JPJavaFrame frame = JPJavaFrame::outer(); |
| 32 | frame.MonitorEnter(m_Value.get()); |
| 33 | } |
| 34 | |
| 35 | void JPMonitor::exit() |
| 36 | { |
| 37 | JPJavaFrame frame = JPJavaFrame::outer(); |
| 38 | frame.MonitorExit(m_Value.get()); |
| 39 | } |
| 40 |