1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
5 * Copyright (C) 2001-2010, Eduardo Silva P. <edsiper@gmail.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Library General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
31 /* This function is called when a thread is created */
32 void mk_cache_thread_init()
34 struct request_idx
*cache_request_idx
;
35 struct mk_iov
*cache_iov_header
;
36 struct header_toc
*cache_header_toc
;
37 mk_pointer
*cache_header_lm
;
38 mk_pointer
*cache_header_cl
;
40 /* client request index */
41 cache_request_idx
= mk_mem_malloc(sizeof(struct request_idx
));
42 cache_request_idx
->first
= NULL
;
43 cache_request_idx
->last
= NULL
;
44 pthread_setspecific(request_index
, (void *) cache_request_idx
);
46 /* Cache header request -> last modified */
47 cache_header_lm
= mk_mem_malloc_z(sizeof(mk_pointer
));
48 cache_header_lm
->data
= mk_mem_malloc_z(32);
49 cache_header_lm
->len
= -1;
50 pthread_setspecific(mk_cache_header_lm
, (void *) cache_header_lm
);
52 /* Cache header request -> content length */
53 cache_header_cl
= mk_mem_malloc_z(sizeof(mk_pointer
));
54 cache_header_cl
->data
= mk_mem_malloc_z(MK_UTILS_INT2MKP_BUFFER_LEN
);
55 cache_header_cl
->len
= -1;
56 pthread_setspecific(mk_cache_header_cl
, (void *) cache_header_cl
);
58 /* Cache iov header struct */
59 cache_iov_header
= mk_iov_create(32, 0);
60 pthread_setspecific(mk_cache_iov_header
, (void *) cache_iov_header
);
62 /* Cache header toc, monkey just search for MK_KNOWN_HEADERS
65 cache_header_toc
= mk_mem_malloc_z(sizeof(struct header_toc
) *
67 pthread_setspecific(mk_cache_header_toc
, (void *) cache_header_toc
);
70 void *mk_cache_get(pthread_key_t key
)
72 return ( void *) pthread_getspecific(key
);