This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Undefined ref to 'function<void ()()>::operator()() const' when called from free function defined in cc file.


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. :-)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]