This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: Undefined ref to 'function<void ()()>::operator()() const' when called from free function defined in cc file.
On Fri, Aug 29, 2008 at 9:19 AM, Peter Dimov <pdimov@mmltd.net> wrote:
> 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. :-)
>
>
Yeah. I'm not a huge fan of this global function<> w/ mutex method (i
could name a few deadlock cases off the top of my head, __f making a
call_once with the same once_flag to name one). I'm not 100% familiar
with GCC's TLS support (other than gthread's get/setspecific) but I'll
definitely take a look.
Thanks for the tip (and will make sure to use GLIBCXX_HAVE_TLS)
Chris