kernel: Use a mutex to allocate new posix timers for a thread
This commit is contained in:
parent
9e65131452
commit
7b2977a036
@ -118,7 +118,6 @@ Result<u64> sys_timer_create(Registers*, SyscallArgs args)
|
|||||||
if (ksevp.sigev_signo <= 0 || ksevp.sigev_signo > NSIG) return err(EINVAL);
|
if (ksevp.sigev_signo <= 0 || ksevp.sigev_signo > NSIG) return err(EINVAL);
|
||||||
|
|
||||||
int id = TRY(current->allocate_timerid());
|
int id = TRY(current->allocate_timerid());
|
||||||
current->posix_timers[id] = Timer {};
|
|
||||||
|
|
||||||
Timer* timer = current->posix_timers[id].value_ptr();
|
Timer* timer = current->posix_timers[id].value_ptr();
|
||||||
timer->signo = ksevp.sigev_signo;
|
timer->signo = ksevp.sigev_signo;
|
||||||
|
@ -61,10 +61,15 @@ Result<FileDescriptor*> Thread::resolve_fd(int fd)
|
|||||||
|
|
||||||
Result<int> Thread::allocate_timerid()
|
Result<int> Thread::allocate_timerid()
|
||||||
{
|
{
|
||||||
|
ScopedMutexLock lock(posix_timer_mutex);
|
||||||
|
|
||||||
for (int i = 0; i < MAX_POSIX_TIMERS; i++)
|
for (int i = 0; i < MAX_POSIX_TIMERS; i++)
|
||||||
{
|
{
|
||||||
// FIXME: Possible race condition, this should be used alongside a mutex.
|
if (!posix_timers[i].has_value())
|
||||||
if (!posix_timers[i].has_value()) { return i; }
|
{
|
||||||
|
posix_timers[i] = Timer {};
|
||||||
|
return i;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return err(EMFILE);
|
return err(EMFILE);
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include "arch/MMU.h"
|
#include "arch/MMU.h"
|
||||||
#include "fs/OpenFileDescription.h"
|
#include "fs/OpenFileDescription.h"
|
||||||
#include "fs/VFS.h"
|
#include "fs/VFS.h"
|
||||||
|
#include "lib/Mutex.h"
|
||||||
#include "memory/AddressSpace.h"
|
#include "memory/AddressSpace.h"
|
||||||
#include <bits/signal.h>
|
#include <bits/signal.h>
|
||||||
#include <luna/Bitset.h>
|
#include <luna/Bitset.h>
|
||||||
@ -109,6 +110,7 @@ struct Thread : public LinkedListNode<Thread>
|
|||||||
Clock profiling_clock;
|
Clock profiling_clock;
|
||||||
|
|
||||||
Option<Timer> posix_timers[MAX_POSIX_TIMERS];
|
Option<Timer> posix_timers[MAX_POSIX_TIMERS];
|
||||||
|
Mutex posix_timer_mutex;
|
||||||
|
|
||||||
Result<int> allocate_timerid();
|
Result<int> allocate_timerid();
|
||||||
Result<Timer*> resolve_timerid(int id);
|
Result<Timer*> resolve_timerid(int id);
|
||||||
|
Loading…
Reference in New Issue
Block a user