-/* Implements the MY_CXT_INIT macro. The first time a module is loaded,
-the global PL_my_cxt_index is incremented, and that value is assigned to
-that module's static my_cxt_index (who's address is passed as an arg).
-Then, for each interpreter this function is called for, it makes sure a
-void* slot is available to hang the static data off, by allocating or
-extending the interpreter's PL_my_cxt_list array */
-
-#ifndef PERL_GLOBAL_STRUCT_PRIVATE
-void *
-Perl_my_cxt_init(pTHX_ int *index, size_t size)
-{
- dVAR;
- void *p;
- PERL_ARGS_ASSERT_MY_CXT_INIT;
- if (*index == -1) {
- /* this module hasn't been allocated an index yet */
- MUTEX_LOCK(&PL_my_ctx_mutex);
- *index = PL_my_cxt_index++;
- MUTEX_UNLOCK(&PL_my_ctx_mutex);
- }
-
- /* make sure the array is big enough */
- if (PL_my_cxt_size <= *index) {
- if (PL_my_cxt_size) {
- IV new_size = PL_my_cxt_size;
- while (new_size <= *index)
- new_size *= 2;
- Renew(PL_my_cxt_list, new_size, void *);
- PL_my_cxt_size = new_size;
- }
- else {
- PL_my_cxt_size = 16;
- Newx(PL_my_cxt_list, PL_my_cxt_size, void *);
- }
- }
- /* newSV() allocates one more than needed */
- p = (void*)SvPVX(newSV(size-1));
- PL_my_cxt_list[*index] = p;
- Zero(p, size, char);
- return p;
-}