kernel/thread: Properly implement has_data for non-current threads.

This was left unimplemented since the dawn of Haiku; but it's so rarely
used nobody seems to have noticed. I've taken care to leave it optimized
for the current thread case.

Change-Id: Ib028a37963b2da6d0ca9b4dbd5a5f4a74ecf25b4
Reviewed-on: https://review.haiku-os.org/c/860
Reviewed-by: Adrien Destugues <[email protected]>
This commit is contained in:
Augustin Cavalier
2019-01-09 17:55:43 +00:00
committed by waddlesplash
parent 647b5a29e9
commit e6bb34532a
+27 -7
View File
@@ -3041,20 +3041,40 @@ receive_data(thread_id *sender, void *buffer, size_t bufferSize)
}
bool
has_data(thread_id thread)
static bool
thread_has_data(thread_id id, bool kernel)
{
// TODO: The thread argument is ignored.
int32 count;
Thread* currentThread = thread_get_current_thread();
Thread* thread;
BReference<Thread> threadReference;
if (id == currentThread->id) {
thread = currentThread;
} else {
thread = Thread::Get(id);
if (thread == NULL)
return false;
if (get_sem_count(thread_get_current_thread()->msg.read_sem,
&count) != B_OK)
threadReference.SetTo(thread, true);
}
if (!kernel && thread->team != currentThread->team)
return false;
int32 count;
if (get_sem_count(thread->msg.read_sem, &count) != B_OK)
return false;
return count == 0 ? false : true;
}
bool
has_data(thread_id thread)
{
return thread_has_data(thread, true);
}
status_t
_get_thread_info(thread_id id, thread_info *info, size_t size)
{
@@ -3581,7 +3601,7 @@ _user_wait_for_thread(thread_id id, status_t *userReturnCode)
bool
_user_has_data(thread_id thread)
{
return has_data(thread);
return thread_has_data(thread, false);
}