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

- Main Page
- Namespaces
- Classes
- Files

# coherence/lang/ThreadLocalReference.hpp

    00001 /*
    00002 * ThreadLocalReference.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_THREAD_LOCAL_REFERENCE_HPP
    00017 #define COH_THREAD_LOCAL_REFERENCE_HPP
    00018
    00019 #include "coherence/lang/compatibility.hpp"
    00020
    00021 #include "coherence/lang/Object.hpp"
    00022 #include "coherence/lang/Reference.hpp"
    00023 #include "coherence/lang/TypedHandle.hpp"
    00024
    00025 COH_OPEN_NAMESPACE2(coherence,lang)
    00026
    00027
    00028 /**
    00029 * ThreadLocalReferences provide a means to store a Handle to an Object in
    00030 * thread local storage. A single native thread-local is used to manage
    00031 * all ThreadLocalReferences, which means that users are free to allocate
    00032 * any number of ThreadLocalReferences.
    00033 *
    00034 * The memory associated with a thread's ThreadLocals is automatically freed
    00035 * when then thread terminates. The memory associated with a non-static
    00036 * ThreadLocalReference will be automatically freed at some point after the
    00037 * ThreadLocalReference has been reclaimed, and is done in such a way that
    00038 * repeated creation and destruction of ThreadLocalReferences will not leak
    00039 * memory.
    00040 */
    00041 class COH_EXPORT ThreadLocalReference
    00042     : public class_spec<ThreadLocalReference,
    00043         extends<Object>,
    00044         implements<Reference> >
    00045     {
    00046     friend class factory<ThreadLocalReference>;
    00047
    00048     // ----- constructors ---------------------------------------------------
    00049
    00050     protected:
    00051         /**
    00052         * Create a new ThreadLocalReference.
    00053         *
    00054         * @return a handle to the new ThreadLocalReference
    00055         */
    00056         ThreadLocalReference();
    00057
    00058
    00059     // ----- Object interface -----------------------------------------------
    00060
    00061     public:
    00062         /**
    00063         * {@inheritDoc}
    00064         */
    00065         virtual void toStream(std::ostream& out) const;
    00066
    00067
    00068     // ----- Reference<Object> interface ------------------------------------
    00069
    00070     public:
    00071         /**
    00072         * Specify the Object to be referenced by the calling thread.
    00073         *
    00074         * @param ohObject  the referenced object
    00075         */
    00076         virtual void set(Object::Holder hObject);
    00077
    00078         /**
    00079         * Return a Holder to the calling threads referenced Object, or
    00080         * NULL if none has been set for the thread.
    00081         *
    00082         * @return a Holder to the referenced Object
    00083         */
    00084         virtual Object::Holder get() const;
    00085
    00086         /**
    00087         * Return a Holder to the calling threads referenced Object, or
    00088         * NULL if none has been set for the thread.
    00089         *
    00090         * @return a Holder to the referenced Object
    00091         */
    00092         virtual Object::Holder get();
    00093     };
    00094
    00095 COH_CLOSE_NAMESPACE2
    00096
    00097 #endif // COH_THREAD_LOCAL_REFERENCE_HPP

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