Re: [AD] mingw, static, tls

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


On Sat, July 18, 2009 10:32 am, Elias Pschernig said:
> I guess it should be possible to create TLS "manually", by using the
> current thread id to return the right value in all the tls functions.

Yeah I guess. Something like this should sort of work (pseudo code):

DWORD cookie;

thread_local_state *tls_get(void)
{
   static bool initialized = false;

   if (!initialized) {
      cookie = TlsAlloc();
      initialized = true;
   }

   thread_local_state *tls = TlsGetValue(cookie);
   if (tls == NULL && GetLastError() == NO_ERROR) {
      tls = _AL_MALLOC(sizeof(tls));
      /* initialize tls */
      TlsSetValue(cookie, tls);
   }

   return tls;
}


But how do you free the memory?

Trent :{)>




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/