Oracle Coherence for C++ API
Release 3.6.1.0
E18813-01

- Main Page
- Namespaces
- Classes
- Files

# coherence/lang/Volatile.hpp

    00001 /*
    00002 * Volatile.hpp
    00003 *
    00004 * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
    00005 *
    00006 * Oracle is a registered trademarks of Oracle Corporation and/or its
    00007 * affiliates.
    00008 *
    00009 * This software is the confidential and proprietary information of Oracle
    00010 * Corporation. You shall not disclose such confidential and proprietary
    00011 * information and shall use it only in accordance with the terms of the
    00012 * license agreement you entered into with Oracle.
    00013 *
    00014 * This notice may not be removed or altered.
    00015 */
    00016 #ifndef COH_VOLATILE_HPP
    00017 #define COH_VOLATILE_HPP
    00018
    00019 #include "coherence/lang/compatibility.hpp"
    00020
    00021 #include "coherence/lang/Object.hpp"
    00022 #include "coherence/native/NativeAtomic64.hpp"
    00023
    00024 #include <ostream>
    00025
    00026 COH_OPEN_NAMESPACE2(coherence,lang)
    00027
    00028
    00029 /**
    00030 * Template class wraps primitive data types with memory barriers, providing
    00031 * JSR-133 style volatiles.
    00032 *
    00033 * Note: In the rare case that a Volatile is declared via the mutable
    00034 *       keyword, the Volatile must be informed of this fact by setting
    00035 *       fMutable to true during construction.
    00036 *
    00037 * @author mf  2008.02.07
    00038 */
    00039 template<class T>
    00040 class COH_EXPORT Volatile
    00041     {
    00042     // ----- typedefs -------------------------------------------------------
    00043
    00044     public:
    00045         /**
    00046         * A primitive data type that is wrapped by this Volatile<T>
    00047         */
    00048         typedef T Type;
    00049
    00050
    00051     // ----- constructors ---------------------------------------------------
    00052
    00053     public:
    00054         /**
    00055         * Construct a new Volatile<T> with the default wrapped T value.
    00056         *
    00057         * @param oGuardian  the object which this data member is part of
    00058         */
    00059         Volatile(Object& oGuardian);
    00060
    00061         /**
    00062         * Copy-construct a Volatile<T>.
    00063         *
    00064         * @param oGuardian  the object which this data member is part of
    00065         */
    00066         Volatile(Object& oGuardian, const Volatile& o);
    00067
    00068         /**
    00069         * Copy-construct a Volatile<T>.
    00070         *
    00071         * @param oGuardian  the object which this data member is part of
    00072         * @param fMutable   true if the member is declared as mutable, false
    00073         *                   if declared as const
    00074         */
    00075         Volatile(Object& oGuardian, const Volatile& o, bool fMutable);
    00076
    00077         /**
    00078         * Construct a new Volatile<T> with the specified wrapped T value.
    00079         *
    00080         * @param oGuardian  the object which this data member is part of
    00081         */
    00082         Volatile(Object& oGuardian, const T& value);
    00083
    00084         /**
    00085         * Construct a new Volatile<T> with the specified wrapped T value.
    00086         *
    00087         * @param oGuardian  the object which this data member is part of
    00088         * @param fMutable   true if the member is declared as mutable, false
    00089         *                   if declared as const
    00090         */
    00091         Volatile(Object& oGuardian, const T& value, bool fMutable);
    00092
    00093         /**
    00094         * Destruct this Volatile<T> object.
    00095         */
    00096         ~Volatile();
    00097
    00098
    00099     // ----- operators ------------------------------------------------------
    00100
    00101     public:
    00102         /**
    00103         * Assign this Volatile the value from another Volatile
    00104         */
    00105         Volatile& operator=(const Volatile& value);
    00106
    00107         /**
    00108         * Assign this Volatile a new value.
    00109         */
    00110         Volatile& operator=(const T& value);
    00111
    00112
    00113     // ----- Volatile interface --------------------------------------------
    00114
    00115     public:
    00116         /**
    00117         * Return the Volatile value
    00118         *
    00119         * @return The Volatile value
    00120         */
    00121         operator const T() const;
    00122
    00123
    00124     // ----- data members ---------------------------------------------------
    00125
    00126     private:
    00127         /**
    00128         * The object which this data member is part of.
    00129         */
    00130         const Object& m_oGuardian;
    00131
    00132         /**
    00133         * The volatile value wrapped in a NativeAtomic64.
    00134         */
    00135         coherence::native::NativeAtomic64 m_atomic;
    00136     };
    00137
    00138 COH_CLOSE_NAMESPACE2
    00139
    00140
    00141 // ----- global operators and functions -------------------------------------
    00142
    00143 /**
    00144 * Output a human-readable description of the given Volatile<T> to the
    00145 * specified stream.
    00146 *
    00147 * @param out  the stream used to output the description
    00148 * @param o    the Volatile<T> value to describe
    00149 *
    00150 * @return the supplied stream
    00151 */
    00152 template<class T> std::ostream& operator<<(std::ostream& out,
    00153             const coherence::lang::Volatile<T>& o);
    00154
    00155 #endif // COH_Volatile_HPP

Copyright © 2000, 2010, Oracle and/or its affiliates. All rights reserved.