perl/win32/win32thread.c
bulk88 650608f18d de-layer Perlhost.h's 3 Malloc() classed + Cwd class
-Perl's primary malloc pool (per interp, never ithread shared), doesnt
 need CS mutexes, the refcounting/multiple my_perl owners infrastruture,
 etc. Inline the IPerlMem/VPerLMem class/struct direct into CPerlHost
 class. Less ptr derefs at runtime. Saves memory, because no malloc header.
 And remove the 0x24 ??? bytes on x86-32 CS/mutex struct.
-Use retval of libc's memset(), saves a non-vol reg push/pop/saving cycle.
 ZeroMemory() has void retval. Lack of a Calloc() API in VMem.h is for
 another time.
-"virtual int Chdir(const char *dirname);" remove virtual tag. It is
 unused ptr indirection. Also the secret C++ vtable ptr im CPerlHost
 objs is now gone.
-inline VDir obj into CPerlHost, VDir *s are not shared between interps.
-Sort machine type integer members of CPerlHost class by size. Remove
 Alignment holes.
-Speedup  win32_checkTLS(), win32_checkTLS() is probably redundant
 outside -DDEBUGGING nowadays, it was added in commit

222c300afb1c8466398010a3403616462c302185  1/13/2002 10:37:48 AM
Win32 fixes:
 - vmem.h hack to handle free-by-wrong-thread after eval "".

still will leave it in for now, just optimize it instead.

I benchmarked, 10000x calls to Perl_get_context() in a loop.
Retval ignored, is 126 us (microsec). 10000x calls to
GetCurrentThreadId(), is 34 us.
2025-03-19 05:18:15 +01:00

41 lines
742 B
C

#include "EXTERN.h"
#include "perl.h"
#ifdef USE_DECLSPEC_THREAD
__declspec(thread) void *PL_current_context = NULL;
#endif
void
Perl_set_context(void *t)
{
#if defined(USE_ITHREADS)
# ifdef USE_DECLSPEC_THREAD
Perl_current_context = t;
PERL_SET_NON_tTHX_CONTEXT(t);
# else
DWORD err = GetLastError();
TlsSetValue(PL_thr_key,t);
SetLastError(err);
# endif
dTHXa(t);
PL_sys_intern.cur_tid = GetCurrentThreadId();
#endif
}
void *
Perl_get_context(void)
{
#if defined(USE_ITHREADS)
# ifdef USE_DECLSPEC_THREAD
return Perl_current_context;
# else
DWORD err = GetLastError();
void *result = TlsGetValue(PL_thr_key);
SetLastError(err);
return result;
# endif
#else
return NULL;
#endif
}