Browse code

*** empty log message ***

Andrei Pelinescu-Onciul authored on 13/02/2002 19:38:08
Showing 3 changed files
... ...
@@ -28,21 +28,23 @@ typedef  volatile int fl_lock_t;
28 28
 /*test and set lock, ret 1 if lock held by someone else, 0 otherwise*/
29 29
 inline static int tsl(fl_lock_t* lock)
30 30
 {
31
-	volatile char val;
31
+	volatile int val;
32 32
 #ifdef __i386
33 33
 	
34 34
 	val=1;
35 35
 	asm volatile( 
36 36
 		" xchg %b0, %1" : "=q" (val), "=m" (*lock) : "0" (val) : "memory"
37 37
 	);
38
-	return val;
39
-#elif defined __sparc64
38
+#elif defined __sparc
40 39
 	asm volatile(
41 40
 			"ldstub [%1], %0 \n\t"
42 41
 			"membar #StoreStore | #StoreLoad \n\t"
43 42
 			: "=r"(val) : "r"(lock):"memory"
44 43
 	);
44
+#else
45
+#error "unknown arhitecture"
45 46
 #endif
47
+	return val;
46 48
 }
47 49
 
48 50
 
... ...
@@ -59,14 +61,13 @@ inline static void get_lock(fl_lock_t* lock)
59 59
 
60 60
 inline static void release_lock(fl_lock_t* lock)
61 61
 {
62
-	char val;
63
-
64 62
 #ifdef __i386
63
+	char val;
65 64
 	val=0;
66 65
 	asm volatile(
67 66
 		" xchg %b0, %1" : "=q" (val), "=m" (*lock) : "0" (val) : "memory"
68 67
 	); /* hmm, maybe lock; movb $0, [%1] would be faster ???*/
69
-#elif defined __sparc64
68
+#elif defined __sparc
70 69
 	asm volatile(
71 70
 			"membar #LoadStore | #StoreStore \n\t" /*is this really needed?*/
72 71
 			"stb %%g0, [%0] \n\t"
... ...
@@ -74,6 +75,8 @@ inline static void release_lock(fl_lock_t* lock)
74 74
 			: "r" (lock)
75 75
 			: "memory"
76 76
 	);
77
+#else
78
+#error "unknown arhitecture"
77 79
 #endif
78 80
 }
79 81
 
... ...
@@ -9,30 +9,44 @@ CC=gcc
9 9
 CFLAGS= -O2 -Wall
10 10
 DEFS=
11 11
 LIBS=
12
+INCLUDE=
13
+
14
+OS = $(shell uname -s)
15
+
16
+
17
+ifeq ($(OS), SunOS)
18
+LIBS+= -lrt
19
+CFLAGS+=-mv8 -Wa,-xarch=v8plus
20
+endif
12 21
 
13 22
 $(NAME): $(NAME).c
14 23
 	gcc $(CFLAGS) $(DEFS) -DNO_LOCK -o $@ $< $(LIBS)
15 24
 
16 25
 
17 26
 $(NAME)_sysv: $(NAME).c
18
-	gcc $(CFLAGS) $(DEFS) -DSYSV_SEM -o $@ $< $(LIBS)
27
+	gcc $(CFLAGS) $(DEFS) -DSYSV_SEM -o $@ $(INCLUDE) $< $(LIBS)
19 28
 
20 29
 
21 30
 $(NAME)_flock: $(NAME).c
22
-	gcc $(CFLAGS) $(DEFS) -DFLOCK -o $@ $< $(LIBS)
31
+	gcc $(CFLAGS) $(DEFS) -DFLOCK -o $@ $(INCLUDE) $< $(LIBS)
23 32
 
24 33
 $(NAME)_posix: $(NAME).c
25
-	gcc $(CFLAGS) $(DEFS) -DPOSIX_SEM -o $@ $< $(LIBS) -lpthread
34
+	gcc $(CFLAGS) $(DEFS) -DPOSIX_SEM -o $@ $(INCLUDE) $< $(LIBS) -lpthread
26 35
 
27 36
 $(NAME)_pmutex: $(NAME).c
28
-	gcc $(CFLAGS) $(DEFS) -DPTHREAD_MUTEX -o $@ $< $(LIBS) -lpthread
37
+	gcc $(CFLAGS) $(DEFS) -DPTHREAD_MUTEX -o $@ $(INCLUDE) $< $(LIBS) -lpthread
29 38
 
30 39
 $(NAME)_fastlock: $(NAME).c
31
-	gcc $(CFLAGS) $(DEFS) -DFAST_LOCK -o $@ $< $(LIBS) 
40
+	gcc $(CFLAGS) $(DEFS) -DFAST_LOCK -o $@ $(INCLUDE) $< $(LIBS) 
32 41
 
33
-all: $(NAME) $(NAME)_sysv $(NAME)_flock $(NAME)_posix $(NAME)_pmutex \
42
+all: $(NAME) $(NAME)_sysv  $(NAME)_posix $(NAME)_pmutex \
34 43
 		$(NAME)_fastlock
35 44
 
45
+ifneq ($(OS), SunOS)
46
+
47
+all: $(NAME)_flock
48
+
49
+endif
36 50
 
37 51
 clean:
38 52
 	-@rm $(NAME) $(NAME)_sysv $(NAME)_flock $(NAME)_posix \
... ...
@@ -7,8 +7,8 @@
7 7
 #include <string.h>
8 8
 #include <ctype.h>
9 9
 #include <unistd.h>
10
-//#include <sys/types.h>
11
-//#include <fcntl.h>
10
+#include <sys/types.h>
11
+#include <fcntl.h>
12 12
 
13 13
 #ifdef FLOCK
14 14
 #include <sys/file.h>