nxt_runtime.c (1253:b225cd619dbb) nxt_runtime.c (1254:aae6699f4eee)
1
2/*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) Valentin V. Bartenev
5 * Copyright (C) NGINX, Inc.
6 */
7
8#include <nxt_main.h>

--- 23 unchanged lines hidden (view full) ---

32 nxt_runtime_t *rt);
33static nxt_int_t nxt_runtime_pid_file_create(nxt_task_t *task,
34 nxt_file_name_t *pid_file);
35static void nxt_runtime_thread_pool_destroy(nxt_task_t *task, nxt_runtime_t *rt,
36 nxt_runtime_cont_t cont);
37static void nxt_runtime_thread_pool_init(void);
38static void nxt_runtime_thread_pool_exit(nxt_task_t *task, void *obj,
39 void *data);
1
2/*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) Valentin V. Bartenev
5 * Copyright (C) NGINX, Inc.
6 */
7
8#include <nxt_main.h>

--- 23 unchanged lines hidden (view full) ---

32 nxt_runtime_t *rt);
33static nxt_int_t nxt_runtime_pid_file_create(nxt_task_t *task,
34 nxt_file_name_t *pid_file);
35static void nxt_runtime_thread_pool_destroy(nxt_task_t *task, nxt_runtime_t *rt,
36 nxt_runtime_cont_t cont);
37static void nxt_runtime_thread_pool_init(void);
38static void nxt_runtime_thread_pool_exit(nxt_task_t *task, void *obj,
39 void *data);
40static void nxt_runtime_process_destroy(nxt_runtime_t *rt,
40static nxt_process_t *nxt_runtime_process_get(nxt_runtime_t *rt, nxt_pid_t pid);
41static void nxt_runtime_process_remove(nxt_runtime_t *rt,
41 nxt_process_t *process);
42 nxt_process_t *process);
42static nxt_process_t *nxt_runtime_process_remove_pid(nxt_runtime_t *rt,
43 nxt_pid_t pid);
43static void nxt_runtime_port_add(nxt_task_t *task, nxt_port_t *port);
44
45
46nxt_int_t
47nxt_runtime_create(nxt_task_t *task)
48{
49 nxt_mp_t *mp;
50 nxt_int_t ret;
51 nxt_array_t *listen_sockets;

--- 1241 unchanged lines hidden (view full) ---

1293 nxt_thread_mutex_create(&process->cp_mutex);
1294
1295 process->use_count = 1;
1296
1297 return process;
1298}
1299
1300
44
45
46nxt_int_t
47nxt_runtime_create(nxt_task_t *task)
48{
49 nxt_mp_t *mp;
50 nxt_int_t ret;
51 nxt_array_t *listen_sockets;

--- 1241 unchanged lines hidden (view full) ---

1293 nxt_thread_mutex_create(&process->cp_mutex);
1294
1295 process->use_count = 1;
1296
1297 return process;
1298}
1299
1300
1301static void
1302nxt_runtime_process_destroy(nxt_runtime_t *rt, nxt_process_t *process)
1301void
1302nxt_runtime_process_release(nxt_runtime_t *rt, nxt_process_t *process)
1303{
1304 nxt_port_t *port;
1305
1303{
1304 nxt_port_t *port;
1305
1306 if (process->registered == 1) {
1307 nxt_runtime_process_remove(rt, process);
1308 }
1309
1306 nxt_assert(process->use_count == 0);
1307 nxt_assert(process->registered == 0);
1308
1309 nxt_port_mmaps_destroy(&process->incoming, 1);
1310 nxt_port_mmaps_destroy(&process->outgoing, 1);
1311
1312 do {
1313 port = nxt_port_hash_retrieve(&process->connected_ports);

--- 66 unchanged lines hidden (view full) ---

1380 }
1381
1382 nxt_thread_mutex_unlock(&rt->processes_mutex);
1383
1384 return process;
1385}
1386
1387
1310 nxt_assert(process->use_count == 0);
1311 nxt_assert(process->registered == 0);
1312
1313 nxt_port_mmaps_destroy(&process->incoming, 1);
1314 nxt_port_mmaps_destroy(&process->outgoing, 1);
1315
1316 do {
1317 port = nxt_port_hash_retrieve(&process->connected_ports);

--- 66 unchanged lines hidden (view full) ---

1384 }
1385
1386 nxt_thread_mutex_unlock(&rt->processes_mutex);
1387
1388 return process;
1389}
1390
1391
1388nxt_process_t *
1392static nxt_process_t *
1389nxt_runtime_process_get(nxt_runtime_t *rt, nxt_pid_t pid)
1390{
1391 nxt_process_t *process;
1392 nxt_lvlhsh_query_t lhq;
1393
1394 nxt_runtime_process_lhq_pid(&lhq, &pid);
1395
1396 nxt_thread_mutex_lock(&rt->processes_mutex);

--- 93 unchanged lines hidden (view full) ---

1490 nxt_thread_log_debug("process %PI failed to add", process->pid);
1491 break;
1492 }
1493
1494 nxt_thread_mutex_unlock(&rt->processes_mutex);
1495}
1496
1497
1393nxt_runtime_process_get(nxt_runtime_t *rt, nxt_pid_t pid)
1394{
1395 nxt_process_t *process;
1396 nxt_lvlhsh_query_t lhq;
1397
1398 nxt_runtime_process_lhq_pid(&lhq, &pid);
1399
1400 nxt_thread_mutex_lock(&rt->processes_mutex);

--- 93 unchanged lines hidden (view full) ---

1494 nxt_thread_log_debug("process %PI failed to add", process->pid);
1495 break;
1496 }
1497
1498 nxt_thread_mutex_unlock(&rt->processes_mutex);
1499}
1500
1501
1498static nxt_process_t *
1499nxt_runtime_process_remove_pid(nxt_runtime_t *rt, nxt_pid_t pid)
1502static void
1503nxt_runtime_process_remove(nxt_runtime_t *rt, nxt_process_t *process)
1500{
1504{
1501 nxt_process_t *process;
1505 nxt_pid_t pid;
1502 nxt_lvlhsh_query_t lhq;
1503
1506 nxt_lvlhsh_query_t lhq;
1507
1504 process = NULL;
1508 pid = process->pid;
1505
1506 nxt_runtime_process_lhq_pid(&lhq, &pid);
1507
1508 lhq.pool = rt->mem_pool;
1509
1510 nxt_thread_mutex_lock(&rt->processes_mutex);
1511
1512 switch (nxt_lvlhsh_delete(&rt->processes, &lhq)) {

--- 9 unchanged lines hidden (view full) ---

1522 break;
1523
1524 default:
1525 nxt_thread_log_debug("process %PI remove failed", pid);
1526 break;
1527 }
1528
1529 nxt_thread_mutex_unlock(&rt->processes_mutex);
1509
1510 nxt_runtime_process_lhq_pid(&lhq, &pid);
1511
1512 lhq.pool = rt->mem_pool;
1513
1514 nxt_thread_mutex_lock(&rt->processes_mutex);
1515
1516 switch (nxt_lvlhsh_delete(&rt->processes, &lhq)) {

--- 9 unchanged lines hidden (view full) ---

1526 break;
1527
1528 default:
1529 nxt_thread_log_debug("process %PI remove failed", pid);
1530 break;
1531 }
1532
1533 nxt_thread_mutex_unlock(&rt->processes_mutex);
1530
1531 return process;
1532}
1533
1534
1534}
1535
1536
1535void
1536nxt_process_use(nxt_task_t *task, nxt_process_t *process, int i)
1537nxt_process_t *
1538nxt_runtime_process_first(nxt_runtime_t *rt, nxt_lvlhsh_each_t *lhe)
1537{
1539{
1538 nxt_runtime_t *rt;
1540 nxt_lvlhsh_each_init(lhe, &lvlhsh_processes_proto);
1539
1541
1540 process->use_count += i;
1542 return nxt_runtime_process_next(rt, lhe);
1543}
1541
1544
1542 if (process->use_count == 0) {
1543 rt = task->thread->runtime;
1544
1545
1545 if (process->registered == 1) {
1546 nxt_runtime_process_remove_pid(rt, process->pid);
1547 }
1546nxt_port_t *
1547nxt_runtime_process_port_create(nxt_task_t *task, nxt_runtime_t *rt,
1548 nxt_pid_t pid, nxt_port_id_t id, nxt_process_type_t type)
1549{
1550 nxt_port_t *port;
1551 nxt_process_t *process;
1548
1552
1549 nxt_runtime_process_destroy(rt, process);
1553 process = nxt_runtime_process_get(rt, pid);
1554 if (nxt_slow_path(process == NULL)) {
1555 return NULL;
1550 }
1556 }
1551}
1552
1557
1558 port = nxt_port_new(task, id, pid, type);
1559 if (nxt_slow_path(port == NULL)) {
1560 nxt_process_use(task, process, -1);
1561 return NULL;
1562 }
1553
1563
1554nxt_process_t *
1555nxt_runtime_process_first(nxt_runtime_t *rt, nxt_lvlhsh_each_t *lhe)
1556{
1557 nxt_lvlhsh_each_init(lhe, &lvlhsh_processes_proto);
1564 nxt_process_port_add(task, process, port);
1558
1565
1559 return nxt_runtime_process_next(rt, lhe);
1566 nxt_process_use(task, process, -1);
1567
1568 nxt_runtime_port_add(task, port);
1569
1570 nxt_port_use(task, port, -1);
1571
1572 return port;
1560}
1561
1562
1573}
1574
1575
1563void
1576static void
1564nxt_runtime_port_add(nxt_task_t *task, nxt_port_t *port)
1565{
1566 nxt_int_t res;
1567 nxt_runtime_t *rt;
1568
1569 rt = task->thread->runtime;
1570
1571 res = nxt_port_hash_add(&rt->ports, port);

--- 39 unchanged lines hidden ---
1577nxt_runtime_port_add(nxt_task_t *task, nxt_port_t *port)
1578{
1579 nxt_int_t res;
1580 nxt_runtime_t *rt;
1581
1582 rt = task->thread->runtime;
1583
1584 res = nxt_port_hash_add(&rt->ports, port);

--- 39 unchanged lines hidden ---