summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibC/bits/stdio_file_implementation.h
diff options
context:
space:
mode:
authorConor Byrne <71222289+cbyrneee@users.noreply.github.com>2022-01-01 00:18:21 +0000
committerBrian Gianforcaro <b.gianfo@gmail.com>2022-01-01 09:50:32 +0000
commit8515d7d5abf48663494fddfba077e302a34e768e (patch)
tree71c0e7a02e36817fde5fead1ba0529a441167c95 /Userland/Libraries/LibC/bits/stdio_file_implementation.h
parentaa0db4e4b053b6ef06f14ae08be4ac692856753e (diff)
downloadserenity-8515d7d5abf48663494fddfba077e302a34e768e.zip
LibC: Implement ``flockfile`` and ``funlockfile``
To do this, we must set the type attribute when initializing a FILE to ``__PTHREAD_MUTEX_RECURSIVE``.
Diffstat (limited to 'Userland/Libraries/LibC/bits/stdio_file_implementation.h')
-rw-r--r--Userland/Libraries/LibC/bits/stdio_file_implementation.h11
1 files changed, 5 insertions, 6 deletions
diff --git a/Userland/Libraries/LibC/bits/stdio_file_implementation.h b/Userland/Libraries/LibC/bits/stdio_file_implementation.h
index 34d3172866..48029992ad 100644
--- a/Userland/Libraries/LibC/bits/stdio_file_implementation.h
+++ b/Userland/Libraries/LibC/bits/stdio_file_implementation.h
@@ -19,7 +19,8 @@ public:
: m_fd(fd)
, m_mode(mode)
{
- __pthread_mutex_init(&m_mutex, nullptr);
+ pthread_mutexattr_t attr = { __PTHREAD_MUTEX_RECURSIVE };
+ __pthread_mutex_init(&m_mutex, &attr);
}
~FILE();
@@ -31,6 +32,9 @@ public:
void purge();
bool close();
+ void lock();
+ void unlock();
+
int fileno() const { return m_fd; }
bool eof() const { return m_eof; }
int mode() const { return m_mode; }
@@ -115,9 +119,6 @@ private:
// Flush *some* data from the buffer.
bool write_from_buffer();
- void lock();
- void unlock();
-
int m_fd { -1 };
int m_mode { 0 };
u8 m_flags { Flags::None };
@@ -126,8 +127,6 @@ private:
pid_t m_popen_child { -1 };
Buffer m_buffer;
__pthread_mutex_t m_mutex;
-
- friend class ScopedFileLock;
};
class ScopedFileLock {