mirror of
https://github.com/genodelabs/genode.git
synced 2025-04-09 04:15:52 +00:00
Linux: Add 'Platform_thread' destructor
This commit is contained in:
parent
d64dea51c0
commit
90395e9428
@ -68,7 +68,14 @@ Genode::Ep_socket_descriptor_registry *Genode::ep_sd_registry()
|
||||
*/
|
||||
static int lookup_tid_by_client_socket(int sd)
|
||||
{
|
||||
sockaddr_un name;
|
||||
/*
|
||||
* Synchronize calls so that the large 'sockaddr_un' can be allocated
|
||||
* in the BSS rather than the stack.
|
||||
*/
|
||||
Lock lock;
|
||||
Lock::Guard guard(lock);
|
||||
|
||||
static sockaddr_un name;
|
||||
socklen_t name_len = sizeof(name);
|
||||
int ret = lx_getpeername(sd, (sockaddr *)&name, &name_len);
|
||||
if (ret < 0)
|
||||
|
@ -60,6 +60,8 @@ class Genode::Socket_descriptor_registry
|
||||
Entry(int fd, int global_id) : fd(fd), global_id(global_id) { }
|
||||
|
||||
bool is_free() const { return fd == -1; }
|
||||
|
||||
void mark_as_free() { fd = -1; }
|
||||
};
|
||||
|
||||
Entry _entries[MAX_FDS];
|
||||
@ -75,6 +77,15 @@ class Genode::Socket_descriptor_registry
|
||||
throw Limit_reached();
|
||||
}
|
||||
|
||||
Entry &_find_entry_by_fd(int fd)
|
||||
{
|
||||
for (unsigned i = 0; i < MAX_FDS; i++)
|
||||
if (_entries[i].fd == fd)
|
||||
return _entries[i];
|
||||
|
||||
throw Limit_reached();
|
||||
}
|
||||
|
||||
bool _is_registered(int global_id) const
|
||||
{
|
||||
for (unsigned i = 0; i < MAX_FDS; i++)
|
||||
@ -112,6 +123,13 @@ class Genode::Socket_descriptor_registry
|
||||
entry = Entry(sd, global_id);
|
||||
}
|
||||
|
||||
void disassociate(int sd)
|
||||
{
|
||||
Genode::Lock::Guard guard(_lock);
|
||||
|
||||
_find_entry_by_fd(sd).mark_as_free();
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup file descriptor that belongs to specified global ID
|
||||
*
|
||||
|
@ -41,6 +41,8 @@ namespace Genode {
|
||||
*/
|
||||
Platform_thread(const char *name, unsigned priority, addr_t);
|
||||
|
||||
~Platform_thread();
|
||||
|
||||
/**
|
||||
* Cancel currently blocking operation
|
||||
*/
|
||||
|
@ -33,6 +33,18 @@ Platform_thread::Platform_thread(const char *name, unsigned, addr_t)
|
||||
}
|
||||
|
||||
|
||||
Platform_thread::~Platform_thread()
|
||||
{
|
||||
ep_sd_registry()->disassociate(_ncs.client_sd);
|
||||
|
||||
if (_ncs.client_sd)
|
||||
lx_close(_ncs.client_sd);
|
||||
|
||||
if (_ncs.server_sd)
|
||||
lx_close(_ncs.server_sd);
|
||||
}
|
||||
|
||||
|
||||
void Platform_thread::cancel_blocking()
|
||||
{
|
||||
PDBG("send cancel-blocking signal to %ld\n", _tid);
|
||||
|
Loading…
x
Reference in New Issue
Block a user