xthread_create takes fork flags

上级 f838a215
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "uspinlock.h" #include "uspinlock.h"
#include "mtrace.h" #include "mtrace.h"
#include "pthread.h" #include "pthread.h"
#include "fcntl.h"
#endif #endif
#include "xsys.h" #include "xsys.h"
#include <sys/mman.h> #include <sys/mman.h>
...@@ -20,6 +21,7 @@ ...@@ -20,6 +21,7 @@
enum { readaccess = 1 }; enum { readaccess = 1 };
enum { verbose = 0 }; enum { verbose = 0 };
enum { npg = 1 }; enum { npg = 1 };
enum { xthread_flags = FORK_SEPARATE_PGMAP };
static pthread_barrier_t bar; static pthread_barrier_t bar;
static pthread_barrier_t bar2; static pthread_barrier_t bar2;
...@@ -79,7 +81,7 @@ main(int ac, char **av) ...@@ -79,7 +81,7 @@ main(int ac, char **av)
pthread_barrier_init(&bar2, 0, nthread); pthread_barrier_init(&bar2, 0, nthread);
for(u64 i = 0; i < nthread; i++) { for(u64 i = 0; i < nthread; i++) {
pthread_create(&tid[i], 0, thr, (void*) i); xthread_create(&tid[i], xthread_flags, thr, (void*) i);
if (0) printf("mapbench[%d]: child %d\n", getpid(), tid); if (0) printf("mapbench[%d]: child %d\n", getpid(), tid);
} }
......
...@@ -24,3 +24,7 @@ int pthread_barrier_init(pthread_barrier_t *b, ...@@ -24,3 +24,7 @@ int pthread_barrier_init(pthread_barrier_t *b,
const pthread_barrierattr_t *attr, const pthread_barrierattr_t *attr,
unsigned count); unsigned count);
int pthread_barrier_wait(pthread_barrier_t *b); int pthread_barrier_wait(pthread_barrier_t *b);
// Special xv6 pthread_create, flags is FORK_* bits
int xthread_create(pthread_t* tid, int flags,
void* (*start)(void*), void* arg);
#if defined(LINUX) #if defined(LINUX)
#define O_CREATE O_CREAT #define O_CREATE O_CREAT
#define FORK_SEPARATE_PGMAP 0
#define xfork() fork() #define xfork() fork()
#define xexit() exit(EXIT_SUCCESS) #define xexit() exit(EXIT_SUCCESS)
static inline void xwait() static inline void xwait()
...@@ -17,6 +18,8 @@ static inline void xwait() ...@@ -17,6 +18,8 @@ static inline void xwait()
#define mtenable_type(x, y) do { } while (0) #define mtenable_type(x, y) do { } while (0)
#define mtdisable(x) do { } while(0) #define mtdisable(x) do { } while(0)
#define xpthread_join(tid) pthread_join(tid, nullptr); #define xpthread_join(tid) pthread_join(tid, nullptr);
#define xthread_create(ptr, x, fn, arg) \
pthread_create((ptr), 0, (fn), (arg))
#else // Must be xv6 #else // Must be xv6
......
...@@ -31,6 +31,20 @@ pthread_create(pthread_t* tid, const pthread_attr_t* attr, ...@@ -31,6 +31,20 @@ pthread_create(pthread_t* tid, const pthread_attr_t* attr,
return 0; return 0;
} }
int
xthread_create(pthread_t* tid, int flags,
void* (*start)(void*), void* arg)
{
char* base = (char*) sbrk(stack_size);
int t = forkt(base + stack_size, (void*) start, arg,
FORK_SHARE_VMAP | FORK_SHARE_FD | flags);
if (t < 0)
return t;
*tid = t;
return 0;
}
pthread_t pthread_t
pthread_self() pthread_self()
{ {
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论