提交 2eb42789 创建 作者: Nickolai Zeldovich's avatar Nickolai Zeldovich

get rid of macros around gcc __sync_* ops

上级 8e76d1ae
...@@ -27,14 +27,14 @@ ...@@ -27,14 +27,14 @@
#if CILKENABLE #if CILKENABLE
#include "types.h" #include "types.h"
#include "kernel.h" #include "kernel.hh"
#include "amd64.h" #include "amd64.h"
#include "cpu.h" #include "cpu.hh"
#include "bits.h" #include "bits.hh"
#include "spinlock.h" #include "spinlock.h"
#include "condvar.h" #include "condvar.h"
#include "queue.h" #include "queue.h"
#include "proc.h" #include "proc.hh"
#include "mtrace.h" #include "mtrace.h"
#include "qlock.h" #include "qlock.h"
...@@ -114,7 +114,7 @@ __cilk_pop(struct cilkqueue *q) ...@@ -114,7 +114,7 @@ __cilk_pop(struct cilkqueue *q)
i = q->head; i = q->head;
if ((i - q->tail) == 0) { if ((i - q->tail) == 0) {
ql_unlock(&q->lock, &qn); ql_unlock(&q->lock, &qn);
return NULL; return 0;
} }
i = (i-1) & (NSLOTS-1); i = (i-1) & (NSLOTS-1);
q->head--; q->head--;
...@@ -134,7 +134,7 @@ __cilk_steal(struct cilkqueue *q) ...@@ -134,7 +134,7 @@ __cilk_steal(struct cilkqueue *q)
i = q->tail; i = q->tail;
if ((i - q->head) == 0) { if ((i - q->head) == 0) {
ql_unlock(&q->lock, &qn); ql_unlock(&q->lock, &qn);
return NULL; return 0;
} }
i = i & (NSLOTS-1); i = i & (NSLOTS-1);
q->tail++; q->tail++;
...@@ -147,13 +147,13 @@ __cilk_steal(struct cilkqueue *q) ...@@ -147,13 +147,13 @@ __cilk_steal(struct cilkqueue *q)
static void static void
__cilk_run(struct cilkthread *th) __cilk_run(struct cilkthread *th)
{ {
void (*fn)(uptr arg0, uptr arg1) = (void*)th->rip; void (*fn)(uptr arg0, uptr arg1) = (void(*)(uptr,uptr))th->rip;
struct cilkframe *old = mycpu()->cilkframe; struct cilkframe *old = mycpu()->cilkframe;
mycpu()->cilkframe = th->frame; mycpu()->cilkframe = th->frame;
fn(th->arg0, th->arg1); fn(th->arg0, th->arg1);
mycpu()->cilkframe = old; mycpu()->cilkframe = old;
subfetch(&th->frame->ref, 1); th->frame->ref--;
kfree(th); kfree(th);
} }
...@@ -163,7 +163,7 @@ __cilk_run(struct cilkthread *th) ...@@ -163,7 +163,7 @@ __cilk_run(struct cilkthread *th)
void void
cilk_push(void *rip, u64 arg0, u64 arg1) cilk_push(void *rip, u64 arg0, u64 arg1)
{ {
void (*fn)(uptr, uptr) = rip; void (*fn)(uptr, uptr) = (void(*)(uptr,uptr))rip;
struct cilkthread *th; struct cilkthread *th;
th = (struct cilkthread *) kalloc(); th = (struct cilkthread *) kalloc();
...@@ -179,8 +179,8 @@ cilk_push(void *rip, u64 arg0, u64 arg1) ...@@ -179,8 +179,8 @@ cilk_push(void *rip, u64 arg0, u64 arg1)
if (__cilk_push(cilk_cur(), th)) { if (__cilk_push(cilk_cur(), th)) {
kfree(th); kfree(th);
fn(arg0, arg1); fn(arg0, arg1);
} else } else
fetchadd(&cilk_frame()->ref, 1); cilk_frame()->ref++;
} }
// Try to execute one cilkthread. // Try to execute one cilkthread.
...@@ -248,7 +248,7 @@ cilk_end(void) ...@@ -248,7 +248,7 @@ cilk_end(void)
} }
} }
} }
mycpu()->cilkframe = NULL; mycpu()->cilkframe = 0;
popcli(); popcli();
} }
...@@ -281,7 +281,7 @@ testcilk(void) ...@@ -281,7 +281,7 @@ testcilk(void)
s = rdtsc(); s = rdtsc();
cilk_start(); cilk_start();
for (i = 0; i < iters; i++) for (i = 0; i < iters; i++)
cilk_push(__test_stub, i, i); cilk_push((void*) __test_stub, i, i);
cilk_end(); cilk_end();
e = rdtsc(); e = rdtsc();
cprintf("testcilk: %lu\n", (e-s)/iters); cprintf("testcilk: %lu\n", (e-s)/iters);
......
...@@ -18,11 +18,7 @@ ...@@ -18,11 +18,7 @@
#define NELEM(x) (sizeof(x)/sizeof((x)[0])) #define NELEM(x) (sizeof(x)/sizeof((x)[0]))
#define cmpswap(ptr, old, new) __sync_bool_compare_and_swap(ptr, old, new)
#define subfetch(ptr, val) __sync_sub_and_fetch(ptr, val)
#define fetchadd(ptr, val) __sync_fetch_and_add(ptr, val)
#define __offsetof offsetof #define __offsetof offsetof
#define __mpalign__ __attribute__((aligned(CACHELINE))) #define __mpalign__ __attribute__((aligned(CACHELINE)))
#define __padout__ char __padout[0] __attribute__((aligned(CACHELINE))) #define __padout__ char __padout[0] __attribute__((aligned(CACHELINE)))
#define __noret__ __attribute__((noreturn)) #define __noret__ __attribute__((noreturn))
#include "spinlock.h" #include "spinlock.h"
#include "atomic.hh"
// Saved registers for kernel context switches. // Saved registers for kernel context switches.
// (also implicitly defined in swtch.S) // (also implicitly defined in swtch.S)
...@@ -14,7 +15,7 @@ struct context { ...@@ -14,7 +15,7 @@ struct context {
// Work queue frame // Work queue frame
struct cilkframe { struct cilkframe {
volatile u64 ref; volatile std::atomic<u64> ref;
}; };
// Per-process, per-stack meta data for mtrace // Per-process, per-stack meta data for mtrace
......
...@@ -12,7 +12,7 @@ typedef struct { ...@@ -12,7 +12,7 @@ typedef struct {
static inline void static inline void
ql_init(qlock_t *l, const char *name) ql_init(qlock_t *l, const char *name)
{ {
l->v = NULL; l->v = 0;
l->name = name; l->name = name;
} }
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论