diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2009-11-03 21:11:43 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2009-11-03 21:11:43 +0100 |
commit | 9f4d3aea7210d91ce4135bf31a50167fdfec1fda (patch) | |
tree | 1feda0d1d3ae0f8b22a4e5a8117d0b1de711449d /lfq_cas.h | |
parent | 88fed6a7409411c9ab26151bb757de6f95063e72 (diff) | |
download | lock_free-9f4d3aea7210d91ce4135bf31a50167fdfec1fda.zip lock_free-9f4d3aea7210d91ce4135bf31a50167fdfec1fda.tar.gz |
first version of single linked lock free queue
Diffstat (limited to 'lfq_cas.h')
-rw-r--r-- | lfq_cas.h | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/lfq_cas.h b/lfq_cas.h new file mode 100644 index 0000000..a77e1ef --- /dev/null +++ b/lfq_cas.h @@ -0,0 +1,42 @@ +/* + * File : lfq_cas.h + * Author : Jérémy Zurcher <jeremy@asynk.ch> + * Date : 01/11/09 + * License : + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ + +#include "lfq.h" + +/* CMPXCHG8B m64 Compare EDX:EAX with m64. If equal, set ZF and load ECX:EBX into m64. Else, clear ZF and load m64 into EDX:EAX. */ +static inline unsigned int cas( volatile struct split *mem, + volatile struct split old, + volatile struct split new ) { + char result; + __asm__ __volatile__("lock; cmpxchg8b %0; setz %1;" + : "=m"(*mem), "=q"(result) + : "m"(*mem), "d" (old.count), "a" (old.next), + "c" (new.count), "b" (new.next) + : "memory"); + return (int)result; +} + |