nxt_runtime.c (74:0d59ae8c7cfa) nxt_runtime.c (75:63205c12a84b)
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>

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

1494
1495static const nxt_lvlhsh_proto_t lvlhsh_processes_proto nxt_aligned(64) = {
1496 NXT_LVLHSH_DEFAULT,
1497 nxt_runtime_lvlhsh_pid_test,
1498 nxt_lvlhsh_alloc,
1499 nxt_lvlhsh_free,
1500};
1501
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>

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

1494
1495static const nxt_lvlhsh_proto_t lvlhsh_processes_proto nxt_aligned(64) = {
1496 NXT_LVLHSH_DEFAULT,
1497 nxt_runtime_lvlhsh_pid_test,
1498 nxt_lvlhsh_alloc,
1499 nxt_lvlhsh_free,
1500};
1501
1502// Explicitly using 32 bit types to avoid possible alignment.
1503typedef struct {
1504 int32_t pid;
1505 uint32_t port_id;
1506} nxt_pid_port_id_t;
1507
1502
1508static nxt_int_t
1509nxt_runtime_lvlhsh_port_test(nxt_lvlhsh_query_t *lhq, void *data)
1510{
1511 nxt_port_t *port;
1512 nxt_pid_port_id_t *pid_port_id;
1513
1514 port = data;
1515 pid_port_id = (nxt_pid_port_id_t *) lhq->key.start;
1516
1517 if (lhq->key.length == sizeof(nxt_pid_port_id_t) &&
1518 pid_port_id->pid == port->pid &&
1519 pid_port_id->port_id == port->id) {
1520 return NXT_OK;
1521 }
1522
1523 return NXT_DECLINED;
1524}
1525
1526static const nxt_lvlhsh_proto_t lvlhsh_ports_proto nxt_aligned(64) = {
1527 NXT_LVLHSH_DEFAULT,
1528 nxt_runtime_lvlhsh_port_test,
1529 nxt_lvlhsh_alloc,
1530 nxt_lvlhsh_free,
1531};
1532
1533
1534nxt_process_t *
1535nxt_runtime_process_find(nxt_runtime_t *rt, nxt_pid_t pid)
1536{
1537 nxt_lvlhsh_query_t lhq;
1538
1539 lhq.key_hash = nxt_murmur_hash2(&pid, sizeof(pid));
1540 lhq.key.length = sizeof(pid);
1541 lhq.key.start = (u_char *) &pid;

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

1687
1688 return nxt_runtime_process_next(rt, lhe);
1689}
1690
1691
1692nxt_port_t *
1693nxt_runtime_port_first(nxt_runtime_t *rt, nxt_lvlhsh_each_t *lhe)
1694{
1503nxt_process_t *
1504nxt_runtime_process_find(nxt_runtime_t *rt, nxt_pid_t pid)
1505{
1506 nxt_lvlhsh_query_t lhq;
1507
1508 lhq.key_hash = nxt_murmur_hash2(&pid, sizeof(pid));
1509 lhq.key.length = sizeof(pid);
1510 lhq.key.start = (u_char *) &pid;

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

1656
1657 return nxt_runtime_process_next(rt, lhe);
1658}
1659
1660
1661nxt_port_t *
1662nxt_runtime_port_first(nxt_runtime_t *rt, nxt_lvlhsh_each_t *lhe)
1663{
1695 nxt_memzero(lhe, sizeof(nxt_lvlhsh_each_t));
1696
1697 lhe->proto = &lvlhsh_ports_proto;
1698
1699 return nxt_runtime_port_next(rt, lhe);
1664 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{
1665}
1666
1667
1668void
1669nxt_runtime_port_add(nxt_runtime_t *rt, nxt_port_t *port)
1670{
1706 nxt_pid_port_id_t pid_port;
1707 nxt_lvlhsh_query_t lhq;
1708
1709 pid_port.pid = port->pid;
1710 pid_port.port_id = port->id;
1711
1712 lhq.key_hash = nxt_murmur_hash2(&pid_port, sizeof(pid_port));
1713 lhq.key.length = sizeof(pid_port);
1714 lhq.key.start = (u_char *) &pid_port;
1715 lhq.proto = &lvlhsh_ports_proto;
1716 lhq.replace = 0;
1717 lhq.value = port;
1718 lhq.pool = rt->mem_pool;
1719
1720 /* TODO lock ports */
1721
1671 /* TODO lock ports */
1672
1722 switch (nxt_lvlhsh_insert(&rt->ports, &lhq)) {
1723
1724 case NXT_OK:
1725 break;
1726
1727 default:
1728 nxt_thread_log_error(NXT_LOG_WARN, "port #%d for pid %PI add failed",
1729 port->id, port->pid);
1730 break;
1731 }
1673 nxt_port_hash_add(&rt->ports, rt->mem_pool, port);
1732}
1733
1734
1735void
1736nxt_runtime_port_remove(nxt_runtime_t *rt, nxt_port_t *port)
1737{
1674}
1675
1676
1677void
1678nxt_runtime_port_remove(nxt_runtime_t *rt, nxt_port_t *port)
1679{
1738 nxt_pid_port_id_t pid_port;
1739 nxt_lvlhsh_query_t lhq;
1740
1741 pid_port.pid = port->pid;
1742 pid_port.port_id = port->id;
1743
1744 lhq.key_hash = nxt_murmur_hash2(&pid_port, sizeof(pid_port));
1745 lhq.key.length = sizeof(pid_port);
1746 lhq.key.start = (u_char *) &pid_port;
1747 lhq.proto = &lvlhsh_ports_proto;
1748 lhq.replace = 0;
1749 lhq.value = port;
1750 lhq.pool = rt->mem_pool;
1751
1752 /* TODO lock ports */
1753
1680 /* TODO lock ports */
1681
1754 switch (nxt_lvlhsh_delete(&rt->ports, &lhq)) {
1755
1756 case NXT_OK:
1757 break;
1758
1759 default:
1760 break;
1761 }
1682 nxt_port_hash_remove(&rt->ports, rt->mem_pool, port);
1762}
1763
1764
1765nxt_port_t *
1766nxt_runtime_port_find(nxt_runtime_t *rt, nxt_pid_t pid,
1767 nxt_port_id_t port_id)
1768{
1683}
1684
1685
1686nxt_port_t *
1687nxt_runtime_port_find(nxt_runtime_t *rt, nxt_pid_t pid,
1688 nxt_port_id_t port_id)
1689{
1769 nxt_pid_port_id_t pid_port;
1770 nxt_lvlhsh_query_t lhq;
1771
1772 pid_port.pid = pid;
1773 pid_port.port_id = port_id;
1774
1775 lhq.key_hash = nxt_murmur_hash2(&pid_port, sizeof(pid_port));
1776 lhq.key.length = sizeof(pid_port);
1777 lhq.key.start = (u_char *) &pid_port;
1778 lhq.proto = &lvlhsh_ports_proto;
1779
1780 /* TODO lock ports */
1781
1690 /* TODO lock ports */
1691
1782 if (nxt_lvlhsh_find(&rt->ports, &lhq) == NXT_OK) {
1783 nxt_thread_log_debug("process port (%PI, %d) found", pid, port_id);
1784 return lhq.value;
1785 }
1786
1787 nxt_thread_log_debug("process port (%PI, %d) not found", pid, port_id);
1788
1789 return NULL;
1692 return nxt_port_hash_find(&rt->ports, pid, port_id);
1790}
1693}