2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3 * Copyright (C) <2004> Thomas Vander Stichele <thomas at apestaart dot org>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
25 static GList *fds = NULL;
26 static GMutex *fdlock;
29 #define MAX_THREADS 100
38 g_mutex_lock (fdlock);
40 for (walk = fds; walk;) {
41 GstPollFD *fd = (GstPollFD *) walk->data;
43 walk = g_list_next (walk);
45 random = (gint) (10.0 * rand () / (RAND_MAX + 1.0));
50 GstPollFD *newfd = g_new0 (GstPollFD, 1);
52 gst_poll_add_fd (set, newfd);
53 fds = g_list_prepend (fds, newfd);
58 if ((gint) (10.0 * rand () / (RAND_MAX + 1.0)) < 2) {
59 gst_poll_remove_fd (set, fd);
60 fds = g_list_remove (fds, fd);
67 gst_poll_fd_ctl_write (set, fd, TRUE);
70 gst_poll_fd_ctl_write (set, fd, FALSE);
73 gst_poll_fd_ctl_read (set, fd, TRUE);
76 gst_poll_fd_ctl_read (set, fd, FALSE);
80 gst_poll_fd_has_closed (set, fd);
83 gst_poll_fd_has_error (set, fd);
86 gst_poll_fd_can_read (set, fd);
89 gst_poll_fd_can_write (set, fd);
92 g_assert_not_reached ();
96 if (g_list_length (fds) < 900) {
97 random = removed + (gint) (2.0 * rand () / (RAND_MAX + 1.0));
99 GstPollFD *newfd = g_new0 (GstPollFD, 1);
101 gst_poll_add_fd (set, newfd);
102 fds = g_list_prepend (fds, newfd);
107 g_mutex_unlock (fdlock);
111 run_test (void *threadid)
113 gint id = GPOINTER_TO_INT (threadid);
117 gint res = gst_poll_wait (set, 10);
120 g_print ("error %d %s\n", errno, g_strerror (errno));
124 if (g_timer_elapsed (timer, NULL) > 0.5) {
125 g_mutex_lock (fdlock);
126 g_print ("active fds :%d\n", g_list_length (fds));
127 g_timer_start (timer);
128 g_mutex_unlock (fdlock);
134 g_thread_exit (NULL);
139 main (gint argc, gchar * argv[])
141 GThread *threads[MAX_THREADS];
145 gst_init (&argc, &argv);
147 fdlock = g_mutex_new ();
148 timer = g_timer_new ();
151 g_print ("usage: %s <num_threads>\n", argv[0]);
155 num_threads = atoi (argv[1]);
157 set = gst_poll_new (GST_POLL_MODE_POLL, TRUE);
159 for (t = 0; t < num_threads; t++) {
160 GError *error = NULL;
162 threads[t] = g_thread_create (run_test, GINT_TO_POINTER (t), TRUE, &error);
164 printf ("ERROR: g_thread_create() %s\n", error->message);
168 printf ("main(): Created %d threads.\n", t);
170 for (t = 0; t < num_threads; t++) {
171 g_thread_join (threads[t]);