return f;
}
-#ifdef USE_THREADS
-perl_mutex PerlIO_mutex;
-#endif
-
/* PL_perlio_fd_refcnt[] is in intrpvar.h */
-/* Must be called with PerlIO_mutex locked. */
+/* Must be called with PL_perlio_mutex locked (if under 5.005 threads). */
static void
S_more_refcounted_fds(pTHX_ const int new_fd) {
dVAR;
if (!new_array) {
#ifdef USE_THREADS
- MUTEX_UNLOCK(&PerlIO_mutex);
+ MUTEX_UNLOCK(&PL_perlio_mutex);
#endif
/* Can't use PerlIO to write as it allocates memory */
PerlLIO_write(PerlIO_fileno(Perl_error_log),
{
/* Place holder for stdstreams call ??? */
#ifdef USE_THREADS
- MUTEX_INIT(&PerlIO_mutex);
+ MUTEX_INIT(&PL_perlio_mutex);
#else
PERL_UNUSED_CONTEXT;
#endif
dVAR;
#ifdef USE_THREADS
- MUTEX_LOCK(&PerlIO_mutex);
+ MUTEX_LOCK(&PL_perlio_mutex);
#endif
if (fd >= PL_perlio_fd_refcnt_size)
S_more_refcounted_fds(aTHX_ fd);
PerlIO_debug("fd %d refcnt=%d\n",fd,PL_perlio_fd_refcnt[fd]);
#ifdef USE_THREADS
- MUTEX_UNLOCK(&PerlIO_mutex);
+ MUTEX_UNLOCK(&PL_perlio_mutex);
#endif
}
}
if (fd >= 0) {
dVAR;
#ifdef USE_THREADS
- MUTEX_LOCK(&PerlIO_mutex);
+ MUTEX_LOCK(&PL_perlio_mutex);
#endif
/* XXX should this be a panic? */
if (fd >= PL_perlio_fd_refcnt_size)
cnt = --PL_perlio_fd_refcnt[fd];
PerlIO_debug("fd %d refcnt=%d\n",fd,cnt);
#ifdef USE_THREADS
- MUTEX_UNLOCK(&PerlIO_mutex);
+ MUTEX_UNLOCK(&PL_perlio_mutex);
#endif
}
return cnt;
PerlIO_debug("Cleanup layers\n");
#endif
-#ifdef DEBUGGING
- {
- /* By now all filehandles should have been closed, so any
- * stray (non-STD-)filehandles indicate *possible* (PerlIO)
- * errors. */
- for (i = 3; i < PL_perlio_fd_refcnt_size; i++) {
- if (PL_perlio_fd_refcnt[i])
- PerlIO_debug("PerlIO_cleanup: fd %d refcnt=%d\n",
- i, PL_perlio_fd_refcnt[i]);
- }
- }
-#endif
-
/* Raise STDIN..STDERR refcount so we don't close them */
for (i=0; i < 3; i++)
PerlIOUnix_refcnt_inc(i);
PerlIO_list_free(aTHX_ PL_def_layerlist);
PL_def_layerlist = NULL;
}
+}
+
+void PerlIO_teardown(pTHX) /* Call only from PERL_SYS_TERM(). */
+{
+#ifdef DEBUGGING
+ {
+ /* By now all filehandles should have been closed, so any
+ * stray (non-STD-)filehandles indicate *possible* (PerlIO)
+ * errors. */
+ int i;
+ for (i = 3; i < PL_perlio_fd_refcnt_size; i++) {
+ if (PL_perlio_fd_refcnt[i])
+ PerlIO_debug("PerlIO_cleanup: fd %d refcnt=%d\n",
+ i, PL_perlio_fd_refcnt[i]);
+ }
+ }
+#endif
#ifdef USE_THREADS
- MUTEX_UNLOCK(&PerlIO_mutex);
+ MUTEX_LOCK(&PL_perlio_mutex);
#endif
if (PL_perlio_fd_refcnt_size /* Assuming initial size of zero. */
&& PL_perlio_fd_refcnt) {
if (header->interpreter == aTHX)
#endif
{
- Safefree(PL_perlio_fd_refcnt);
+ PerlMemShared_free(PL_perlio_fd_refcnt); /* Not Safefree() because was allocated with PerlMemShared_realloc(). */
PL_perlio_fd_refcnt = NULL;
PL_perlio_fd_refcnt_size = 0;
}
}
#ifdef USE_THREADS
- MUTEX_UNLOCK(&PerlIO_mutex);
+ MUTEX_UNLOCK(&PL_perlio_mutex);
#endif
}