/src/fluent-bit/lib/monkey/mk_server/mk_cache.c
Line | Count | Source |
1 | | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | |
3 | | /* Monkey HTTP Server |
4 | | * ================== |
5 | | * Copyright 2001-2017 Eduardo Silva <eduardo@monkey.io> |
6 | | * |
7 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
8 | | * you may not use this file except in compliance with the License. |
9 | | * You may obtain a copy of the License at |
10 | | * |
11 | | * http://www.apache.org/licenses/LICENSE-2.0 |
12 | | * |
13 | | * Unless required by applicable law or agreed to in writing, software |
14 | | * distributed under the License is distributed on an "AS IS" BASIS, |
15 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | | * See the License for the specific language governing permissions and |
17 | | * limitations under the License. |
18 | | */ |
19 | | |
20 | | #define _GNU_SOURCE |
21 | | |
22 | | #include <monkey/mk_core.h> |
23 | | #include <monkey/mk_cache.h> |
24 | | #include <monkey/mk_cache_tls.h> |
25 | | #include <monkey/mk_config.h> |
26 | | #include <monkey/mk_utils.h> |
27 | | #include <monkey/mk_vhost.h> |
28 | | #include <monkey/mk_tls.h> |
29 | | |
30 | | /* This function is called when a thread is created */ |
31 | | void mk_cache_worker_init() |
32 | 0 | { |
33 | 0 | char *cache_error; |
34 | 0 | mk_ptr_t *p_tmp; |
35 | | |
36 | | /* Cache header request -> last modified */ |
37 | 0 | p_tmp = mk_mem_alloc_z(sizeof(mk_ptr_t)); |
38 | 0 | p_tmp->data = mk_mem_alloc_z(32); |
39 | 0 | p_tmp->len = -1; |
40 | 0 | MK_TLS_SET(mk_tls_cache_header_lm, p_tmp); |
41 | | |
42 | | /* Cache header request -> content length */ |
43 | 0 | p_tmp = mk_mem_alloc_z(sizeof(mk_ptr_t)); |
44 | 0 | p_tmp->data = mk_mem_alloc_z(MK_UTILS_INT2MKP_BUFFER_LEN); |
45 | 0 | p_tmp->len = -1; |
46 | 0 | MK_TLS_SET(mk_tls_cache_header_cl, p_tmp); |
47 | | |
48 | | /* Cache gmtime buffer */ |
49 | 0 | MK_TLS_SET(mk_tls_cache_gmtime, mk_mem_alloc(sizeof(struct tm))); |
50 | | |
51 | | /* Cache the most used text representations of utime2gmt */ |
52 | 0 | MK_TLS_SET(mk_tls_cache_gmtext, |
53 | 0 | mk_mem_alloc_z(sizeof(struct mk_gmt_cache) * MK_GMT_CACHES)); |
54 | | |
55 | | /* Cache buffer for strerror_r(2) */ |
56 | 0 | cache_error = mk_mem_alloc(MK_UTILS_ERROR_SIZE); |
57 | 0 | pthread_setspecific(mk_utils_error_key, (void *) cache_error); |
58 | 0 | } |
59 | | |
60 | | void mk_cache_worker_exit() |
61 | 0 | { |
62 | 0 | char *cache_error; |
63 | | |
64 | | /* Cache header request -> last modified */ |
65 | 0 | mk_ptr_free(MK_TLS_GET(mk_tls_cache_header_lm)); |
66 | 0 | mk_mem_free(MK_TLS_GET(mk_tls_cache_header_lm)); |
67 | | |
68 | | /* Cache header request -> content length */ |
69 | 0 | mk_ptr_free(MK_TLS_GET(mk_tls_cache_header_cl)); |
70 | 0 | mk_mem_free(MK_TLS_GET(mk_tls_cache_header_cl)); |
71 | | |
72 | | /* Cache gmtime buffer */ |
73 | 0 | mk_mem_free(MK_TLS_GET(mk_tls_cache_gmtime)); |
74 | | |
75 | | /* Cache the most used text representations of utime2gmt */ |
76 | 0 | mk_mem_free(MK_TLS_GET(mk_tls_cache_gmtext)); |
77 | | |
78 | | /* Cache buffer for strerror_r(2) */ |
79 | 0 | cache_error = pthread_getspecific(mk_utils_error_key); |
80 | 0 | mk_mem_free(cache_error); |
81 | 0 | } |