Perform blas_thread_shutdown with pthread_atfork() on Cygwin
Even if we're directly using the win32 threading driver and not pthreads, pthread_atfork still works fine to register a pre-fork handler, and is necessary to restore the threading server to a pre-initialized state.
This commit is contained in:
parent
ce2028b425
commit
f5fc109fbd
|
@ -40,6 +40,14 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
|
#if defined(OS_CYGWIN_NT) && !defined(unlikely)
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#define unlikely(x) __builtin_expect(!!(x), 0)
|
||||||
|
#else
|
||||||
|
#define unlikely(x) (x)
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
/* This is a thread implementation for Win32 lazy implementation */
|
/* This is a thread implementation for Win32 lazy implementation */
|
||||||
|
|
||||||
/* Thread server common infomation */
|
/* Thread server common infomation */
|
||||||
|
@ -53,7 +61,7 @@ typedef struct{
|
||||||
|
|
||||||
} blas_pool_t;
|
} blas_pool_t;
|
||||||
|
|
||||||
/* We need this grobal for cheking if initialization is finished. */
|
/* We need this global for cheking if initialization is finished. */
|
||||||
int blas_server_avail = 0;
|
int blas_server_avail = 0;
|
||||||
|
|
||||||
/* Local Variables */
|
/* Local Variables */
|
||||||
|
@ -340,6 +348,11 @@ int blas_thread_init(void){
|
||||||
|
|
||||||
int exec_blas_async(BLASLONG pos, blas_queue_t *queue){
|
int exec_blas_async(BLASLONG pos, blas_queue_t *queue){
|
||||||
|
|
||||||
|
#if defined(SMP_SERVER) && defined(OS_CYGWIN_NT)
|
||||||
|
// Handle lazy re-init of the thread-pool after a POSIX fork
|
||||||
|
if (unlikely(blas_server_avail == 0)) blas_thread_init();
|
||||||
|
#endif
|
||||||
|
|
||||||
blas_queue_t *current;
|
blas_queue_t *current;
|
||||||
|
|
||||||
current = queue;
|
current = queue;
|
||||||
|
@ -405,6 +418,11 @@ int exec_blas_async_wait(BLASLONG num, blas_queue_t *queue){
|
||||||
/* Execute Threads */
|
/* Execute Threads */
|
||||||
int exec_blas(BLASLONG num, blas_queue_t *queue){
|
int exec_blas(BLASLONG num, blas_queue_t *queue){
|
||||||
|
|
||||||
|
#if defined(SMP_SERVER) && defined(OS_CYGWIN_NT)
|
||||||
|
// Handle lazy re-init of the thread-pool after a POSIX fork
|
||||||
|
if (unlikely(blas_server_avail == 0)) blas_thread_init();
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef ALL_THREADED
|
#ifndef ALL_THREADED
|
||||||
int (*routine)(blas_arg_t *, void *, void *, double *, double *, BLASLONG);
|
int (*routine)(blas_arg_t *, void *, void *, double *, double *, BLASLONG);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -323,7 +323,7 @@ void openblas_fork_handler()
|
||||||
// http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60035
|
// http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60035
|
||||||
// In the mean time build with USE_OPENMP=0 or link against another
|
// In the mean time build with USE_OPENMP=0 or link against another
|
||||||
// implementation of OpenMP.
|
// implementation of OpenMP.
|
||||||
#if !(defined(OS_WINDOWS) || defined(OS_ANDROID)) && defined(SMP_SERVER)
|
#if !((defined(OS_WINDOWS) && !defined(OS_CYGWIN_NT)) || defined(OS_ANDROID)) && defined(SMP_SERVER)
|
||||||
int err;
|
int err;
|
||||||
err = pthread_atfork ((void (*)(void)) BLASFUNC(blas_thread_shutdown), NULL, NULL);
|
err = pthread_atfork ((void (*)(void)) BLASFUNC(blas_thread_shutdown), NULL, NULL);
|
||||||
if(err != 0)
|
if(err != 0)
|
||||||
|
|
Loading…
Reference in New Issue