diff --git a/indra/llcommon/aithreadsafe.h b/indra/llcommon/aithreadsafe.h index 2c11908af..a8b1ac490 100644 --- a/indra/llcommon/aithreadsafe.h +++ b/indra/llcommon/aithreadsafe.h @@ -132,6 +132,14 @@ public: // Only for use by AITHREADSAFE, see below. void* memory() const { return const_cast(&mMemory[0]); } + // Cast a T* back to AIThreadSafeBits. This is the inverse of memory(). + template + static AIThreadSafeBits* wrapper_cast(T2* ptr) + { return reinterpret_cast*>(reinterpret_cast(ptr) - offsetof(AIThreadSafeBits, mMemory[0])); } + template + static AIThreadSafeBits const* wrapper_cast(T2 const* ptr) + { return reinterpret_cast const*>(reinterpret_cast(ptr) - offsetof(AIThreadSafeBits, mMemory[0])); } + protected: // Accessors. T const* ptr() const { return reinterpret_cast(mMemory); }