summaryrefslogtreecommitdiffstats
path: root/man3/nxt_unit_ctx_alloc.3
blob: d00db9e6da0aeb8b0ddb58b2848d3c90a8ac0b22 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
.\" (C) 2023, NGINX, Inc.
.\"
.TH nxt_unit_ctx_alloc 3 (date) "NGINX Unit (unreleased)"
.SH Name
nxt_unit_ctx_alloc \- create context object for Unit app thread
.SH Library
NGINX Unit library
.RI ( libunit ", " -lunit )
.SH Synopsis
.nf
.B #include <nxt_unit.h>
.PP
.B [[gnu::malloc(nxt_unit_done)]]
.BI "nxt_unit_ctx_t *_Nullable nxt_unit_ctx_alloc(nxt_unit_ctx_t *" ctx ,
.BI "                                             void *_Nullable " data );
.fi
.SH Arguments
.TP
.I ctx
Main context object for the application.
It should have been created with
.MR nxt_unit_init 3 .
.TP
.I data
XXX
.SH Description
.MR nxt_unit_ctx_alloc 3
creates a context object that will be used for a worker thread.
.PP
The next step after creating a thread context object
is running the application thread;
for that, see
.MR nxt_unit_run 3 .
.PP
The context object created by this function should be
destroyed by passing it to
.MR nxt_unit_done 3 .
.SH Return value
A pointer to a context object on success,
or NULL on error.
.SH Errors
Errors will be reported in the Unit debug log.
.IP \[bu] 3
.MR pthread_mutex_init 3
failed.
.PD 0
.IP \[bu]
.MR socketpair 2
failed.
.IP \[bu]
.MR setsockopt 2
failed.
.IP \[bu]
.MR memfd_create 2
failed.
.IP \[bu]
.MR shm_open 2
failed.
.IP \[bu]
.MR ftruncate 2
failed.
.IP \[bu]
.MR mmap 2
failed.
.IP \[bu]
.MR sendmsg 2
failed.
.IP \[bu]
.MR nxt_unit_malloc 3
failed.
.IP \[bu]
.I nxt_unit_init_t::callbacks.port_send
failed.
.IP \[bu]
Internal hash table failure.
.PD
.SH Examples
See
.MR nxt_unit_init 3
for an example where this
.IR worker ()
function is used.
.PP
.EX
#include <pthread.h>
#include <stddef.h>
#include <stdint.h>
\&
#include <nxt_unit.h>
\&
void *
worker(void *main_ctx)
{
    int             rc;
    nxt_unit_ctx_t  *ctx;
\&
    ctx = nxt_unit_ctx_alloc(main_ctx, NULL);
    if (ctx == NULL) {
        pthread_exit(NULL);
    }
\&
    nxt_unit_debug(ctx, "start worker");
    rc = nxt_unit_run(ctx);
    nxt_unit_debug(ctx, "worker finished with %d code", rc);
\&
    nxt_unit_done(ctx);
\&
    pthread_exit((void *) (intptr_t) rc);
}
.EE
.SH Copyright
(C) 2017-2023, NGINX, Inc.
.PP
SPDX-License-Identifier: Apache-2.0
.SH See also
.MR nxt_unit_done 3 ,
.MR nxt_unit_run 3 ,
.MR pthread_create 3 ,
.MR pthread_exit 3 ,
.MR unitd 8
.PP
Website
.UR https://unit.nginx.org
.UE
.PP
Mailing list
.UR https://mailman.nginx.org/mailman/listinfo/unit
.UE
.PP
GitHub
.UR https://github.com/nginx/unit
.UE