}
#endif /* COLLECT_DEBUG */
+ if (0 != pthread_key_create (&perl_thr_key, c_ithread_destructor)) {
+ log_err ("init_pi: pthread_key_create failed");
+
+ /* this must not happen - cowardly giving up if it does */
+ exit (1);
+ }
+
+ #ifdef __FreeBSD__
+ /* On FreeBSD, PERL_SYS_INIT3 expands to some expression which
+ * triggers a "value computed is not used" warning by gcc. */
+ (void)
+ #endif
PERL_SYS_INIT3 (&argc, &argv, &environ);
- if (NULL == (perl = perl_alloc ())) {
- log_err ("module_register: Not enough memory.");
+ perl_threads = (c_ithread_list_t *)smalloc (sizeof (c_ithread_list_t));
+ memset (perl_threads, 0, sizeof (c_ithread_list_t));
+
+ pthread_mutex_init (&perl_threads->mutex, NULL);
+ /* locking the mutex should not be necessary at this point
+ * but let's just do it for the sake of completeness */
+ pthread_mutex_lock (&perl_threads->mutex);
+
+ perl_threads->head = c_ithread_create (NULL);
+ perl_threads->tail = perl_threads->head;
+
+ if (NULL == (perl_threads->head->interp = perl_alloc ())) {
+ log_err ("init_pi: Not enough memory.");
exit (3);
}
- perl_construct (perl);
+
+ aTHX = perl_threads->head->interp;
+ pthread_mutex_unlock (&perl_threads->mutex);
+
+ perl_construct (aTHX);
PL_exit_flags |= PERL_EXIT_DESTRUCT_END;