--------------------------------------------------------------------------*/ / Main watchdog worker thread. */ For singleton workers child thread that first obtains the process */ mutex is running. Threads in other child's are locked on mutex. */ / --------------------------------------------------------------------------*/
| 105 | /* */ |
| 106 | /*--------------------------------------------------------------------------*/ |
| 107 | static void* APR_THREAD_FUNC wd_worker(apr_thread_t *thread, void *data) |
| 108 | { |
| 109 | ap_watchdog_t *w = (ap_watchdog_t *)data; |
| 110 | apr_status_t rv; |
| 111 | int locked = 0; |
| 112 | int probed = 0; |
| 113 | int inited = 0; |
| 114 | int mpmq_s = 0; |
| 115 | apr_pool_t *temp_pool = NULL; |
| 116 | |
| 117 | w->pool = apr_thread_pool_get(thread); |
| 118 | w->is_running = 1; |
| 119 | |
| 120 | apr_atomic_set32(&w->thread_started, 1); /* thread started */ |
| 121 | |
| 122 | if (w->mutex) { |
| 123 | while (w->is_running) { |
| 124 | if (ap_mpm_query(AP_MPMQ_MPM_STATE, &mpmq_s) != APR_SUCCESS) { |
| 125 | w->is_running = 0; |
| 126 | break; |
| 127 | } |
| 128 | if (mpmq_s == AP_MPMQ_STOPPING) { |
| 129 | w->is_running = 0; |
| 130 | break; |
| 131 | } |
| 132 | rv = apr_proc_mutex_trylock(w->mutex); |
| 133 | if (rv == APR_SUCCESS) { |
| 134 | if (probed) { |
| 135 | /* Sleep after we were locked |
| 136 | * up to 1 second. Httpd can be |
| 137 | * in the middle of shutdown, and |
| 138 | * our child didn't yet received |
| 139 | * the shutdown signal. |
| 140 | */ |
| 141 | probed = 10; |
| 142 | while (w->is_running && probed > 0) { |
| 143 | apr_sleep(AP_WD_TM_INTERVAL); |
| 144 | probed--; |
| 145 | if (ap_mpm_query(AP_MPMQ_MPM_STATE, &mpmq_s) != APR_SUCCESS) { |
| 146 | w->is_running = 0; |
| 147 | break; |
| 148 | } |
| 149 | if (mpmq_s == AP_MPMQ_STOPPING) { |
| 150 | w->is_running = 0; |
| 151 | break; |
| 152 | } |
| 153 | } |
| 154 | } |
| 155 | locked = 1; |
| 156 | break; |
| 157 | } |
| 158 | probed = 1; |
| 159 | apr_sleep(AP_WD_TM_SLICE); |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | apr_pool_create(&temp_pool, w->pool); |
| 164 | apr_pool_tag(temp_pool, "wd_running"); |
nothing calls this directly
no test coverage detected