mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-23 01:21:42 +00:00
Rewrite Java Notifier and update Interrupt JNI.
Notifier takes advantage of the multi-notifier support now in HAL. Each Notifier is now handled by a separate thread at the JNI level, so one notifier taking longer to process (or being breakpointed) does not stop the other notifiers from running. These threads are configured as daemon threads. In both Notifier and Interrupt JNI, the JNI thread attachment no longer repeatedly calls AttachCurrentThread(). This improves performance but more importantly avoids impacting the Eclipse debugger, which attempts to track each call to AttachCurrentThread() as a separate Java thread. Note: There is currently no way to free an interrupt handler. Repeatedly calling attachInterruptHandler() will result in leaking previous handlers. Change-Id: Ib12e3df88943c03e0269d3906e5b153767139391
This commit is contained in:
31
wpilibj/src/athena/cpp/lib/SafeThread.cpp
Normal file
31
wpilibj/src/athena/cpp/lib/SafeThread.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2015. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include "SafeThread.h"
|
||||
|
||||
//using namespace nt;
|
||||
|
||||
void detail::SafeThreadOwnerBase::Start(SafeThread* thr) {
|
||||
SafeThread* curthr = nullptr;
|
||||
SafeThread* newthr = thr;
|
||||
if (!m_thread.compare_exchange_strong(curthr, newthr)) {
|
||||
delete newthr;
|
||||
return;
|
||||
}
|
||||
std::thread([=]() {
|
||||
newthr->Main();
|
||||
delete newthr;
|
||||
}).detach();
|
||||
}
|
||||
|
||||
void detail::SafeThreadOwnerBase::Stop() {
|
||||
SafeThread* thr = m_thread.exchange(nullptr);
|
||||
if (!thr) return;
|
||||
std::lock_guard<std::mutex> lock(thr->m_mutex);
|
||||
thr->m_active = false;
|
||||
thr->m_cond.notify_one();
|
||||
}
|
||||
Reference in New Issue
Block a user