Skip to content

Commit

Permalink
Fix timer state after event queue was destroyed
Browse files Browse the repository at this point in the history
* Hw tests show state is unaffected by external destruction of the event queue

* Minor race regarding state check fixed (can result in an undestroyable state)
  • Loading branch information
elad335 committed Mar 27, 2019
1 parent 76248a2 commit a170b56
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
29 changes: 15 additions & 14 deletions rpcs3/Emu/Cell/lv2/sys_timer.cpp
@@ -1,4 +1,4 @@
#include "stdafx.h"
#include "stdafx.h"
#include "Emu/Memory/vm.h"
#include "Emu/System.h"
#include "Emu/IdManager.h"
Expand Down Expand Up @@ -30,19 +30,24 @@ void lv2_timer_context::operator()()
{
std::lock_guard lock(mutex);

if (_state != SYS_TIMER_STATE_RUN)
{
continue;
}

if (const auto queue = port.lock())
{
queue->send(source, data1, data2, next);
}

if (period)
{
// Set next expiration time and check again (HACK)
expire += period;
continue;
}
if (period)
{
// Set next expiration time and check again (HACK)
expire += period;
continue;
}

// Stop: oneshot or the event port was disconnected (TODO: is it correct?)
// Stop after oneshot
state = SYS_TIMER_STATE_STOP;
continue;
}
Expand All @@ -61,12 +66,6 @@ void lv2_timer_context::operator()()
}
}

void lv2_timer_context::on_abort()
{
// Signal thread using invalid state
state = -1;
}

error_code sys_timer_create(vm::ptr<u32> timer_id)
{
sys_timer.warning("sys_timer_create(timer_id=*0x%x)", timer_id);
Expand All @@ -93,6 +92,8 @@ error_code sys_timer_destroy(u32 timer_id)
return CELL_EISCONN;
}

// Signal thread using invalid state
timer.state = -1;
return {};
});

Expand Down
1 change: 0 additions & 1 deletion rpcs3/Emu/Cell/lv2/sys_timer.h
Expand Up @@ -22,7 +22,6 @@ struct lv2_timer_context : lv2_obj
static const u32 id_base = 0x11000000;

void operator()();
void on_abort();

shared_mutex mutex;
atomic_t<u32> state{SYS_TIMER_STATE_STOP};
Expand Down

0 comments on commit a170b56

Please sign in to comment.