mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 01:07:36 +00:00
LibC+LibPthread: Implement pthread_atfork()
This required a bit of rearchitecture, as pthread_atfork() required a mutex, and duplicating a mutex impl for it was silly. As such, this patch moves some standalone bits of pthread into LibC and uses those to implement atfork(). It should be noted that for programs that don't use atfork(), this mechanism only costs two atomic loads (as opposed to the normal mutex lock+unlock) :^)
This commit is contained in:
parent
8e074f8665
commit
bb777459a0
6 changed files with 231 additions and 37 deletions
|
@ -29,6 +29,7 @@
|
|||
#include <AK/Vector.h>
|
||||
#include <alloca.h>
|
||||
#include <assert.h>
|
||||
#include <bits/pthread_integration.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <getopt.h>
|
||||
|
@ -75,10 +76,15 @@ int fchown(int fd, uid_t uid, gid_t gid)
|
|||
|
||||
pid_t fork()
|
||||
{
|
||||
__pthread_fork_prepare();
|
||||
|
||||
int rc = syscall(SC_fork);
|
||||
if (rc == 0) {
|
||||
s_cached_tid = 0;
|
||||
s_cached_pid = 0;
|
||||
__pthread_fork_child();
|
||||
} else if (rc != -1) {
|
||||
__pthread_fork_parent();
|
||||
}
|
||||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue