21 #include <osl/mutex.hxx>
22 #include <osl/conditn.hxx>
23 #include <rtl/instance.hxx>
43 struct ProcessableEvent
52 ProcessableEvent(
const AnyEventRef& _rEvent, const ::rtl::Reference< IEventProcessor >& _xProcessor )
54 ,xProcessor( _xProcessor )
68 explicit EqualProcessor( const ::rtl::Reference< IEventProcessor >& _rProcessor ) :rProcessor( _rProcessor ) { }
70 bool operator()(
const ProcessableEvent& _rEvent )
72 return _rEvent.xProcessor.get() == rProcessor.get();
108 ::osl::MutexGuard aGuard(
m_xImpl->aMutex );
111 m_xImpl->aEvents.erase(std::remove_if(
m_xImpl->aEvents.begin(),
m_xImpl->aEvents.end(), EqualProcessor( _xProcessor ) ),
m_xImpl->aEvents.end());
117 ::osl::MutexGuard aGuard(
m_xImpl->aMutex );
123 m_xImpl->aPendingActions.set();
129 ::osl::MutexGuard aGuard(
m_xImpl->aMutex );
132 m_xImpl->aEvents.emplace_back( _rEvent, _xProcessor );
135 m_xImpl->aPendingActions.set();
143 m_xImpl->aPendingActions.wait();
146 osl::MutexGuard aGuard(
m_xImpl->aMutex);
153 aEvent =
m_xImpl->aEvents.front();
158 m_xImpl->aPendingActions.reset();
161 if (aEvent.aEvent.is()) {
162 assert(aEvent.xProcessor.is());
163 aEvent.xProcessor->processEvent(*aEvent.aEvent);
189 struct theNotifiersMutex :
public rtl::Static<osl::Mutex, theNotifiersMutex> {};
193 static std::vector<std::weak_ptr<AsyncEventNotifierAutoJoin>>
g_Notifiers;
197 std::vector<std::weak_ptr<AsyncEventNotifierAutoJoin>> notifiers;
199 ::osl::MutexGuard g(theNotifiersMutex::get());
202 for (std::weak_ptr<AsyncEventNotifierAutoJoin>
const& wNotifier : notifiers)
204 std::shared_ptr<AsyncEventNotifierAutoJoin>
const pNotifier(
208 pNotifier->terminate();
223 ::osl::MutexGuard g(theNotifiersMutex::get());
227 std::remove_if(g_Notifiers.begin(), g_Notifiers.end(),
228 [](std::weak_ptr<AsyncEventNotifierAutoJoin>
const&
w) {
234 std::shared_ptr<AsyncEventNotifierAutoJoin>
237 std::shared_ptr<AsyncEventNotifierAutoJoin>
const ret(
239 ::osl::MutexGuard g(theNotifiersMutex::get());
240 g_Notifiers.push_back(ret);
252 xThis->m_xImpl->pKeepThisAlive = xThis;
254 if (!xThis->create()) {
255 throw std::runtime_error(
"osl::Thread::create failed");
258 xThis->m_xImpl->pKeepThisAlive.reset();
278 m_xImpl->pKeepThisAlive.reset();
::rtl::Reference< AnyEvent > AnyEventRef
void JoinAsyncEventNotifiers()
virtual SAL_DLLPRIVATE ~AsyncEventNotifier() override
static std::shared_ptr< AsyncEventNotifierAutoJoin > newAsyncEventNotifierAutoJoin(char const *name)
virtual SAL_DLLPRIVATE ~AsyncEventNotifierBase()
std::deque< ProcessableEvent > EventQueue
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
virtual SAL_DLLPRIVATE void SAL_CALL run() override
std::shared_ptr< AsyncEventNotifierAutoJoin > pKeepThisAlive
AsyncEventNotifier(char const *name)
constructs a notifier thread
static void launch(std::shared_ptr< AsyncEventNotifierAutoJoin > const &)
void addEvent(const AnyEventRef &_rEvent, const ::rtl::Reference< IEventProcessor > &_xProcessor)
adds an event to the queue, together with the instance which is responsible for processing it ...
virtual void SAL_CALL terminate()
terminates the thread
virtual SAL_DLLPRIVATE void SAL_CALL onTerminated() override
void removeEventsForProcessor(const ::rtl::Reference< IEventProcessor > &_xProcessor)
removes all events for the given event processor from the queue
const ::rtl::Reference< IEventProcessor > & rProcessor
virtual SAL_DLLPRIVATE void execute()
virtual void SAL_CALL terminate() override
terminates the thread
static std::vector< std::weak_ptr< AsyncEventNotifierAutoJoin > > g_Notifiers
::osl::Condition aPendingActions
virtual SAL_DLLPRIVATE ~AsyncEventNotifierAutoJoin() override
virtual SAL_DLLPRIVATE void execute() override
virtual void SAL_CALL terminate() override
terminates the thread
std::unique_ptr< EventNotifierImpl > m_xImpl
SAL_DLLPRIVATE AsyncEventNotifierAutoJoin(char const *name)
virtual ~AnyEvent() override
::rtl::Reference< IEventProcessor > xProcessor