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.
26 static GList *fds = NULL;
27 static GMutex *fdlock;
30 #define MAX_THREADS 100
39 g_mutex_lock (fdlock);
41 for (walk = fds; walk;) {
42 GstPollFD *fd = (GstPollFD *) walk->data;
44 walk = g_list_next (walk);
46 random = (gint) (10.0 * rand () / (RAND_MAX + 1.0));
51 GstPollFD *newfd = g_new0 (GstPollFD, 1);
53 gst_poll_add_fd (set, newfd);
54 fds = g_list_prepend (fds, newfd);
59 if ((gint) (10.0 * rand () / (RAND_MAX + 1.0)) < 2) {
60 gst_poll_remove_fd (set, fd);
61 fds = g_list_remove (fds, fd);
68 gst_poll_fd_ctl_write (set, fd, TRUE);
71 gst_poll_fd_ctl_write (set, fd, FALSE);
74 gst_poll_fd_ctl_read (set, fd, TRUE);
77 gst_poll_fd_ctl_read (set, fd, FALSE);
81 gst_poll_fd_has_closed (set, fd);
84 gst_poll_fd_has_error (set, fd);
87 gst_poll_fd_can_read (set, fd);
90 gst_poll_fd_can_write (set, fd);
93 g_assert_not_reached ();
97 if (g_list_length (fds) < 900) {
98 random = removed + (gint) (2.0 * rand () / (RAND_MAX + 1.0));
100 GstPollFD *newfd = g_new0 (GstPollFD, 1);
102 gst_poll_add_fd (set, newfd);
103 fds = g_list_prepend (fds, newfd);
108 g_mutex_unlock (fdlock);
112 run_test (void *threadid)
114 gint id = GPOINTER_TO_INT (threadid);
118 gint res = gst_poll_wait (set, 10);
121 g_print ("error %d %s\n", errno, g_strerror (errno));
125 if (g_timer_elapsed (timer, NULL) > 0.5) {
126 g_mutex_lock (fdlock);
127 g_print ("active fds :%d\n", g_list_length (fds));
128 g_timer_start (timer);
129 g_mutex_unlock (fdlock);
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 (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]);