nxt_runtime.c (125:5cc5002a788e) nxt_runtime.c (128:cfa3a5ce7f2f)
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>

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

1517{
1518 nxt_lvlhsh_query_t lhq;
1519
1520 lhq.key_hash = nxt_murmur_hash2(&pid, sizeof(pid));
1521 lhq.key.length = sizeof(pid);
1522 lhq.key.start = (u_char *) &pid;
1523 lhq.proto = &lvlhsh_processes_proto;
1524
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>

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

1517{
1518 nxt_lvlhsh_query_t lhq;
1519
1520 lhq.key_hash = nxt_murmur_hash2(&pid, sizeof(pid));
1521 lhq.key.length = sizeof(pid);
1522 lhq.key.start = (u_char *) &pid;
1523 lhq.proto = &lvlhsh_processes_proto;
1524
1525 /* TODO lock processes */
1526
1527 if (nxt_lvlhsh_find(&rt->processes, &lhq) == NXT_OK) {
1528 nxt_thread_log_debug("process %PI found", pid);
1529 return lhq.value;
1530 }
1531
1532 nxt_thread_log_debug("process %PI not found", pid);
1533
1534 return NULL;

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

1541 nxt_process_t *process;
1542 nxt_lvlhsh_query_t lhq;
1543
1544 lhq.key_hash = nxt_murmur_hash2(&pid, sizeof(pid));
1545 lhq.key.length = sizeof(pid);
1546 lhq.key.start = (u_char *) &pid;
1547 lhq.proto = &lvlhsh_processes_proto;
1548
1525 if (nxt_lvlhsh_find(&rt->processes, &lhq) == NXT_OK) {
1526 nxt_thread_log_debug("process %PI found", pid);
1527 return lhq.value;
1528 }
1529
1530 nxt_thread_log_debug("process %PI not found", pid);
1531
1532 return NULL;

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

1539 nxt_process_t *process;
1540 nxt_lvlhsh_query_t lhq;
1541
1542 lhq.key_hash = nxt_murmur_hash2(&pid, sizeof(pid));
1543 lhq.key.length = sizeof(pid);
1544 lhq.key.start = (u_char *) &pid;
1545 lhq.proto = &lvlhsh_processes_proto;
1546
1549 /* TODO lock processes */
1550
1551 if (nxt_lvlhsh_find(&rt->processes, &lhq) == NXT_OK) {
1552 nxt_thread_log_debug("process %PI found", pid);
1553 return lhq.value;
1554 }
1555
1556 process = nxt_runtime_process_new(rt);
1557 if (nxt_slow_path(process == NULL)) {
1558 return NULL;

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

1594 lhq.key_hash = nxt_murmur_hash2(&process->pid, sizeof(process->pid));
1595 lhq.key.length = sizeof(process->pid);
1596 lhq.key.start = (u_char *) &process->pid;
1597 lhq.proto = &lvlhsh_processes_proto;
1598 lhq.replace = 0;
1599 lhq.value = process;
1600 lhq.pool = rt->mem_pool;
1601
1547 if (nxt_lvlhsh_find(&rt->processes, &lhq) == NXT_OK) {
1548 nxt_thread_log_debug("process %PI found", pid);
1549 return lhq.value;
1550 }
1551
1552 process = nxt_runtime_process_new(rt);
1553 if (nxt_slow_path(process == NULL)) {
1554 return NULL;

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

1590 lhq.key_hash = nxt_murmur_hash2(&process->pid, sizeof(process->pid));
1591 lhq.key.length = sizeof(process->pid);
1592 lhq.key.start = (u_char *) &process->pid;
1593 lhq.proto = &lvlhsh_processes_proto;
1594 lhq.replace = 0;
1595 lhq.value = process;
1596 lhq.pool = rt->mem_pool;
1597
1602 /* TODO lock processes */
1603
1604 switch (nxt_lvlhsh_insert(&rt->processes, &lhq)) {
1605
1606 case NXT_OK:
1607 if (rt->nprocesses == 0) {
1608 rt->mprocess = process;
1609 }
1610
1611 rt->nprocesses++;

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

1622 break;
1623 }
1624}
1625
1626
1627void
1628nxt_runtime_process_remove(nxt_runtime_t *rt, nxt_process_t *process)
1629{
1598 switch (nxt_lvlhsh_insert(&rt->processes, &lhq)) {
1599
1600 case NXT_OK:
1601 if (rt->nprocesses == 0) {
1602 rt->mprocess = process;
1603 }
1604
1605 rt->nprocesses++;

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

1616 break;
1617 }
1618}
1619
1620
1621void
1622nxt_runtime_process_remove(nxt_runtime_t *rt, nxt_process_t *process)
1623{
1624 uint32_t i;
1630 nxt_port_t *port;
1625 nxt_port_t *port;
1626 nxt_port_mmap_t *port_mmap;
1631 nxt_lvlhsh_query_t lhq;
1632
1633 lhq.key_hash = nxt_murmur_hash2(&process->pid, sizeof(process->pid));
1634 lhq.key.length = sizeof(process->pid);
1635 lhq.key.start = (u_char *) &process->pid;
1636 lhq.proto = &lvlhsh_processes_proto;
1637 lhq.replace = 0;
1638 lhq.value = process;
1639 lhq.pool = rt->mem_pool;
1640
1627 nxt_lvlhsh_query_t lhq;
1628
1629 lhq.key_hash = nxt_murmur_hash2(&process->pid, sizeof(process->pid));
1630 lhq.key.length = sizeof(process->pid);
1631 lhq.key.start = (u_char *) &process->pid;
1632 lhq.proto = &lvlhsh_processes_proto;
1633 lhq.replace = 0;
1634 lhq.value = process;
1635 lhq.pool = rt->mem_pool;
1636
1641 /* TODO lock processes */
1642
1643 switch (nxt_lvlhsh_delete(&rt->processes, &lhq)) {
1644
1645 case NXT_OK:
1646 rt->nprocesses--;
1647
1648 nxt_process_port_each(process, port) {
1649
1650 nxt_runtime_port_remove(rt, port);
1651
1652 } nxt_process_port_loop;
1653
1637 switch (nxt_lvlhsh_delete(&rt->processes, &lhq)) {
1638
1639 case NXT_OK:
1640 rt->nprocesses--;
1641
1642 nxt_process_port_each(process, port) {
1643
1644 nxt_runtime_port_remove(rt, port);
1645
1646 } nxt_process_port_loop;
1647
1648 if (process->incoming) {
1649 nxt_mp_thread_adopt(process->incoming_mp);
1650
1651 port_mmap = process->incoming->elts;
1652
1653 for (i = 0; i < process->incoming->nelts; i++) {
1654 nxt_port_mmap_destroy(port_mmap);
1655 }
1656
1657 nxt_thread_mutex_destroy(&process->incoming_mutex);
1658
1659 nxt_mp_destroy(process->incoming_mp);
1660 }
1661
1662 if (process->outgoing) {
1663 nxt_mp_thread_adopt(process->outgoing_mp);
1664
1665 port_mmap = process->outgoing->elts;
1666
1667 for (i = 0; i < process->outgoing->nelts; i++) {
1668 nxt_port_mmap_destroy(port_mmap);
1669 }
1670
1671 nxt_thread_mutex_destroy(&process->outgoing_mutex);
1672
1673 nxt_mp_destroy(process->outgoing_mp);
1674 }
1675
1654 nxt_mp_free(rt->mem_pool, process);
1655 break;
1656
1657 default:
1658 break;
1659 }
1660}
1661

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

1676{
1677 return nxt_port_hash_first(&rt->ports, lhe);
1678}
1679
1680
1681void
1682nxt_runtime_port_add(nxt_runtime_t *rt, nxt_port_t *port)
1683{
1676 nxt_mp_free(rt->mem_pool, process);
1677 break;
1678
1679 default:
1680 break;
1681 }
1682}
1683

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

1698{
1699 return nxt_port_hash_first(&rt->ports, lhe);
1700}
1701
1702
1703void
1704nxt_runtime_port_add(nxt_runtime_t *rt, nxt_port_t *port)
1705{
1684 /* TODO lock ports */
1685
1686 nxt_port_hash_add(&rt->ports, rt->mem_pool, port);
1687}
1688
1689
1690void
1691nxt_runtime_port_remove(nxt_runtime_t *rt, nxt_port_t *port)
1692{
1706 nxt_port_hash_add(&rt->ports, rt->mem_pool, port);
1707}
1708
1709
1710void
1711nxt_runtime_port_remove(nxt_runtime_t *rt, nxt_port_t *port)
1712{
1693 /* TODO lock ports */
1694
1695 nxt_port_hash_remove(&rt->ports, rt->mem_pool, port);
1696
1697 if (port->pair[0] != -1) {
1698 nxt_fd_close(port->pair[0]);
1699 }
1700
1701 if (port->pair[1] != -1) {
1702 nxt_fd_close(port->pair[1]);

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

1709 nxt_mp_free(port->process->mem_pool, port);
1710}
1711
1712
1713nxt_port_t *
1714nxt_runtime_port_find(nxt_runtime_t *rt, nxt_pid_t pid,
1715 nxt_port_id_t port_id)
1716{
1713 nxt_port_hash_remove(&rt->ports, rt->mem_pool, port);
1714
1715 if (port->pair[0] != -1) {
1716 nxt_fd_close(port->pair[0]);
1717 }
1718
1719 if (port->pair[1] != -1) {
1720 nxt_fd_close(port->pair[1]);

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

1727 nxt_mp_free(port->process->mem_pool, port);
1728}
1729
1730
1731nxt_port_t *
1732nxt_runtime_port_find(nxt_runtime_t *rt, nxt_pid_t pid,
1733 nxt_port_id_t port_id)
1734{
1717 /* TODO lock ports */
1718
1719 return nxt_port_hash_find(&rt->ports, pid, port_id);
1720}
1735 return nxt_port_hash_find(&rt->ports, pid, port_id);
1736}