xref: /unit/src/nxt_port_memory.h (revision 1662:1472957bc7bd)
1 
2 /*
3  * Copyright (C) Max Romanov
4  * Copyright (C) NGINX, Inc.
5  */
6 
7 #ifndef _NXT_PORT_MEMORY_H_INCLUDED_
8 #define _NXT_PORT_MEMORY_H_INCLUDED_
9 
10 
11 #define PORT_MMAP_MIN_SIZE (3 * sizeof(uint32_t))
12 
13 typedef struct nxt_port_mmap_header_s nxt_port_mmap_header_t;
14 typedef struct nxt_port_mmap_handler_s nxt_port_mmap_handler_t;
15 
16 void nxt_port_mmaps_destroy(nxt_port_mmaps_t *port_mmaps, nxt_bool_t free_elts);
17 
18 typedef struct nxt_port_mmap_tracking_s nxt_port_mmap_tracking_t;
19 
20 struct nxt_port_mmap_tracking_s {
21     void                *mmap_handler;
22     nxt_atomic_t        *tracking;
23 };
24 
25 nxt_int_t
26 nxt_port_mmap_get_tracking(nxt_task_t *task, nxt_port_mmaps_t *mmaps,
27     nxt_port_mmap_tracking_t *tracking, uint32_t stream);
28 
29 nxt_bool_t
30 nxt_port_mmap_tracking_cancel(nxt_task_t *task,
31     nxt_port_mmap_tracking_t *tracking, uint32_t stream);
32 
33 nxt_int_t
34 nxt_port_mmap_tracking_write(uint32_t *buf, nxt_port_mmap_tracking_t *t);
35 
36 nxt_bool_t
37 nxt_port_mmap_tracking_read(nxt_task_t *task, nxt_port_recv_msg_t *msg);
38 
39 /*
40  * Allocates nxt_but_t structure from task's thread engine mem_pool, assigns
41  * this buf 'mem' pointers to first available shared mem bucket(s). 'size'
42  * used as a hint to acquire several successive buckets if possible.
43  */
44 nxt_buf_t *
45 nxt_port_mmap_get_buf(nxt_task_t *task, nxt_port_mmaps_t *mmaps, size_t size);
46 
47 nxt_int_t nxt_port_mmap_increase_buf(nxt_task_t *task, nxt_buf_t *b,
48     size_t size, size_t min_size);
49 
50 nxt_port_mmap_handler_t *
51 nxt_port_incoming_port_mmap(nxt_task_t *task, nxt_process_t *process,
52     nxt_fd_t fd);
53 
54 void
55 nxt_port_mmap_write(nxt_task_t *task, nxt_port_t *port,
56     nxt_port_send_msg_t *msg, nxt_sendbuf_coalesce_t *sb, void *mmsg_buf);
57 
58 void
59 nxt_port_mmap_read(nxt_task_t *task, nxt_port_recv_msg_t *msg);
60 
61 enum nxt_port_method_e {
62     NXT_PORT_METHOD_ANY = 0,
63     NXT_PORT_METHOD_PLAIN,
64     NXT_PORT_METHOD_MMAP
65 };
66 
67 typedef enum nxt_port_method_e nxt_port_method_t;
68 
69 nxt_port_method_t
70 nxt_port_mmap_get_method(nxt_task_t *task, nxt_port_t *port, nxt_buf_t *b);
71 
72 nxt_int_t nxt_shm_open(nxt_task_t *task, size_t size);
73 
74 void nxt_process_broadcast_shm_ack(nxt_task_t *task, nxt_process_t *process);
75 
76 #endif /* _NXT_PORT_MEMORY_H_INCLUDED_ */
77