thread_data (aka th_params) was merged into global_state, as they both did the same thing. ARRAYS that need realloc on thread number change: threads, tids, params, stridesArray, iter, reduce_iter
| 30 | // ARRAYS that need realloc on thread number change: |
| 31 | // threads, tids, params, stridesArray, iter, reduce_iter |
| 32 | struct global_state { |
| 33 | // Global variables for threads |
| 34 | int n_thread; // number of desired threads in pool |
| 35 | int init_threads_done; // pool of threads initialized? |
| 36 | pthread_t* threads; // ARRAY, opaque structure for threads |
| 37 | int* tids; // ARRAY, ID per each thread |
| 38 | npy_intp gindex; // global index for all threads |
| 39 | int init_sentinels_done; // Flag, sentinels initialized? |
| 40 | int giveup; // Flag, should parallel code giveup? |
| 41 | int force_serial; // Flag, force serial code instead of parallel? |
| 42 | int pid; // the PID for this process |
| 43 | |
| 44 | // Program control and registry structs |
| 45 | NumExprObject* params; // ARRAY, copies the programs and registers for each thread. |
| 46 | char* registerArena; // Holds n_threads * MAXARGS * sizeof(NumExprReg) memory in a block |
| 47 | |
| 48 | // Temporaries in a pre-allocated block |
| 49 | // A private pool/arena for temporaries so the interpreter does not have to |
| 50 | // allocate and deallocate memory with each execution. |
| 51 | char* tempArena; // The pointer to the temporary memory region |
| 52 | Py_ssize_t tempSize; // The size of the temporary memory region |
| 53 | |
| 54 | // Syncronization variables |
| 55 | pthread_mutex_t global_mutex; // Previously was a Python threading.Lock() |
| 56 | pthread_mutex_t count_mutex; |
| 57 | int count_threads; |
| 58 | int barrier_passed; // Indicates if the thread pool's thread barrier |
| 59 | // is unlocked and ready for the VM to process |
| 60 | // to prevent spurious wakeups on `nix systems. |
| 61 | // 0 indicates not past barrier, 1 indicates |
| 62 | // the VM is running. |
| 63 | // -1 indicates the thread has been ordered to |
| 64 | // exit, a function previously occupied by `end_threads` |
| 65 | pthread_mutex_t count_threads_mutex; |
| 66 | pthread_cond_t count_threads_cv; |
| 67 | |
| 68 | // NumPy iterator handles |
| 69 | npy_intp start; |
| 70 | npy_intp vlen; |
| 71 | npy_intp task_size; |
| 72 | |
| 73 | npy_intp* stridesArray; // ARRAY, one strides array per thread |
| 74 | NpyIter** iter; // ARRAY, one iterator per thread |
| 75 | NpyIter** reduce_iter; // ARRAY, when doing nested iteration for a reduction |
| 76 | bool reduction_outer_loop; // Flag indicating reduction is the outer loop instead of the inner |
| 77 | bool need_output_buffering; // Flag indicating whether output buffering is needed |
| 78 | |
| 79 | // Global return and error handling |
| 80 | int ret_code; |
| 81 | int *pc_error; |
| 82 | char **errorMessage; |
| 83 | |
| 84 | global_state() { |
| 85 | // Initialize mutex and condition variable objects |
| 86 | pthread_mutex_init(&count_mutex, NULL); |
| 87 | pthread_mutex_init(&global_mutex, NULL); |
| 88 | // Barrier initialization |
| 89 | pthread_mutex_init(&count_threads_mutex, NULL); |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…