summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cas.c8
-rw-r--r--cas.h56
-rw-r--r--container_of.c24
3 files changed, 47 insertions, 41 deletions
diff --git a/cas.c b/cas.c
index 6e9ac3b..f138a5c 100644
--- a/cas.c
+++ b/cas.c
@@ -1,7 +1,7 @@
/*
* File : cas.c
* Author : Jérémy Zurcher <jeremy@asynk.ch>
- * Date : 01/11/09
+ * Date : 2009/11/01
* License :
*
* Permission is hereby granted, free of charge, to any person obtaining
@@ -75,6 +75,12 @@ int main( int argc, char*argv[], char*env[] )
_check((_hi_eq(mem,&v5)),"3 hi value is wrong");
_check((_lo_eq(mem,&v1)),"3 lo value is wrong");
+ _hi(old_val,&v1); _lo(old_val,&v2);
+ _hi(mem,&v4); _lo(mem,&v5);
+ mem = old_val;
+ _check((_hi_eq(mem,&v1)),"4 lo value is wrong");
+ _check((_lo_eq(mem,&v2)),"4 lo value is wrong");
+
printf("success\n");
return EXIT_SUCCESS;
diff --git a/cas.h b/cas.h
index 51312d1..8f88d91 100644
--- a/cas.h
+++ b/cas.h
@@ -1,7 +1,7 @@
/*
* File : cas.h
* Author : Jérémy Zurcher <jeremy@asynk.ch>
- * Date : 25/01/13
+ * Date : 2013/01/25
* License :
*
* Permission is hereby granted, free of charge, to any person obtaining
@@ -50,8 +50,8 @@ extern "C" {
struct _cas_pointer_t
{
- _cas_field_t lo;
- _cas_field_t hi;
+ _cas_field_t lo;
+ _cas_field_t hi;
} __attribute__ (( __aligned__( _cas_aligned ) ));
typedef struct _cas_pointer_t cas_pointer_t;
@@ -63,39 +63,39 @@ typedef struct _cas_pointer_t cas_pointer_t;
inline int cas(volatile cas_pointer_t* mem, cas_pointer_t old_val, cas_pointer_t new_val)
{
- char success;
+ char success;
#if defined(__i386__) && defined(__GNUC__)
- asm volatile("lock cmpxchg8b (%6);"
- "setz %7;"
- : "=a" ( old_val.lo ),
- "=d" ( old_val.hi )
- : "0" ( old_val.lo ),
- "1" ( old_val.hi ),
- "b" ( new_val.lo ),
- "c" ( new_val.hi ),
- "r" ( mem ),
- "m" ( success )
- : "cc", "memory"
- );
+ asm volatile("lock cmpxchg8b (%6);"
+ "setz %7;"
+ : "=a" ( old_val.lo )
+ , "=d" ( old_val.hi )
+ : "0" ( old_val.lo )
+ , "1" ( old_val.hi )
+ , "b" ( new_val.lo )
+ , "c" ( new_val.hi )
+ , "r" ( mem )
+ , "m" ( success )
+ : "cc", "memory"
+ );
#elif defined(__x86_64__) && defined(__GNUC__)
- asm volatile (
- "lock cmpxchg16b %1;"
- "setz %0;"
- : "=q" ( success )
- , "+m" ( *mem )
- , "+d" ( old_val.hi )
- , "+a" ( old_val.lo )
- : "c" ( new_val.hi )
- , "b" ( new_val.lo )
- : "cc", "memory"
- );
+ asm volatile (
+ "lock cmpxchg16b %1;"
+ "setz %0;"
+ : "=q" ( success )
+ , "+m" ( *mem )
+ , "+d" ( old_val.hi )
+ , "+a" ( old_val.lo )
+ : "c" ( new_val.hi )
+ , "b" ( new_val.lo )
+ : "cc", "memory"
+ );
#endif
- return (int)success;
+ return (int)success;
}
# ifdef __cplusplus
diff --git a/container_of.c b/container_of.c
index 13f8e69..53e6ffe 100644
--- a/container_of.c
+++ b/container_of.c
@@ -1,7 +1,7 @@
/*
* File : container_of.c
* Author : Jérémy Zurcher <jeremy@asynk.ch>
- * Date : 01/11/09
+ * Date : 2009/11/01
* License :
*
* Permission is hereby granted, free of charge, to any person obtaining
@@ -48,7 +48,7 @@ static void _check(int cond, const char *msg)
{
if(!cond)
{
- fprintf(stderr,"%s\n",msg);
+ fprintf(stderr,"%s failed\n",msg);
exit(EXIT_FAILURE);
}
}
@@ -57,17 +57,17 @@ int main(int argc, char *argv[])
{
struct node n;
- _check((&n==container_of( &n.data1, struct node, data1)),"1 container_of failed");
- _check((&n==container_of( &n.data2, struct node, data2)),"2 container_of failed");
- _check((&n==container_of( &n.data3, struct node, data3)),"3 container_of failed");
- _check((&n==container_of( &n.data4, struct node, data4)),"4 container_of failed");
- _check((&n==container_of( &n.data5, struct node, data5)),"5 container_of failed");
+ _check((&n==container_of( &n.data1, struct node, data1)),"1 container_of");
+ _check((&n==container_of( &n.data2, struct node, data2)),"2 container_of");
+ _check((&n==container_of( &n.data3, struct node, data3)),"3 container_of");
+ _check((&n==container_of( &n.data4, struct node, data4)),"4 container_of");
+ _check((&n==container_of( &n.data5, struct node, data5)),"5 container_of");
- _check((&n==containerof( &n.data1, struct node, data1)),"1 container_of failed");
- _check((&n==containerof( &n.data2, struct node, data2)),"2 container_of failed");
- _check((&n==containerof( &n.data3, struct node, data3)),"3 container_of failed");
- _check((&n==containerof( &n.data4, struct node, data4)),"4 container_of failed");
- _check((&n==containerof( &n.data5, struct node, data5)),"5 container_of failed");
+ _check((&n==containerof( &n.data1, struct node, data1)),"1 containerof");
+ _check((&n==containerof( &n.data2, struct node, data2)),"2 containerof");
+ _check((&n==containerof( &n.data3, struct node, data3)),"3 containerof");
+ _check((&n==containerof( &n.data4, struct node, data4)),"4 containerof");
+ _check((&n==containerof( &n.data5, struct node, data5)),"5 containerof");
printf("success\n");