1 /* $Id: test_sel_thread.c,v 1.2 2007-04-20 11:44:58 adam Exp $
2 Copyright (c) 2006-2007, Index Data.
4 This file is part of Pazpar2.
6 Pazpar2 is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
11 Pazpar2 is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with Pazpar2; see the file LICENSE. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
26 #include "sel_thread.h"
29 #include <yaz/xmalloc.h>
31 /** \brief stuff we work on in separate thread */
37 /** \brief work to be carried out in separate thrad */
38 static void work_handler(void *vp)
40 struct my_work_data *p = vp;
44 /** \brief see if we can create and destroy without problems */
45 static void test_1(void)
48 sel_thread_t p = sel_thread_create(work_handler, &fd);
53 sel_thread_destroy(p);
57 void iochan_handler(struct iochan *i, int event)
59 static int number = 0;
60 sel_thread_t p = iochan_getdata(i);
62 if (event & EVENT_INPUT)
64 struct my_work_data *work;
66 work = sel_thread_result(p);
71 YAZ_CHECK_EQ(work->x * 2, work->y);
72 /* stop work after a couple of iterations */
80 if (event & EVENT_TIMEOUT)
82 struct my_work_data *work;
84 work = xmalloc(sizeof(*work));
86 sel_thread_add(p, work);
88 work = xmalloc(sizeof(*work));
90 sel_thread_add(p, work);
96 /** brief use the fd for something */
97 static void test_2(void)
100 sel_thread_t p = sel_thread_create(work_handler, &thread_fd);
104 IOCHAN chan = iochan_create(thread_fd, iochan_handler,
105 EVENT_INPUT|EVENT_TIMEOUT);
106 iochan_settimeout(chan, 1);
107 iochan_setdata(chan, p);
111 sel_thread_destroy(p);
114 int main(int argc, char **argv)
116 YAZ_CHECK_INIT(argc, argv);
131 * indent-tabs-mode: nil
133 * vim: shiftwidth=4 tabstop=8 expandtab