/*
 *  ZThreads, a platform-independant, multithreading and 
 *  synchroniation library
 *
 *  Copyright (C) 2000-2002, Eric Crahen, See LGPL.TXT for details
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 *
 *  SUNY @ Buffalo, hereby disclaims all copyright interest in the
 *  ZThreads library written by Eric Crahen
 */

#ifndef __ZTFASTTHREADLOCAL_H__
#define __ZTFASTTHREADLOCAL_H__

#include "zthread/ZThread.h"
#include "zthread/AbstractThreadLocal.h"

namespace ZThread {

/**
 * @class FastThreadLocal
 *
 * @author Eric Crahen <crahen@cse.buffalo.edu>
 * @date <2002-02-24T09:24:55-0500>
 * @version 2.0.0a
 *
 * This is very similar to the ThreadLocal object in function and purpose.
 * The major difference is that a FastThreadLocal never perfoms any kind
 * of context check to determine when it was first used. Because of this 
 * associated values are not proprogated to child threads, and initialValue()
 * is never called by the framework. 
 */
template <class T>
class ZTHREAD_API FastThreadLocal : private AbstractThreadLocal {
  public:

  /**
   * Create a new FastThreadLocal object
   */
  inline FastThreadLocal() throw() {
  }

  /**
   * Destroy this FastThreadLocal object
   */
  inline virtual ~FastThreadLocal() throw() {
  }

  /**
   * Get the value associated with the current thread and this object via fetch().
   *
   * @return T associated value
   *
   * @exception Synchronization_Exception - thrown if there is an error
   * allocating native thread local storage
   */
  inline T get() const
    throw(Synchronization_Exception) {

    return reinterpret_cast<T>( AbstractThreadLocal::fetch() );

  }
  
 
  /**
   * Set the value associated with the current thread and this object. This value 
   * can only be retrieved from the current thread.
   *
   * @param T new associated value
   * @return T old associated value
   *
   * @exception Synchronization_Exception - thrown if there is an error
   * allocating native thread local storage
   */
  inline T set(T val) const
    throw(Synchronization_Exception) {

    return reinterpret_cast<T>( AbstractThreadLocal::put((void*)val) );

  }

  protected:

  /**
   * Not used for FastThreadLocal.
   */
  inline virtual void* initialValue() const throw() {   
    return (void*)0;
  }


};


};

#endif
