Undefined ref to 'function<void ()()>::operator()() const' when called from free function defined in cc file.
Peter Dimov
pdimov@mmltd.net
Sat Aug 30 05:38:00 GMT 2008
Chris Fairles wrote:
> extern function<void()> __once_proxy_object;
> extern unique_lock<mutex> __once_proxy_lock;
> extern "C" void __once_proxy();
>
> template<typename _Callable, typename... _Args>
> void
> call_once(once_flag& __once, _Callable __f, _Args&&... __args)
> {
> __once_proxy_lock.lock();
> __once_proxy_object = bind(__f, __args...);
>
> int __e = __gthread_once(&(__once._M_once), &__once_proxy);
>
> if(__once_proxy_lock)
> __once_proxy_lock.unlock();
>
> if (__e)
> __throw_system_error(__e);
> }
Can you use thread locals?
extern __thread void* __once_callable;
extern __thread void (*__once_call)();
extern "C" void __once_proxy();
template<typename _Callable>
void __once_call_impl()
{
(*(_Callable*)__once_calable)();
}
template<typename _Callable>
void call_once(once_flag& __once, _Callable __f)
{
__once_callable = &__f;
__once_call = &__once_call_impl<_Callable>;
__gthread_once(&__once._M_once, &__once_proxy);
}
or something. :-)
More information about the Libstdc++
mailing list