File tree 3 files changed +54
-0
lines changed 3 files changed +54
-0
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ OBJECTS=ck_ticket.THROUGHPUT ck_ticket.LATENCY \
10
10
ck_ticket_pb.THROUGHPUT ck_ticket_pb.LATENCY \
11
11
ck_anderson.THROUGHPUT ck_anderson.LATENCY \
12
12
ck_spinlock.THROUGHPUT ck_spinlock.LATENCY \
13
+ pthread.THROUGHPUT pthread.LATENCY \
13
14
ck_hclh.THROUGHPUT ck_hclh.LATENCY
14
15
15
16
all : $(OBJECTS )
@@ -80,6 +81,12 @@ ck_anderson.THROUGHPUT: ck_anderson.c
80
81
ck_anderson.LATENCY : ck_anderson.c
81
82
$(CC ) -DLATENCY $(CFLAGS ) -o ck_anderson.LATENCY ck_anderson.c -lm
82
83
84
+ pthread.THROUGHPUT : pthread.c
85
+ $(CC ) -DTHROUGHPUT $(CFLAGS ) -o pthread.THROUGHPUT pthread.c -lm
86
+
87
+ pthread.LATENCY : pthread.c
88
+ $(CC ) -DLATENCY $(CFLAGS ) -o pthread.LATENCY pthread.c -lm
89
+
83
90
clean :
84
91
rm -rf * .dSYM * .exe $(OBJECTS )
85
92
Original file line number Diff line number Diff line change
1
+ #include "../pthread.h"
2
+
3
+ #ifdef THROUGHPUT
4
+ #include "throughput.h"
5
+ #elif defined(LATENCY )
6
+ #include "latency.h"
7
+ #endif
Original file line number Diff line number Diff line change
1
+ #include <ck_cc.h>
2
+ #include <pthread.h>
3
+
4
+ CK_CC_INLINE static void
5
+ spin_lock (volatile unsigned int * lock )
6
+ {
7
+ #ifdef __x86_64__
8
+ __asm__ __volatile__(
9
+ "\n1:\t"
10
+ "lock ; decl %0\n\t"
11
+ "jns 2f\n"
12
+ "3:\n"
13
+ "rep;nop\n\t"
14
+ "cmpl $0,%0\n\t"
15
+ "jle 3b\n\t"
16
+ "jmp 1b\n"
17
+ "2:\t" : "=m" (* lock ) : : "memory" );
18
+ #else
19
+ * lock = 1 ;
20
+ #endif
21
+
22
+ return ;
23
+ }
24
+
25
+ CK_CC_INLINE static void
26
+ spin_unlock (volatile unsigned int * lock )
27
+ {
28
+ #ifdef __x86_64__
29
+ __asm__ __volatile__("movl $1,%0" :"=m" (* lock ) :: "memory" );
30
+ #else
31
+ * lock = 0 ;
32
+ return ;
33
+ #endif
34
+ }
35
+
36
+ #define LOCK_NAME "pthread_mutex"
37
+ #define LOCK_DEFINE pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER
38
+ #define LOCK pthread_mutex_lock(&lock)
39
+ #define UNLOCK pthread_mutex_unlock(&lock)
40
+
You can’t perform that action at this time.
0 commit comments