blob: 7690b4bc32b2a2406997aa56de6e63cd5455882f [file] [log] [blame]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook MathML Module V1.1b1//EN"
"http://www.oasis-open.org/docbook/xml/mathml/1.1CR1/dbmathml.dtd" [
<!ENTITY atomicFunctionsInc SYSTEM "atomicFunctionsInc.xml">
]>
<refentry>
<refentryinfo>
<keywordset>
<keyword>atomic_compare_exchange_strong</keyword>
</keywordset>
</refentryinfo>
<refmeta>
<refentrytitle>atomic_compare_exchange_strong</refentrytitle>
<refmiscinfo>
<copyright>
<year>2007-2013</year>
<holder>The Khronos Group Inc.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and/or associated documentation files (the
"Materials"), to deal in the Materials without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Materials, and to
permit persons to whom the Materials are furnished to do so, subject to
the condition that this copyright notice and permission notice shall be included
in all copies or substantial portions of the Materials.</holder>
</copyright>
</refmiscinfo>
<manvolnum>3</manvolnum>
</refmeta>
<!-- ================================ SYNOPSIS -->
<refnamediv id="atomic_compare_exchange">
<refname>atomic_compare_exchange functions</refname>
<refpurpose>
atomic_compare_exchange functions.
</refpurpose>
</refnamediv>
<refsynopsisdiv xmlns:xlink="http://www.w3.org/1999/xlink"><title></title>
<funcsynopsis>
<funcprototype>
<funcdef>
<link xlink:href="scalarDataTypes.html">bool</link>
<function>atomic_compare_exchange_strong</function>
</funcdef>
<paramdef>volatile A <parameter>*object</parameter></paramdef>
<paramdef>C <parameter>*expected</parameter></paramdef>
<paramdef>C <parameter>desired</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<funcsynopsis>
<funcprototype>
<funcdef>
<link xlink:href="scalarDataTypes.html">bool</link>
<function>atomic_compare_exchange_strong_explicit</function>
</funcdef>
<paramdef>volatile A <parameter>*object</parameter></paramdef>
<paramdef>C <parameter>*expected</parameter></paramdef>
<paramdef>C <parameter>desired</parameter></paramdef>
<paramdef><link xlink:href="memory_order.html">memory_order</link><parameter>success</parameter></paramdef>
<paramdef><link xlink:href="memory_order.html">memory_order</link><parameter>failure</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<funcsynopsis>
<funcprototype>
<funcdef>
<link xlink:href="scalarDataTypes.html">bool</link>
<function>atomic_compare_exchange_strong_explicit</function>
</funcdef>
<paramdef>volatile A <parameter>*object</parameter></paramdef>
<paramdef>C <parameter>*expected</parameter></paramdef>
<paramdef>C <parameter>desired</parameter></paramdef>
<paramdef><link xlink:href="memory_order.html">memory_order</link><parameter>success</parameter></paramdef>
<paramdef><link xlink:href="memory_order.html">memory_order</link><parameter>failure</parameter></paramdef>
<paramdef><link xlink:href="memory_scope.html">memory_scope</link><parameter>scope</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<funcsynopsis>
<funcprototype>
<funcdef>
<link xlink:href="scalarDataTypes.html">bool</link>
<function>atomic_compare_exchange_weak</function>
</funcdef>
<paramdef>volatile A <parameter>*object</parameter></paramdef>
<paramdef>C <parameter>*expected</parameter></paramdef>
<paramdef>C <parameter>desired</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<funcsynopsis>
<funcprototype>
<funcdef>
<link xlink:href="scalarDataTypes.html">bool</link>
<function>atomic_compare_exchange_weak_explicit</function>
</funcdef>
<paramdef>volatile A <parameter>*object</parameter></paramdef>
<paramdef>C <parameter>*expected</parameter></paramdef>
<paramdef>C <parameter>desired</parameter></paramdef>
<paramdef><link xlink:href="memory_order.html">memory_order</link><parameter>success</parameter></paramdef>
<paramdef><link xlink:href="memory_order.html">memory_order</link><parameter>failure</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<funcsynopsis>
<funcprototype>
<funcdef>
<link xlink:href="scalarDataTypes.html">bool</link>
<function>atomic_compare_exchange_weak_explicit</function>
</funcdef>
<paramdef>volatile A <parameter>*object</parameter></paramdef>
<paramdef>C <parameter>*expected</parameter></paramdef>
<paramdef>C <parameter>desired</parameter></paramdef>
<paramdef><link xlink:href="memory_order.html">memory_order</link><parameter>success</parameter></paramdef>
<paramdef><link xlink:href="memory_order.html">memory_order</link><parameter>failure</parameter></paramdef>
<paramdef><link xlink:href="memory_scope.html">memory_scope</link><parameter>scope</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<!-- ================================ PARAMETERS -->
<refsect1 id="parameters"><title>Parameters</title>
<variablelist>
<varlistentry>
<term><varname>object</varname></term>
<listitem>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>expected</varname></term>
<listitem>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>desired</varname></term>
<listitem>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>success</varname></term>
<listitem>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>failure</varname></term>
<listitem>
The <varname>failure</varname> argument shall not be
<constant>memory_order_release</constant> nor
<constant>memory_order_acq_rel</constant>.
</listitem>
</varlistentry>
<varlistentry>
<term><varname>scope</varname></term>
<listitem>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<!-- ================================ DESCRIPTION -->
<refsect1 id="description"><title>Description</title>
<para>
These functions can only be used with an object of any atomic integer type.
</para>
<para>
The <varname>failure</varname> argument shall be no
stronger than the <varname>success</varname>
argument. Atomically, compares the value pointed
to by <varname>object</varname> for equality with that in
<varname>expected</varname>, and if true, replaces the value pointed
to by <varname>object</varname> with <varname>desired</varname>, and if false,
updates the value in <varname>expected</varname>
with the value pointed to by <varname>object</varname>. Further, if the
comparison is true, memory is affected according
to the value of <varname>success</varname>, and if the
comparison is false, memory is affected according
to the value of <varname>failure</varname>. These
operations
are atomic read-modify-write operations
(as defined by section 5.1.2.4 of the C11 specification).
</para>
<para>
NOTE: The effect of the compare-and-exchange operations is:
</para>
<para>
<literallayout><code>if (*object == *expected)
*object = desired;
else
*expected = *object;</code></literallayout>
</para>
<para>
The weak compare-and-exchange operations may fail
spuriously. That is, even when the
contents of memory referred to by
<varname>expected</varname> and
<varname>object</varname> are equal,
it may return zero and
store back to <varname>expected</varname>
the same memory contents that were originally there.
This spurious failure enables implementation of
compare-and-exchange on a broader class of
machines, e.g. load-locked store-conditional machines.
</para>
<para>
These generic functions return the result of the comparison.
</para>
&atomicFunctionsInc;
</refsect1>
<!-- ================================ NOTES
<refsect1 id="notes"><title>Notes</title>
</refsect1>-->
<!-- ================================ EXAMPLE -->
<!-- DO NOT DELETE IN CASE AN EXAMPLE IS ADDED IN THE FUTURE -->
<!--
<refsect2 id="example1">
<title>
Example
</title>
<informaltable frame="none">
<tgroup cols="1" align="left" colsep="0" rowsep="0">
<colspec colname="col1" colnum="1" />
<tbody>
<row>
<entry>
Example goes here - it will be set in "code" type with white space preserved.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</refsect2>
-->
<!-- ================================ SPECIFICATION -->
<!-- Set the "uri" attribute in the <olink /> element to the "named destination" for the PDF page
-->
<refsect1 id="specification"><title>Specification</title>
<para>
<imageobject>
<imagedata fileref="pdficon_small1.gif" format="gif" />
</imageobject>
<olink uri="atomic_compare_exchange">OpenCL Specification</olink>
</para>
</refsect1>
<!-- ================================ ALSO SEE -->
<refsect1 id="seealso"><title>Also see</title>
<para>
<citerefentry href="atomicFunctions"><refentrytitle>Atomic Functions</refentrytitle></citerefentry>
</para>
</refsect1>
<!-- ============================== COPYRIGHT -->
<!-- Content included from copyright.inc.xsl -->
<refsect3 id="Copyright"><title></title>
<imageobject>
<imagedata fileref="KhronosLogo.jpg" format="jpg" />
</imageobject>
<para />
</refsect3>
<!-- 16-Dec-2013, rev. 19 -->
</refentry>