Deleted Added
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
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{
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);
1700}
1701
1702
1703void
1704nxt_runtime_port_add(nxt_runtime_t *rt, nxt_port_t *port)
1705{
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
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 }
1732}
1733
1734
1735void
1736nxt_runtime_port_remove(nxt_runtime_t *rt, nxt_port_t *port)
1737{
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
1754 switch (nxt_lvlhsh_delete(&rt->ports, &lhq)) {
1755
1756 case NXT_OK:
1757 break;
1758
1759 default:
1760 break;
1761 }
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{
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
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;
1790}