OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [tags/] [gnu-src/] [gcc-4.5.1/] [gcc-4.5.1-or32-1.0rc4/] [libstdc++-v3/] [include/] [std/] [thread] - Diff between revs 424 and 519

Only display areas with differences | Details | Blame | View Log

Rev 424 Rev 519
//  -*- C++ -*-
//  -*- C++ -*-
// Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
// Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
//
//
// This file is part of the GNU ISO C++ Library.  This library is free
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// any later version.
// This library is distributed in the hope that it will be useful,
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// GNU General Public License for more details.
// Under Section 7 of GPL version 3, you are granted additional
// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.
// 3.1, as published by the Free Software Foundation.
// You should have received a copy of the GNU General Public License and
// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
// .
// .
/** @file thread
/** @file thread
 *  This is a Standard C++ Library header.
 *  This is a Standard C++ Library header.
 */
 */
#ifndef _GLIBCXX_THREAD
#ifndef _GLIBCXX_THREAD
#define _GLIBCXX_THREAD 1
#define _GLIBCXX_THREAD 1
#pragma GCC system_header
#pragma GCC system_header
#ifndef __GXX_EXPERIMENTAL_CXX0X__
#ifndef __GXX_EXPERIMENTAL_CXX0X__
# include 
# include 
#else
#else
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1)
#if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1)
namespace std
namespace std
{
{
  /**
  /**
   * @defgroup threads Threads
   * @defgroup threads Threads
   * @ingroup concurrency
   * @ingroup concurrency
   *
   *
   * Classes for thread support.
   * Classes for thread support.
   * @{
   * @{
   */
   */
  template
  template
    struct hash;
    struct hash;
  /// thread
  /// thread
  class thread
  class thread
  {
  {
  public:
  public:
    typedef __gthread_t                 native_handle_type;
    typedef __gthread_t                 native_handle_type;
    struct _Impl_base;
    struct _Impl_base;
    typedef shared_ptr<_Impl_base>  __shared_base_type;
    typedef shared_ptr<_Impl_base>  __shared_base_type;
    /// thread::id
    /// thread::id
    class id
    class id
    {
    {
      native_handle_type        _M_thread;
      native_handle_type        _M_thread;
    public:
    public:
      id() : _M_thread() { }
      id() : _M_thread() { }
      explicit
      explicit
      id(native_handle_type __id) : _M_thread(__id) { }
      id(native_handle_type __id) : _M_thread(__id) { }
    private:
    private:
      friend class thread;
      friend class thread;
      friend class hash;
      friend class hash;
      friend bool
      friend bool
      operator==(thread::id __x, thread::id __y)
      operator==(thread::id __x, thread::id __y)
      { return __gthread_equal(__x._M_thread, __y._M_thread); }
      { return __gthread_equal(__x._M_thread, __y._M_thread); }
      friend bool
      friend bool
      operator<(thread::id __x, thread::id __y)
      operator<(thread::id __x, thread::id __y)
      { return __x._M_thread < __y._M_thread; }
      { return __x._M_thread < __y._M_thread; }
      template
      template
        friend basic_ostream<_CharT, _Traits>&
        friend basic_ostream<_CharT, _Traits>&
        operator<<(basic_ostream<_CharT, _Traits>& __out, thread::id __id);
        operator<<(basic_ostream<_CharT, _Traits>& __out, thread::id __id);
    };
    };
    // Simple base type that the templatized, derived class containing
    // Simple base type that the templatized, derived class containing
    // an arbitrary functor can be converted to and called.
    // an arbitrary functor can be converted to and called.
    struct _Impl_base
    struct _Impl_base
    {
    {
      __shared_base_type        _M_this_ptr;
      __shared_base_type        _M_this_ptr;
      inline virtual ~_Impl_base();
      inline virtual ~_Impl_base();
      virtual void _M_run() = 0;
      virtual void _M_run() = 0;
    };
    };
    template
    template
      struct _Impl : public _Impl_base
      struct _Impl : public _Impl_base
      {
      {
        _Callable               _M_func;
        _Callable               _M_func;
        _Impl(_Callable&& __f) : _M_func(std::forward<_Callable>(__f))
        _Impl(_Callable&& __f) : _M_func(std::forward<_Callable>(__f))
        { }
        { }
        void
        void
        _M_run() { _M_func(); }
        _M_run() { _M_func(); }
      };
      };
  private:
  private:
    id                          _M_id;
    id                          _M_id;
  public:
  public:
    thread() = default;
    thread() = default;
    thread(const thread&) = delete;
    thread(const thread&) = delete;
    thread(thread&& __t)
    thread(thread&& __t)
    { swap(__t); }
    { swap(__t); }
    template
    template
      explicit thread(_Callable __f)
      explicit thread(_Callable __f)
      {
      {
        _M_start_thread(_M_make_routine<_Callable>
        _M_start_thread(_M_make_routine<_Callable>
                        (std::forward<_Callable>(__f)));
                        (std::forward<_Callable>(__f)));
      }
      }
    template
    template
      thread(_Callable&& __f, _Args&&... __args)
      thread(_Callable&& __f, _Args&&... __args)
      { _M_start_thread(_M_make_routine(std::bind(__f, __args...))); }
      { _M_start_thread(_M_make_routine(std::bind(__f, __args...))); }
    ~thread()
    ~thread()
    {
    {
      if (joinable())
      if (joinable())
        std::terminate();
        std::terminate();
    }
    }
    thread& operator=(const thread&) = delete;
    thread& operator=(const thread&) = delete;
    thread& operator=(thread&& __t)
    thread& operator=(thread&& __t)
    {
    {
      if (joinable())
      if (joinable())
        std::terminate();
        std::terminate();
      swap(__t);
      swap(__t);
      return *this;
      return *this;
    }
    }
    void
    void
    swap(thread& __t)
    swap(thread& __t)
    { std::swap(_M_id, __t._M_id); }
    { std::swap(_M_id, __t._M_id); }
    bool
    bool
    joinable() const
    joinable() const
    { return !(_M_id == id()); }
    { return !(_M_id == id()); }
    void
    void
    join();
    join();
    void
    void
    detach();
    detach();
    thread::id
    thread::id
    get_id() const
    get_id() const
    { return _M_id; }
    { return _M_id; }
    /** @pre thread is joinable
    /** @pre thread is joinable
     */
     */
    native_handle_type
    native_handle_type
    native_handle()
    native_handle()
    { return _M_id._M_thread; }
    { return _M_id._M_thread; }
    // Returns a value that hints at the number of hardware thread contexts.
    // Returns a value that hints at the number of hardware thread contexts.
    static unsigned int
    static unsigned int
    hardware_concurrency()
    hardware_concurrency()
    { return 0; }
    { return 0; }
  private:
  private:
    void
    void
    _M_start_thread(__shared_base_type);
    _M_start_thread(__shared_base_type);
    template
    template
      shared_ptr<_Impl<_Callable>>
      shared_ptr<_Impl<_Callable>>
      _M_make_routine(_Callable&& __f)
      _M_make_routine(_Callable&& __f)
      {
      {
        // Create and allocate full data structure, not base.
        // Create and allocate full data structure, not base.
        return make_shared<_Impl<_Callable>>(std::forward<_Callable>(__f));
        return make_shared<_Impl<_Callable>>(std::forward<_Callable>(__f));
      }
      }
  };
  };
  inline thread::_Impl_base::~_Impl_base() = default;
  inline thread::_Impl_base::~_Impl_base() = default;
  inline void
  inline void
  swap(thread& __x, thread& __y)
  swap(thread& __x, thread& __y)
  { __x.swap(__y); }
  { __x.swap(__y); }
  inline bool
  inline bool
  operator!=(thread::id __x, thread::id __y)
  operator!=(thread::id __x, thread::id __y)
  { return !(__x == __y); }
  { return !(__x == __y); }
  inline bool
  inline bool
  operator<=(thread::id __x, thread::id __y)
  operator<=(thread::id __x, thread::id __y)
  { return !(__y < __x); }
  { return !(__y < __x); }
  inline bool
  inline bool
  operator>(thread::id __x, thread::id __y)
  operator>(thread::id __x, thread::id __y)
  { return __y < __x; }
  { return __y < __x; }
  inline bool
  inline bool
  operator>=(thread::id __x, thread::id __y)
  operator>=(thread::id __x, thread::id __y)
  { return !(__x < __y); }
  { return !(__x < __y); }
  // DR 889.
  // DR 889.
  /// std::hash specialization for thread::id.
  /// std::hash specialization for thread::id.
  template<>
  template<>
    struct hash
    struct hash
    : public std::unary_function
    : public std::unary_function
    {
    {
      size_t
      size_t
      operator()(const thread::id& __id) const
      operator()(const thread::id& __id) const
      { return std::_Fnv_hash::hash(__id._M_thread); }
      { return std::_Fnv_hash::hash(__id._M_thread); }
    };
    };
  template
  template
    inline basic_ostream<_CharT, _Traits>&
    inline basic_ostream<_CharT, _Traits>&
    operator<<(basic_ostream<_CharT, _Traits>& __out, thread::id __id)
    operator<<(basic_ostream<_CharT, _Traits>& __out, thread::id __id)
    {
    {
      if (__id == thread::id())
      if (__id == thread::id())
        return __out << "thread::id of a non-executing thread";
        return __out << "thread::id of a non-executing thread";
      else
      else
        return __out << __id._M_thread;
        return __out << __id._M_thread;
    }
    }
  /** @namespace std::this_thread
  /** @namespace std::this_thread
   *  @brief ISO C++ 0x entities sub namespace for thread.
   *  @brief ISO C++ 0x entities sub namespace for thread.
   *  30.2.2 Namespace this_thread.
   *  30.2.2 Namespace this_thread.
   */
   */
  namespace this_thread
  namespace this_thread
  {
  {
    /// get_id
    /// get_id
    inline thread::id
    inline thread::id
    get_id() { return thread::id(__gthread_self()); }
    get_id() { return thread::id(__gthread_self()); }
#ifdef _GLIBCXX_USE_SCHED_YIELD
#ifdef _GLIBCXX_USE_SCHED_YIELD
    /// yield
    /// yield
    inline void
    inline void
    yield()
    yield()
    { __gthread_yield(); }
    { __gthread_yield(); }
#endif
#endif
#ifdef _GLIBCXX_USE_NANOSLEEP
#ifdef _GLIBCXX_USE_NANOSLEEP
    /// sleep_until
    /// sleep_until
    template
    template
      inline void
      inline void
      sleep_until(const chrono::time_point<_Clock, _Duration>& __atime)
      sleep_until(const chrono::time_point<_Clock, _Duration>& __atime)
      { sleep_for(__atime - _Clock::now()); }
      { sleep_for(__atime - _Clock::now()); }
    /// sleep_for
    /// sleep_for
    template
    template
      inline void
      inline void
      sleep_for(const chrono::duration<_Rep, _Period>& __rtime)
      sleep_for(const chrono::duration<_Rep, _Period>& __rtime)
      {
      {
        chrono::seconds __s =
        chrono::seconds __s =
          chrono::duration_cast(__rtime);
          chrono::duration_cast(__rtime);
        chrono::nanoseconds __ns =
        chrono::nanoseconds __ns =
          chrono::duration_cast(__rtime - __s);
          chrono::duration_cast(__rtime - __s);
        __gthread_time_t __ts =
        __gthread_time_t __ts =
          {
          {
            static_cast(__s.count()),
            static_cast(__s.count()),
            static_cast(__ns.count())
            static_cast(__ns.count())
          };
          };
        ::nanosleep(&__ts, 0);
        ::nanosleep(&__ts, 0);
      }
      }
#endif
#endif
  }
  }
  // @} group threads
  // @} group threads
}
}
#endif // _GLIBCXX_HAS_GTHREADS && _GLIBCXX_USE_C99_STDINT_TR1
#endif // _GLIBCXX_HAS_GTHREADS && _GLIBCXX_USE_C99_STDINT_TR1
#endif // __GXX_EXPERIMENTAL_CXX0X__
#endif // __GXX_EXPERIMENTAL_CXX0X__
#endif // _GLIBCXX_THREAD
#endif // _GLIBCXX_THREAD
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.