libc-plugin: make fd allocator thread safe

issue #2488
This commit is contained in:
Sebastian Sumpf 2017-08-15 18:32:40 +02:00 committed by Christian Helmuth
parent 17df52bfbd
commit 61ae2e5b80
2 changed files with 8 additions and 0 deletions

View File

@ -68,6 +68,10 @@ namespace Libc {
class File_descriptor_allocator : Allocator_avl_tpl<File_descriptor>
{
private:
Genode::Lock _lock;
public:
/**

View File

@ -51,6 +51,8 @@ File_descriptor *File_descriptor_allocator::alloc(Plugin *plugin,
Plugin_context *context,
int libc_fd)
{
Lock::Guard guard(_lock);
/* we use addresses returned by the allocator as file descriptors */
addr_t addr = (libc_fd <= ANY_FD ? ANY_FD : libc_fd);
@ -79,6 +81,7 @@ File_descriptor *File_descriptor_allocator::alloc(Plugin *plugin,
void File_descriptor_allocator::free(File_descriptor *fdo)
{
Lock::Guard guard(_lock);
::free((void *)fdo->fd_path);
Allocator_avl_base::free(reinterpret_cast<void*>(fdo->libc_fd));
}
@ -86,6 +89,7 @@ void File_descriptor_allocator::free(File_descriptor *fdo)
File_descriptor *File_descriptor_allocator::find_by_libc_fd(int libc_fd)
{
Lock::Guard guard(_lock);
return metadata(reinterpret_cast<void*>(libc_fd));
}