diff --git a/repos/libports/src/lib/libc/internal/pthread.h b/repos/libports/src/lib/libc/internal/pthread.h index 6aa5f68a7a..5f762d09dd 100644 --- a/repos/libports/src/lib/libc/internal/pthread.h +++ b/repos/libports/src/lib/libc/internal/pthread.h @@ -37,6 +37,7 @@ namespace Libc { struct Pthread_registry; struct Pthread_blockade; struct Pthread_job; + struct Pthread_mutex; } @@ -373,4 +374,36 @@ struct Libc::Pthread_job : Monitor::Job }; +struct Libc::Pthread_mutex +{ + public: + + class Guard + { + private: + + Pthread_mutex &_mutex; + + public: + + explicit Guard(Pthread_mutex &mutex) : _mutex(mutex) { _mutex.lock(); } + + ~Guard() { _mutex.unlock(); } + }; + + private: + + pthread_mutex_t _mutex; + + public: + + Pthread_mutex() { pthread_mutex_init(&_mutex, nullptr); } + + ~Pthread_mutex() { pthread_mutex_destroy(&_mutex); } + + void lock() { pthread_mutex_lock(&_mutex); } + void unlock() { pthread_mutex_unlock(&_mutex); } +}; + + #endif /* _LIBC__INTERNAL__PTHREAD_H_ */ diff --git a/repos/libports/src/lib/libc/socket_fs_plugin.cc b/repos/libports/src/lib/libc/socket_fs_plugin.cc index ddeaf480a3..3bde44ff80 100644 --- a/repos/libports/src/lib/libc/socket_fs_plugin.cc +++ b/repos/libports/src/lib/libc/socket_fs_plugin.cc @@ -41,6 +41,7 @@ #include #include #include +#include #include @@ -248,7 +249,7 @@ struct Libc::Socket_fs::Context : Plugin_context ssize_t connect_status_len; connect_status_len = read(connect_fd(), connect_status, - sizeof(connect_status)); + sizeof(connect_status)); if (connect_status_len <= 0) { error("socket_fs: reading from the connect file failed"); @@ -1070,10 +1071,9 @@ static int read_ifaddr_file(sockaddr_in &sockaddr, Socket_fs::Absolute_path cons extern "C" int getifaddrs(struct ifaddrs **ifap) { - /* FIXME this should be a pthread_mutex because function uses blocking operations */ - static Mutex mutex; + static Pthread_mutex mutex; - Mutex::Guard guard(mutex); + Pthread_mutex::Guard guard(mutex); static sockaddr_in address; static sockaddr_in netmask { 0 }; @@ -1170,14 +1170,12 @@ bool Socket_fs::Plugin::poll(File_descriptor &fdo, struct pollfd &pfd) bool res { false }; - if ((pfd.events & POLLIN_MASK) && context->read_ready()) - { + if ((pfd.events & POLLIN_MASK) && context->read_ready()) { pfd.revents |= pfd.events & POLLIN_MASK; res = true; } - if ((pfd.events & POLLOUT_MASK) && context->write_ready()) - { + if ((pfd.events & POLLOUT_MASK) && context->write_ready()) { pfd.revents |= pfd.events & POLLOUT_MASK; res = true; }