head	1.4;
access;
symbols
	RELENG_9_1_0_RELEASE:1.1.2.2
	RELENG_9_1:1.1.2.2.0.2
	RELENG_9_1_BP:1.1.2.2
	RELENG_9:1.1.0.2;
locks; strict;
comment	@# @;


1.4
date	2013.04.28.00.41.54;	author svnexp;	state Exp;
branches;
next	1.3;

1.3
date	2012.11.17.03.36.33;	author svnexp;	state Exp;
branches;
next	1.2;

1.2
date	2012.10.22.18.25.04;	author dim;	state Exp;
branches;
next	1.1;

1.1
date	2011.11.25.20.59.04;	author theraven;	state Exp;
branches
	1.1.2.1;
next	;

1.1.2.1
date	2012.05.22.18.30.14;	author theraven;	state dead;
branches;
next	1.1.2.2;

1.1.2.2
date	2012.05.22.18.30.14;	author theraven;	state Exp;
branches;
next	1.1.2.3;

1.1.2.3
date	2012.11.21.18.41.40;	author svnexp;	state Exp;
branches;
next	1.1.2.4;

1.1.2.4
date	2012.11.29.21.29.14;	author svnexp;	state Exp;
branches;
next	1.1.2.5;

1.1.2.5
date	2013.05.11.17.01.44;	author svnexp;	state Exp;
branches;
next	;


desc
@@


1.4
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/249998
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@// -*- C++ -*-
//===---------------------- condition_variable ----------------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#ifndef _LIBCPP_CONDITION_VARIABLE
#define _LIBCPP_CONDITION_VARIABLE

/*
    condition_variable synopsis

namespace std
{

enum class cv_status { no_timeout, timeout };

class condition_variable
{
public:
    condition_variable();
    ~condition_variable();

    condition_variable(const condition_variable&) = delete;
    condition_variable& operator=(const condition_variable&) = delete;

    void notify_one() noexcept;
    void notify_all() noexcept;

    void wait(unique_lock<mutex>& lock);
    template <class Predicate>
        void wait(unique_lock<mutex>& lock, Predicate pred);

    template <class Clock, class Duration>
        cv_status
        wait_until(unique_lock<mutex>& lock,
                   const chrono::time_point<Clock, Duration>& abs_time);

    template <class Clock, class Duration, class Predicate>
        bool
        wait_until(unique_lock<mutex>& lock,
                   const chrono::time_point<Clock, Duration>& abs_time,
                   Predicate pred);

    template <class Rep, class Period>
        cv_status
        wait_for(unique_lock<mutex>& lock,
                 const chrono::duration<Rep, Period>& rel_time);

    template <class Rep, class Period, class Predicate>
        bool
        wait_for(unique_lock<mutex>& lock,
                 const chrono::duration<Rep, Period>& rel_time,
                 Predicate pred);

    typedef pthread_cond_t* native_handle_type;
    native_handle_type native_handle();
};

void notify_all_at_thread_exit(condition_variable& cond, unique_lock<mutex> lk);

class condition_variable_any
{
public:
    condition_variable_any();
    ~condition_variable_any();

    condition_variable_any(const condition_variable_any&) = delete;
    condition_variable_any& operator=(const condition_variable_any&) = delete;

    void notify_one() noexcept;
    void notify_all() noexcept;

    template <class Lock>
        void wait(Lock& lock);
    template <class Lock, class Predicate>
        void wait(Lock& lock, Predicate pred);

    template <class Lock, class Clock, class Duration>
        cv_status
        wait_until(Lock& lock,
                   const chrono::time_point<Clock, Duration>& abs_time);

    template <class Lock, class Clock, class Duration, class Predicate>
        bool
        wait_until(Lock& lock,
                   const chrono::time_point<Clock, Duration>& abs_time,
                   Predicate pred);

    template <class Lock, class Rep, class Period>
        cv_status
        wait_for(Lock& lock,
                 const chrono::duration<Rep, Period>& rel_time);

    template <class Lock, class Rep, class Period, class Predicate>
        bool
        wait_for(Lock& lock,
                 const chrono::duration<Rep, Period>& rel_time,
                 Predicate pred);
};

}  // std

*/

#include <__config>
#include <__mutex_base>
#include <memory>

#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif

_LIBCPP_BEGIN_NAMESPACE_STD

class _LIBCPP_TYPE_VIS condition_variable_any
{
    condition_variable __cv_;
    shared_ptr<mutex>  __mut_;
public:
    condition_variable_any();

    void notify_one() _NOEXCEPT;
    void notify_all() _NOEXCEPT;

    template <class _Lock>
        void wait(_Lock& __lock);
    template <class _Lock, class _Predicate>
        void wait(_Lock& __lock, _Predicate __pred);

    template <class _Lock, class _Clock, class _Duration>
        cv_status
        wait_until(_Lock& __lock,
                   const chrono::time_point<_Clock, _Duration>& __t);

    template <class _Lock, class _Clock, class _Duration, class _Predicate>
        bool
        wait_until(_Lock& __lock,
                   const chrono::time_point<_Clock, _Duration>& __t,
                   _Predicate __pred);

    template <class _Lock, class _Rep, class _Period>
        cv_status
        wait_for(_Lock& __lock,
                 const chrono::duration<_Rep, _Period>& __d);

    template <class _Lock, class _Rep, class _Period, class _Predicate>
        bool
        wait_for(_Lock& __lock,
                 const chrono::duration<_Rep, _Period>& __d,
                 _Predicate __pred);
};

inline _LIBCPP_INLINE_VISIBILITY
condition_variable_any::condition_variable_any()
    : __mut_(make_shared<mutex>()) {}

inline _LIBCPP_INLINE_VISIBILITY
void
condition_variable_any::notify_one() _NOEXCEPT
{
    {lock_guard<mutex> __lx(*__mut_);}
    __cv_.notify_one();
}

inline _LIBCPP_INLINE_VISIBILITY
void
condition_variable_any::notify_all() _NOEXCEPT
{
    {lock_guard<mutex> __lx(*__mut_);}
    __cv_.notify_all();
}

struct __lock_external
{
    template <class _Lock>
    void operator()(_Lock* __m) {__m->lock();}
};

template <class _Lock>
void
condition_variable_any::wait(_Lock& __lock)
{
    shared_ptr<mutex> __mut = __mut_;
    unique_lock<mutex> __lk(*__mut);
    __lock.unlock();
    unique_ptr<_Lock, __lock_external> __lxx(&__lock);
    lock_guard<unique_lock<mutex> > __lx(__lk, adopt_lock);
    __cv_.wait(__lk);
}  // __mut_.unlock(), __lock.lock()

template <class _Lock, class _Predicate>
inline _LIBCPP_INLINE_VISIBILITY
void
condition_variable_any::wait(_Lock& __lock, _Predicate __pred)
{
    while (!__pred())
        wait(__lock);
}

template <class _Lock, class _Clock, class _Duration>
cv_status
condition_variable_any::wait_until(_Lock& __lock,
                                   const chrono::time_point<_Clock, _Duration>& __t)
{
    shared_ptr<mutex> __mut = __mut_;
    unique_lock<mutex> __lk(*__mut);
    __lock.unlock();
    unique_ptr<_Lock, __lock_external> __lxx(&__lock);
    lock_guard<unique_lock<mutex> > __lx(__lk, adopt_lock);
    return __cv_.wait_until(__lk, __t);
}  // __mut_.unlock(), __lock.lock()

template <class _Lock, class _Clock, class _Duration, class _Predicate>
inline _LIBCPP_INLINE_VISIBILITY
bool
condition_variable_any::wait_until(_Lock& __lock,
                                   const chrono::time_point<_Clock, _Duration>& __t,
                                   _Predicate __pred)
{
    while (!__pred())
        if (wait_until(__lock, __t) == cv_status::timeout)
            return __pred();
    return true;
}

template <class _Lock, class _Rep, class _Period>
inline _LIBCPP_INLINE_VISIBILITY
cv_status
condition_variable_any::wait_for(_Lock& __lock,
                                 const chrono::duration<_Rep, _Period>& __d)
{
    return wait_until(__lock, chrono::steady_clock::now() + __d);
}

template <class _Lock, class _Rep, class _Period, class _Predicate>
inline _LIBCPP_INLINE_VISIBILITY
bool
condition_variable_any::wait_for(_Lock& __lock,
                                 const chrono::duration<_Rep, _Period>& __d,
                                 _Predicate __pred)
{
    return wait_until(__lock, chrono::steady_clock::now() + __d,
                      _VSTD::move(__pred));
}

_LIBCPP_FUNC_VIS
void notify_all_at_thread_exit(condition_variable& cond, unique_lock<mutex> lk);

_LIBCPP_END_NAMESPACE_STD

#endif  // _LIBCPP_CONDITION_VARIABLE
@


1.3
log
@## SVN ##
## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/242945
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
## SVN ##
## SVN ## ------------------------------------------------------------------------
## SVN ## r242945 | theraven | 2012-11-13 03:27:43 +0000 (Tue, 13 Nov 2012) | 2 lines
## SVN ##
## SVN ## Import new version of libc++ into base.
## SVN ##
## SVN ## ------------------------------------------------------------------------
## SVN ##
@
text
@d120 1
a120 1
class _LIBCPP_VISIBLE condition_variable_any
d251 1
a251 1
_LIBCPP_VISIBLE
@


1.2
log
@SVN rev 241903 on 2012-10-22 18:25:04Z by dim

Import libc++ trunk r165949.  Among other improvements and bug fixes,
this has many visibility problems fixed, which should help with
compiling certain ports that exercise C++11 mode (i.e. Firefox).

Also, belatedly add the LICENSE.TXT and accompanying CREDITS.TXT files,
which are referred to in all the source files.

MFC after:	1 month
@
text
@d166 1
a166 1
    {lock_guard<mutex> _(*__mut_);}
d174 1
a174 1
    {lock_guard<mutex> _(*__mut_);}
d191 2
a192 2
    unique_ptr<_Lock, __lock_external> __(&__lock);
    lock_guard<unique_lock<mutex> > _(__lk, adopt_lock);
d213 2
a214 2
    unique_ptr<_Lock, __lock_external> __(&__lock);
    lock_guard<unique_lock<mutex> > _(__lk, adopt_lock);
@


1.1
log
@SVN rev 227983 on 2011-11-25 20:59:04Z by theraven

Import libc++ / libcxxrt into base.  Not build by default yet (use
MK_LIBCPLUSPLUS=yes to enable).  This is a work-in-progress.  It works for
me, but is not guaranteed to work for anyone else and may eat your dog.

To build C++ using libc++, add -stdlib=libc++ to your CXX and LD flags.

Bug reports welcome, bug fixes even more welcome...

Approved by:	dim (mentor)
@
text
@d31 2
a32 2
    void notify_one();
    void notify_all();
d75 2
a76 2
    void notify_one();
    void notify_all();
d127 2
a128 2
    void notify_one();
    void notify_all();
d164 1
a164 1
condition_variable_any::notify_one()
d172 1
a172 1
condition_variable_any::notify_all()
@


1.1.2.1
log
@file condition_variable was added on branch RELENG_9 on 2012-05-22 18:32:26 +0000
@
text
@d1 256
@


1.1.2.2
log
@SVN rev 235798 on 2012-05-22 18:30:14Z by theraven

Merged libcxxrt and libc++.  Now available for testing on 9-stable with
-stdlib=libc++.  Changes to libstdc++ not yet merged, so it is not yet possible
to mix libstdc++ and libc++ in the same program.

Merged revisions: 226702,226785,227006,227755,227983,227987,228531,228630,228761,229067,230127,232950,233098,234715-234716,234772
@
text
@a0 256
// -*- C++ -*-
//===---------------------- condition_variable ----------------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#ifndef _LIBCPP_CONDITION_VARIABLE
#define _LIBCPP_CONDITION_VARIABLE

/*
    condition_variable synopsis

namespace std
{

enum class cv_status { no_timeout, timeout };

class condition_variable
{
public:
    condition_variable();
    ~condition_variable();

    condition_variable(const condition_variable&) = delete;
    condition_variable& operator=(const condition_variable&) = delete;

    void notify_one();
    void notify_all();

    void wait(unique_lock<mutex>& lock);
    template <class Predicate>
        void wait(unique_lock<mutex>& lock, Predicate pred);

    template <class Clock, class Duration>
        cv_status
        wait_until(unique_lock<mutex>& lock,
                   const chrono::time_point<Clock, Duration>& abs_time);

    template <class Clock, class Duration, class Predicate>
        bool
        wait_until(unique_lock<mutex>& lock,
                   const chrono::time_point<Clock, Duration>& abs_time,
                   Predicate pred);

    template <class Rep, class Period>
        cv_status
        wait_for(unique_lock<mutex>& lock,
                 const chrono::duration<Rep, Period>& rel_time);

    template <class Rep, class Period, class Predicate>
        bool
        wait_for(unique_lock<mutex>& lock,
                 const chrono::duration<Rep, Period>& rel_time,
                 Predicate pred);

    typedef pthread_cond_t* native_handle_type;
    native_handle_type native_handle();
};

void notify_all_at_thread_exit(condition_variable& cond, unique_lock<mutex> lk);

class condition_variable_any
{
public:
    condition_variable_any();
    ~condition_variable_any();

    condition_variable_any(const condition_variable_any&) = delete;
    condition_variable_any& operator=(const condition_variable_any&) = delete;

    void notify_one();
    void notify_all();

    template <class Lock>
        void wait(Lock& lock);
    template <class Lock, class Predicate>
        void wait(Lock& lock, Predicate pred);

    template <class Lock, class Clock, class Duration>
        cv_status
        wait_until(Lock& lock,
                   const chrono::time_point<Clock, Duration>& abs_time);

    template <class Lock, class Clock, class Duration, class Predicate>
        bool
        wait_until(Lock& lock,
                   const chrono::time_point<Clock, Duration>& abs_time,
                   Predicate pred);

    template <class Lock, class Rep, class Period>
        cv_status
        wait_for(Lock& lock,
                 const chrono::duration<Rep, Period>& rel_time);

    template <class Lock, class Rep, class Period, class Predicate>
        bool
        wait_for(Lock& lock,
                 const chrono::duration<Rep, Period>& rel_time,
                 Predicate pred);
};

}  // std

*/

#include <__config>
#include <__mutex_base>
#include <memory>

#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif

_LIBCPP_BEGIN_NAMESPACE_STD

class _LIBCPP_VISIBLE condition_variable_any
{
    condition_variable __cv_;
    shared_ptr<mutex>  __mut_;
public:
    condition_variable_any();

    void notify_one();
    void notify_all();

    template <class _Lock>
        void wait(_Lock& __lock);
    template <class _Lock, class _Predicate>
        void wait(_Lock& __lock, _Predicate __pred);

    template <class _Lock, class _Clock, class _Duration>
        cv_status
        wait_until(_Lock& __lock,
                   const chrono::time_point<_Clock, _Duration>& __t);

    template <class _Lock, class _Clock, class _Duration, class _Predicate>
        bool
        wait_until(_Lock& __lock,
                   const chrono::time_point<_Clock, _Duration>& __t,
                   _Predicate __pred);

    template <class _Lock, class _Rep, class _Period>
        cv_status
        wait_for(_Lock& __lock,
                 const chrono::duration<_Rep, _Period>& __d);

    template <class _Lock, class _Rep, class _Period, class _Predicate>
        bool
        wait_for(_Lock& __lock,
                 const chrono::duration<_Rep, _Period>& __d,
                 _Predicate __pred);
};

inline _LIBCPP_INLINE_VISIBILITY
condition_variable_any::condition_variable_any()
    : __mut_(make_shared<mutex>()) {}

inline _LIBCPP_INLINE_VISIBILITY
void
condition_variable_any::notify_one()
{
    {lock_guard<mutex> _(*__mut_);}
    __cv_.notify_one();
}

inline _LIBCPP_INLINE_VISIBILITY
void
condition_variable_any::notify_all()
{
    {lock_guard<mutex> _(*__mut_);}
    __cv_.notify_all();
}

struct __lock_external
{
    template <class _Lock>
    void operator()(_Lock* __m) {__m->lock();}
};

template <class _Lock>
void
condition_variable_any::wait(_Lock& __lock)
{
    shared_ptr<mutex> __mut = __mut_;
    unique_lock<mutex> __lk(*__mut);
    __lock.unlock();
    unique_ptr<_Lock, __lock_external> __(&__lock);
    lock_guard<unique_lock<mutex> > _(__lk, adopt_lock);
    __cv_.wait(__lk);
}  // __mut_.unlock(), __lock.lock()

template <class _Lock, class _Predicate>
inline _LIBCPP_INLINE_VISIBILITY
void
condition_variable_any::wait(_Lock& __lock, _Predicate __pred)
{
    while (!__pred())
        wait(__lock);
}

template <class _Lock, class _Clock, class _Duration>
cv_status
condition_variable_any::wait_until(_Lock& __lock,
                                   const chrono::time_point<_Clock, _Duration>& __t)
{
    shared_ptr<mutex> __mut = __mut_;
    unique_lock<mutex> __lk(*__mut);
    __lock.unlock();
    unique_ptr<_Lock, __lock_external> __(&__lock);
    lock_guard<unique_lock<mutex> > _(__lk, adopt_lock);
    return __cv_.wait_until(__lk, __t);
}  // __mut_.unlock(), __lock.lock()

template <class _Lock, class _Clock, class _Duration, class _Predicate>
inline _LIBCPP_INLINE_VISIBILITY
bool
condition_variable_any::wait_until(_Lock& __lock,
                                   const chrono::time_point<_Clock, _Duration>& __t,
                                   _Predicate __pred)
{
    while (!__pred())
        if (wait_until(__lock, __t) == cv_status::timeout)
            return __pred();
    return true;
}

template <class _Lock, class _Rep, class _Period>
inline _LIBCPP_INLINE_VISIBILITY
cv_status
condition_variable_any::wait_for(_Lock& __lock,
                                 const chrono::duration<_Rep, _Period>& __d)
{
    return wait_until(__lock, chrono::steady_clock::now() + __d);
}

template <class _Lock, class _Rep, class _Period, class _Predicate>
inline _LIBCPP_INLINE_VISIBILITY
bool
condition_variable_any::wait_for(_Lock& __lock,
                                 const chrono::duration<_Rep, _Period>& __d,
                                 _Predicate __pred)
{
    return wait_until(__lock, chrono::steady_clock::now() + __d,
                      _VSTD::move(__pred));
}

_LIBCPP_VISIBLE
void notify_all_at_thread_exit(condition_variable& cond, unique_lock<mutex> lk);

_LIBCPP_END_NAMESPACE_STD

#endif  // _LIBCPP_CONDITION_VARIABLE
@


1.1.2.3
log
@## SVN ##
## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/ 243376
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
## SVN ##
## SVN ## ------------------------------------------------------------------------
## SVN ## r243376 | dim | 2012-11-21 18:38:56 +0000 (Wed, 21 Nov 2012) | 14 lines
## SVN ##
## SVN ## MFC r241903:
## SVN ##
## SVN ##   Import libc++ trunk r165949.  Among other improvements and bug fixes,
## SVN ##   this has many visibility problems fixed, which should help with
## SVN ##   compiling certain ports that exercise C++11 mode (i.e. Firefox).
## SVN ##
## SVN ##   Also, belatedly add the LICENSE.TXT and accompanying CREDITS.TXT files,
## SVN ##   which are referred to in all the source files.
## SVN ##
## SVN ## MFC r241907:
## SVN ##
## SVN ##   Fix two -Wsystem-header warnings in libc++ that were exposed by the new
## SVN ##   ATF import.  These have also been sent upstream.
## SVN ##
## SVN ## ------------------------------------------------------------------------
## SVN ##
@
text
@d31 2
a32 2
    void notify_one() noexcept;
    void notify_all() noexcept;
d75 2
a76 2
    void notify_one() noexcept;
    void notify_all() noexcept;
d127 2
a128 2
    void notify_one() _NOEXCEPT;
    void notify_all() _NOEXCEPT;
d164 1
a164 1
condition_variable_any::notify_one() _NOEXCEPT
d172 1
a172 1
condition_variable_any::notify_all() _NOEXCEPT
@


1.1.2.4
log
@## SVN ##
## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/243683
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
## SVN ##
## SVN ## ------------------------------------------------------------------------
## SVN ## r243683 | dim | 2012-11-29 21:26:57 +0000 (Thu, 29 Nov 2012) | 4 lines
## SVN ##
## SVN ## MFC r242945 (by theraven):
## SVN ##
## SVN ##   Import new version of libc++ into base.
## SVN ##
## SVN ## ------------------------------------------------------------------------
## SVN ##
@
text
@d166 1
a166 1
    {lock_guard<mutex> __lx(*__mut_);}
d174 1
a174 1
    {lock_guard<mutex> __lx(*__mut_);}
d191 2
a192 2
    unique_ptr<_Lock, __lock_external> __lxx(&__lock);
    lock_guard<unique_lock<mutex> > __lx(__lk, adopt_lock);
d213 2
a214 2
    unique_ptr<_Lock, __lock_external> __lxx(&__lock);
    lock_guard<unique_lock<mutex> > __lx(__lk, adopt_lock);
@


1.1.2.5
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/250514
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@d120 1
a120 1
class _LIBCPP_TYPE_VIS condition_variable_any
d251 1
a251 1
_LIBCPP_FUNC_VIS
@


