If fork flags != 0, share the file table..

..now xdu and xls work in xv6 userspace with the wq stuff..
上级 33750412
...@@ -1628,6 +1628,41 @@ tls_test(void) ...@@ -1628,6 +1628,41 @@ tls_test(void)
fprintf(1, "tls_test ok\n"); fprintf(1, "tls_test ok\n");
} }
static pthread_barrier_t ftable_bar;
static volatile int ftable_fd;
static void*
ftablethr(void *arg)
{
char buf[32];
int r;
pthread_barrier_wait(&ftable_bar);
r = read(ftable_fd, buf, sizeof(buf));
if (r < 0)
fprintf(2, "ftablethr: FAILED bad fd\n");
return 0;
}
static void
ftabletest(void)
{
printf("ftabletest...\n");
pthread_barrier_init(&ftable_bar, 0, 2);
pthread_t th;
pthread_create(&th, 0, &ftablethr, 0);
ftable_fd = open("README", 0);
if (ftable_fd < 0)
die("open");
pthread_barrier_wait(&ftable_bar);
wait();
printf("ftabletest ok\n");
}
static pthread_key_t tkey; static pthread_key_t tkey;
static pthread_barrier_t bar0, bar1; static pthread_barrier_t bar0, bar1;
enum { nthread = 8 }; enum { nthread = 8 };
...@@ -1718,6 +1753,7 @@ main(int argc, char *argv[]) ...@@ -1718,6 +1753,7 @@ main(int argc, char *argv[])
bigdir(); // slow bigdir(); // slow
tls_test(); tls_test();
thrtest(); thrtest();
ftabletest();
exectest(); exectest();
......
...@@ -460,12 +460,17 @@ fork(int flags) ...@@ -460,12 +460,17 @@ fork(int flags)
// Clear %eax so that fork returns 0 in the child. // Clear %eax so that fork returns 0 in the child.
np->tf->rax = 0; np->tf->rax = 0;
if (flags == 0) {
np->ftable = new filetable(*myproc()->ftable); np->ftable = new filetable(*myproc()->ftable);
if (np->ftable == nullptr) { if (np->ftable == nullptr) {
// XXX(sbw) leaking? // XXX(sbw) leaking?
freeproc(np); freeproc(np);
return -1; return -1;
} }
} else {
myproc()->ftable->incref();
np->ftable = myproc()->ftable;
}
np->cwd = idup(myproc()->cwd); np->cwd = idup(myproc()->cwd);
pid = np->pid; pid = np->pid;
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论