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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-stable/] [gcc-4.5.1/] [libstdc++-v3/] [src/] [mutex.cc] - Blame information for rev 424

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 424 jeremybenn
// mutex -*- C++ -*-
2
 
3
// Copyright (C) 2008, 2009 Free Software Foundation, Inc.
4
//
5
// This file is part of the GNU ISO C++ Library.  This library is free
6
// software; you can redistribute it and/or modify it under the
7
// terms of the GNU General Public License as published by the
8
// Free Software Foundation; either version 3, or (at your option)
9
// any later version.
10
 
11
// This library is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
// GNU General Public License for more details.
15
 
16
// Under Section 7 of GPL version 3, you are granted additional
17
// permissions described in the GCC Runtime Library Exception, version
18
// 3.1, as published by the Free Software Foundation.
19
 
20
// You should have received a copy of the GNU General Public License and
21
// a copy of the GCC Runtime Library Exception along with this program;
22
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
23
// <http://www.gnu.org/licenses/>.
24
 
25
#include <mutex>
26
 
27
#if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1)
28
#ifndef _GLIBCXX_HAVE_TLS
29
namespace
30
{
31
  inline std::unique_lock<std::mutex>*&
32
  __get_once_functor_lock_ptr()
33
  {
34
    static std::unique_lock<std::mutex>* __once_functor_lock_ptr = 0;
35
    return __once_functor_lock_ptr;
36
  }
37
}
38
#endif
39
 
40
namespace std
41
{
42
  const defer_lock_t defer_lock = defer_lock_t();
43
  const try_to_lock_t try_to_lock = try_to_lock_t();
44
  const adopt_lock_t adopt_lock = adopt_lock_t();
45
 
46
#ifdef _GLIBCXX_HAVE_TLS
47
  __thread void* __once_callable;
48
  __thread void (*__once_call)();
49
#else
50
  // Explicit instantiation due to -fno-implicit-instantiation.
51
  template class function<void()>;
52
  function<void()> __once_functor;
53
 
54
  mutex&
55
  __get_once_mutex()
56
  {
57
    static mutex once_mutex;
58
    return once_mutex;
59
  }
60
 
61
  // code linked against ABI 3.4.12 and later uses this
62
  void
63
  __set_once_functor_lock_ptr(unique_lock<mutex>* __ptr)
64
  {
65
    __get_once_functor_lock_ptr() = __ptr;
66
  }
67
 
68
  // unsafe - retained for compatibility with ABI 3.4.11
69
  unique_lock<mutex>&
70
  __get_once_functor_lock()
71
  {
72
    static unique_lock<mutex> once_functor_lock(__get_once_mutex(), defer_lock);
73
    return once_functor_lock;
74
  }
75
#endif
76
 
77
  extern "C"
78
  {
79
    void __once_proxy()
80
    {
81
#ifndef _GLIBCXX_HAVE_TLS
82
      function<void()> __once_call = std::move(__once_functor);
83
      if (unique_lock<mutex>* __lock = __get_once_functor_lock_ptr())
84
      {
85
        // caller is using new ABI and provided lock ptr
86
        __get_once_functor_lock_ptr() = 0;
87
        __lock->unlock();
88
      }
89
      else
90
        __get_once_functor_lock().unlock();  // global lock
91
#endif
92
      __once_call();
93
    }
94
  }
95
}
96
 
97
#endif // _GLIBCXX_HAS_GTHREADS && _GLIBCXX_USE_C99_STDINT_TR1

powered by: WebSVN 2.1.0

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