mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-27 14:58:30 +00:00
Share file offset across processes
This change ensures that if a file descriptor for an open disk file gets shared by multiple processes within a process tree, then lseek() changes will be visible across processes, and read() / write() are synchronized. Note this only applies to Windows, because UNIX kernels already do this.
This commit is contained in:
parent
a80ab3f8fe
commit
761c6ad615
15 changed files with 256 additions and 63 deletions
|
@ -17,6 +17,8 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/state.internal.h"
|
||||
#include "libc/intrin/fds.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/thread/thread.h"
|
||||
|
||||
void __fds_lock(void) {
|
||||
|
@ -26,3 +28,23 @@ void __fds_lock(void) {
|
|||
void __fds_unlock(void) {
|
||||
pthread_mutex_unlock(&__fds_lock_obj);
|
||||
}
|
||||
|
||||
void __fd_lock(struct Fd *f) {
|
||||
pthread_mutex_lock(&f->shared->lock);
|
||||
}
|
||||
|
||||
void __fd_unlock(struct Fd *f) {
|
||||
pthread_mutex_unlock(&f->shared->lock);
|
||||
}
|
||||
|
||||
struct Cursor *__cursor_new(void) {
|
||||
struct Cursor *c;
|
||||
if ((c = _mapshared(sizeof(struct Cursor)))) {
|
||||
pthread_mutexattr_t attr;
|
||||
pthread_mutexattr_init(&attr);
|
||||
pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
|
||||
pthread_mutex_init(&c->lock, &attr);
|
||||
pthread_mutexattr_destroy(&attr);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue