Skip to content

Commit 0f65d45

Browse files
committed
whitespace,etc
1 parent d81ad0c commit 0f65d45

9 files changed

Lines changed: 93 additions & 74 deletions

File tree

src/modules/perl/mod_perl.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,26 +1034,26 @@ int modperl_response_handler(request_rec *r)
10341034
{
10351035
MP_dDCFG;
10361036
apr_status_t retval, rc;
1037-
1037+
10381038
if (!strEQ(r->handler, "modperl")) {
10391039
return DECLINED;
10401040
}
10411041

10421042
/* default is -SetupEnv, add if PerlOption +SetupEnv */
1043-
1043+
10441044
MP_dINTERPa(r, NULL, NULL);
10451045

10461046
if (MpDirSETUP_ENV(dcfg)) {
10471047
modperl_env_request_populate(aTHX_ r);
10481048
}
10491049

1050-
1050+
10511051
retval = modperl_response_handler_run(r);
10521052
rc = modperl_response_finish(r);
10531053
if (rc != APR_SUCCESS) {
10541054
retval = rc;
10551055
}
1056-
1056+
10571057
MP_INTERP_PUTBACK(interp, aTHX);
10581058
return retval;
10591059
}

src/modules/perl/modperl_callback.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ int modperl_callback_run_handlers(int idx, int type,
179179
desc, r ? r->uri : "");
180180
return DECLINED;
181181
}
182-
182+
183183
MP_dINTERPa(r, c, s);
184184

185185
switch (type) {

src/modules/perl/modperl_config.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ apr_status_t modperl_config_req_cleanup(void *data)
367367
{
368368
request_rec *r = (request_rec *)data;
369369
apr_pool_t *p = ap_is_initial_req(r) ? r->pool : r->main->pool;
370-
modperl_interp_t *interp = modperl_interp_pool_get(p);
370+
modperl_interp_t *interp = modperl_interp_pool_get(p);
371371
if (interp && interp->perl)
372372
return modperl_config_request_cleanup(interp->perl, r);
373373
dTHX;

src/modules/perl/modperl_filter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ int modperl_run_filter(modperl_filter_t *filter)
486486
server_rec *s = r ? r->server : c->base_server;
487487
apr_pool_t *p = r ? r->pool : c->pool;
488488

489-
MP_dINTERPa(NULL, NULL, s); /* this needs to NOT be the interpreter in r->pool */
489+
MP_dINTERPa(r, c, s);
490490

491491
MP_FILTER_SAVE_ERRSV(errsv);
492492

src/modules/perl/modperl_interp.c

Lines changed: 49 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ modperl_interp_t *modperl_interp_new(modperl_interp_pool_t *mip,
6161
clone_flags |= CLONEf_CLONE_HOST;
6262
#endif
6363

64-
64+
PERL_SET_CONTEXT(perl);
6565
interp->perl = perl_clone(perl, clone_flags);
6666
PERL_SET_CONTEXT(interp->perl);
6767

@@ -85,7 +85,7 @@ modperl_interp_t *modperl_interp_new(modperl_interp_pool_t *mip,
8585
* are different things, although they use the same type.
8686
*/
8787
if ((clone_flags & CLONEf_KEEP_PTR_TABLE)) {
88-
dTHXa(interp->perl);
88+
dTHXa(interp->perl);
8989
ptr_table_free(PL_ptr_table);
9090
PL_ptr_table = NULL;
9191
}
@@ -112,8 +112,6 @@ void modperl_interp_destroy(modperl_interp_t *interp)
112112
void **handles;
113113
dTHXa(interp->perl);
114114

115-
PERL_SET_CONTEXT(interp->perl);
116-
117115
MP_TRACE_i(MP_FUNC, "interp == 0x%lx / perl: 0x%lx",
118116
(unsigned long)interp, (unsigned long)interp->perl);
119117

@@ -249,12 +247,23 @@ void modperl_interp_init(server_rec *s, apr_pool_t *p,
249247
scfg->mip = mip;
250248
}
251249

250+
static apr_status_t modperl_interp_pool_unselect(void *data)
251+
{
252+
modperl_interp_t *interp = (modperl_interp_t *)data;
253+
if (interp->refcnt > 1) {
254+
MP_TRACE_i(MP_FUNC, "BIZARRE REFCNT: unselect(interp=%pp): refcnt=%d",
255+
interp, interp->refcnt);
256+
interp->refcnt = 1;
257+
}
258+
return modperl_interp_unselect(data);
259+
}
260+
252261
apr_status_t modperl_interp_unselect(void *data)
253262
{
254263
modperl_interp_t *interp = (modperl_interp_t *)data;
255264
modperl_interp_pool_t *mip = interp->mip;
256265
modperl_tipool_t *tipool = mip->tipool;
257-
266+
258267
MP_ASSERT(interp && MpInterpIN_USE(interp) && interp->refcnt > 0);
259268
MP_TRACE_i(MP_FUNC, "unselect(interp=%pp): refcnt=%d",
260269
interp, interp->refcnt);
@@ -274,8 +283,8 @@ apr_status_t modperl_interp_unselect(void *data)
274283
MpInterpIN_USE_Off(interp);
275284

276285
if (interp->pool)
277-
apr_pool_cleanup_kill(interp->pool, interp, modperl_interp_unselect), interp->pool = NULL;
278-
286+
apr_pool_cleanup_kill(interp->pool, interp, modperl_interp_pool_unselect), interp->pool = NULL;
287+
279288
modperl_thx_interp_set(interp->perl, NULL);
280289
#ifdef MP_DEBUG
281290
PERL_SET_CONTEXT(NULL);
@@ -305,7 +314,7 @@ apr_status_t modperl_interp_unselect(void *data)
305314

306315
#define set_interp(p) \
307316
(void)apr_pool_userdata_set((void *)interp, MP_INTERP_KEY, \
308-
modperl_interp_unselect, \
317+
modperl_interp_pool_unselect, \
309318
p)
310319

311320
modperl_interp_t *modperl_interp_pool_get(apr_pool_t *p)
@@ -321,6 +330,15 @@ void modperl_interp_pool_set(apr_pool_t *p,
321330
(void)apr_pool_userdata_set((void *)interp, MP_INTERP_KEY, NULL, p);
322331
}
323332

333+
modperl_interp_t *modperl_interp_pool_unset(apr_pool_t *p)
334+
{
335+
modperl_interp_t *interp = NULL;
336+
get_interp(p);
337+
(void)apr_pool_userdata_set(NULL, MP_INTERP_KEY, NULL, p);
338+
return interp;
339+
}
340+
341+
324342
/*
325343
* used in the case where we don't have a request_rec or conn_rec,
326344
* such as for directive handlers per-{dir,srv} create and merge.
@@ -344,7 +362,7 @@ modperl_interp_t *modperl_interp_pool_select(apr_pool_t *p,
344362
modperl_init_vhost(s, p, NULL);
345363
if (!scfg->mip) {
346364
/* FIXME: We get here if global "server_rec" == s, scfg->mip
347-
* is not created then. I'm not sure if that's bug or
365+
* is not created then. I'm not sure if that's bug or
348366
* bad/good design decicision. For now just return NULL.
349367
*/
350368
return NULL;
@@ -420,12 +438,13 @@ modperl_interp_t *modperl_interp_select(request_rec *r, conn_rec *c, server_rec
420438
return interp;
421439
}
422440

423-
if (r && !ap_is_initial_req(r))
441+
if (!ap_is_initial_req(r))
424442
r = r->main;
425-
443+
426444
p = r ? r->pool : c ? c->pool : NULL;
427445

428446
if (r && !c) c = r->connection;
447+
429448
if (c)
430449
ccfg = modperl_config_con_get(c);
431450

@@ -438,29 +457,19 @@ modperl_interp_t *modperl_interp_select(request_rec *r, conn_rec *c, server_rec
438457
PERL_SET_CONTEXT(interp->perl);
439458
return interp;
440459
}
441-
#if 0
442-
if (ccfg && ccfg->interp) {
443-
ccfg->interp->refcnt++;
444-
MP_TRACE_i(MP_FUNC,
445-
"found interp 0x%lx in con config, refcnt incremented to %d",
446-
(unsigned long)ccfg->interp, ccfg->interp->refcnt);
447-
PERL_SET_CONTEXT(interp->perl);
448-
return ccfg->interp;
449-
}
450-
#endif
460+
451461
MP_TRACE_i(MP_FUNC,
452462
"fetching interp for %s:%d", s->server_hostname, s->port);
453463
interp = modperl_interp_get(s);
454464
MP_TRACE_i(MP_FUNC, " --> got %pp (perl=%pp)", interp, interp->perl);
455465
++interp->num_requests; /* should only get here once per request */
456466
interp->refcnt = 1;
457467

468+
PERL_SET_CONTEXT(interp->perl);
458469
modperl_thx_interp_set(interp->perl, interp);
459470

460-
/* make sure ccfg is initialized */
471+
/* make sure ccfg/rcfg is initialized */
461472
modperl_config_con_init(c, ccfg);
462-
if (r)
463-
modperl_config_req_init(r, rcfg);
464473

465474
if (ccfg && ccfg->interp == NULL)
466475
ccfg->interp = interp;
@@ -471,7 +480,22 @@ modperl_interp_t *modperl_interp_select(request_rec *r, conn_rec *c, server_rec
471480
"pulled interp %pp (perl=%pp) from mip, num_requests is %d",
472481
interp, interp->perl, interp->num_requests);
473482
if (p)
474-
set_interp(p), interp->pool = p;
483+
/* it is correct to bump the refcnt below, assuming mod_http2's h2_stream.c is patched:
484+
485+
486+
@@ -659,16 +659,16 @@ apr_status_t h2_stream_set_request_rec(h2_stream *stream,
487+
if (stream->rst_error) {
488+
return APR_ECONNRESET;
489+
}
490+
- status = h2_request_rcreate(&req, stream->pool, r,
491+
+ status = h2_request_rcreate(&req, r->pool, r,
492+
&stream->session->hd_scratch);
493+
if (status == APR_SUCCESS) {
494+
495+
496+
497+
*/
498+
interp->refcnt++, set_interp(p), interp->pool = p;
475499

476500
return interp;
477501
}

src/modules/perl/modperl_interp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ modperl_interp_t *modperl_interp_pool_get(apr_pool_t *p);
4242

4343
void modperl_interp_pool_set(apr_pool_t *p,
4444
modperl_interp_t *interp);
45+
modperl_interp_t *modperl_interp_pool_unset(apr_pool_t *p);
4546

4647
modperl_interp_t *modperl_interp_pool_select(apr_pool_t *p,
4748
server_rec *s);

src/modules/perl/modperl_tipool.c

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ void modperl_tipool_destroy(modperl_tipool_t *tipool)
220220
}
221221

222222
MUTEX_DESTROY(&tipool->tiplock);
223-
COND_DESTROY(&tipool->available);
223+
COND_DESTROY(&tipool->available);
224224
}
225225

226226
void modperl_tipool_add(modperl_tipool_t *tipool, void *data)
@@ -254,12 +254,12 @@ void modperl_tipool_remove(modperl_tipool_t *tipool, modperl_list_t *listp)
254254
modperl_list_t *modperl_tipool_pop(modperl_tipool_t *tipool)
255255
{
256256

257-
258-
START:
257+
259258
modperl_tipool_lock(tipool);
260259
volatile modperl_list_t *head = tipool->idle;
261260

262261
if (!head) {
262+
START:
263263
if (tipool->size < tipool->cfg->max) {
264264
if (tipool->func->tipool_rgrow) {
265265
MP_TRACE_i(MP_FUNC,
@@ -269,20 +269,19 @@ modperl_list_t *modperl_tipool_pop(modperl_tipool_t *tipool)
269269
void *item =
270270
(*tipool->func->tipool_rgrow)(tipool,
271271
tipool->data);
272-
273272
modperl_tipool_add(tipool, item);
274273
}
274+
}
275275
else
276276
modperl_tipool_wait(tipool);
277-
}
277+
278278
head = tipool->idle;
279279
}
280280

281281
/* XXX: this should never happen */
282282
if (!head) {
283283
MP_TRACE_i(MP_FUNC, "PANIC: no items available, %d of %d in use",
284284
tipool->in_use, tipool->size);
285-
modperl_tipool_unlock(tipool);
286285
goto START;
287286
}
288287
tipool->idle = modperl_list_remove(tipool->idle, head);
@@ -298,7 +297,6 @@ static void modperl_tipool_putback_base(modperl_tipool_t *tipool,
298297
void *data,
299298
int num_requests)
300299
{
301-
int max_spare, max_requests;
302300
modperl_tipool_lock(tipool);
303301

304302
/* remove from busy list, add back to idle */
@@ -311,8 +309,9 @@ static void modperl_tipool_putback_base(modperl_tipool_t *tipool,
311309
tipool->busy = modperl_list_remove_data(tipool->busy, data, &listp);
312310
}
313311

312+
tipool->in_use--;
313+
314314
if (!listp) {
315-
modperl_tipool_unlock(tipool);/* XXX: Attempt to putback something that was never there */
316315
goto MANAGE_POOL;
317316
}
318317

@@ -325,54 +324,47 @@ static void modperl_tipool_putback_base(modperl_tipool_t *tipool,
325324
}
326325
#endif
327326

328-
tipool->in_use--;
329327
MP_TRACE_i(MP_FUNC, "0x%lx now available (%d in use, %d running)",
330328
(unsigned long)listp->data, tipool->in_use, tipool->size);
331329

332-
modperl_interp_t *interp = listp->data;
333-
334330
tipool->idle = modperl_list_prepend(tipool->idle, listp);
335331
modperl_tipool_signal(tipool);
336-
modperl_tipool_unlock(tipool);
337-
338-
max_spare = ((tipool->size - tipool->in_use) > tipool->cfg->max_spare);
339-
max_requests = ((num_requests > 0) &&
340-
(num_requests > tipool->cfg->max_requests));
341-
342332
/* XXX: this management should probably be happening elsewhere
343333
* like in a thread spawned at startup
344334
*/
345335
MANAGE_POOL:
346-
while (tipool->size < tipool->cfg->max && tipool->size - tipool->in_use < tipool->cfg->min_spare) {
347-
if (tipool->func->tipool_rgrow) {
336+
if (tipool->func->tipool_destroy) {
337+
while (tipool->size - tipool->in_use > tipool->cfg->max_spare) {
338+
if (tipool->idle && tipool->idle->next) {
339+
MP_TRACE_i(MP_FUNC,
340+
"shrinking pool: max_spare=%d, %d of %d in use",
341+
tipool->cfg->max_spare, tipool->in_use,
342+
tipool->size);
343+
listp = modperl_list_last(tipool->idle->next);
344+
if (listp) {
345+
modperl_tipool_remove(tipool, listp);
346+
(*tipool->func->tipool_destroy)(tipool, tipool->data, listp->data);
347+
}
348+
}
349+
else
350+
break;
351+
}
352+
}
353+
if (tipool->func->tipool_rgrow) {
354+
while (tipool->size < tipool->cfg->max && tipool->size - tipool->in_use < tipool->cfg->min_spare) {
348355
MP_TRACE_i(MP_FUNC,
349356
"growing pool: min_spare=%d, %d of %d in use",
350357
tipool->cfg->min_spare, tipool->in_use,
351358
tipool->size);
352359
void *item =
353360
(*tipool->func->tipool_rgrow)(tipool,
354361
tipool->data);
355-
modperl_tipool_lock(tipool);
356362
modperl_tipool_add(tipool, item);
357363
modperl_tipool_signal(tipool);
358-
modperl_tipool_unlock(tipool);
359-
}
360-
}
361-
while (tipool->size - tipool->in_use > tipool->cfg->max_spare) {
362-
if (tipool->func->tipool_destroy) {
363-
MP_TRACE_i(MP_FUNC,
364-
"shrinking pool: max_spare=%d, %d of %d in use",
365-
tipool->cfg->max_spare, tipool->in_use,
366-
tipool->size);
367-
modperl_tipool_lock(tipool);
368-
if (tipool->idle) {
369-
listp = modperl_list_last(tipool->idle);
370-
modperl_tipool_remove(tipool, listp);
371-
(*tipool->func->tipool_destroy)(tipool, tipool->data, listp->data);
372-
}
373-
modperl_tipool_unlock(tipool);
364+
374365
}
375366
}
367+
modperl_tipool_unlock(tipool);
376368
}
377369

378370
/* _data functions are so structures (e.g. modperl_interp_t) don't

src/modules/perl/modperl_tipool.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ void modperl_tipool_putback(modperl_tipool_t *tipool,
6060
void modperl_tipool_putback_data(modperl_tipool_t *tipool, void *data,
6161
int num_requests);
6262

63-
#define modperl_tipool_wait(tipool) \
63+
#define modperl_tipool_wait(tipool) do { \
6464
MP_TRACE_i(MP_FUNC, \
6565
"waiting for available tipool item in thread 0x%lx", \
6666
MP_TIDF); \
6767
MP_TRACE_i(MP_FUNC, "(%d items in use, %d alive)", \
6868
tipool->in_use, tipool->size); \
6969
COND_WAIT(&tipool->available, &tipool->tiplock); \
70-
70+
} while (0)
7171
#define modperl_tipool_signal(tipool) \
7272
MP_TRACE_i(MP_FUNC, "signal available tipool item"); \
7373
COND_SIGNAL(&tipool->available)

0 commit comments

Comments
 (0)