3 * - multithreading layer
6 * This file is part of adns, which is Copyright (C) 1997-1999 Ian Jackson
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2, or (at your option)
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 struct adns_mt__state
{
28 pthread_mutex_t mutex
;
31 struct adns_mt__query
{
38 int adns_mt_init(adns_mt_state
*newstate_r
, adns_initflags flags
, FILE *diagfile
) {
42 adts
= malloc(sizeof(*adts
)); if (!adts
) return errno
;
43 r
= pthread_mutex_init(&adts
->mutex
,0); assert(!r
);
44 r
= pthread_mutex_lock(&adts
->mutex
); assert(!r
);
45 r
= pthread_create(&adts
->executor
,0,executor_start
,adts
);
46 if (r
) { pthread_mutex_destroy(&adts
->mutex
); free(adts
); return r
; }
50 int adns_mt_init_strcfg(adns_mt_state
*newstate_r
, adns_initflags flags
,
51 FILE *diagfile
/*0=>discard*/, const char *configtext
);
53 int adns_mt_synchronous(adns_mt_state adts
,
56 adns_queryflags flags
,
57 adns_answer
**answer_r
);
59 int adns_mt_submit(adns_mt_state adts
,
62 adns_queryflags flags
,
64 adns_mt_query
*query_r
);
66 int adns_mt_wait(adns_mt_state adts
,
67 adns_mt_query
*query_io
,
68 adns_answer
**answer_r
,
71 void adns_mt_cancel(adns_mt_query query
);
72 /* Do not cancel a query while another thread is waiting for it ! */
74 void adns_mt_finish(adns_mt_state
);
75 /* You may call this even if you have queries outstanding;
76 * they will be cancelled. NB the comment about _mt_cancel above.