#include <glib.h>
-#define DEBUG_MSG(x)
-/* #define DEBUG_MSG(args) g_printerr args ; g_printerr ("\n"); */
+/* #define DEBUG 1 */
+
+#ifdef DEBUG
+# define DEBUG_MSG(args) g_printerr args ; g_printerr ("\n");
+#else
+# define DEBUG_MSG(x)
+#endif
#define WAIT 5 /* seconds */
#define MAX_THREADS 10
static void
test_thread_pools_entry_func (gpointer data, gpointer user_data)
{
+#ifdef DEBUG
guint id = 0;
id = GPOINTER_TO_UINT (data);
+#endif
DEBUG_MSG (("[pool] ---> [%3.3d] entered thread.", id));
static void
test_thread_idle_time_entry_func (gpointer data, gpointer user_data)
{
+#ifdef DEBUG
guint thread_id;
thread_id = GPOINTER_TO_UINT (data);
+#endif
DEBUG_MSG (("[idle] ---> entered thread:%2.2d", thread_id));
static gboolean
test_thread_idle_timeout (gpointer data)
{
- guint interval;
gint i;
- interval = GPOINTER_TO_UINT (data);
-
for (i = 0; i < 2; i++) {
g_thread_pool_push (idle_pool, GUINT_TO_POINTER (100 + i), NULL);
DEBUG_MSG (("[idle] ===> pushed new thread with id:%d, number "
}
static void
-test_thread_idle_time ()
+test_thread_idle_time (void)
{
guint limit = 50;
guint interval = 10000;
idle_pool = g_thread_pool_new (test_thread_idle_time_entry_func,
NULL,
- MAX_THREADS,
+ 0,
FALSE,
NULL);
+ g_thread_pool_set_max_threads (idle_pool, MAX_THREADS, NULL);
g_thread_pool_set_max_unused_threads (MAX_UNUSED_THREADS);
g_thread_pool_set_max_idle_time (interval);
+ g_assert (g_thread_pool_get_max_threads (idle_pool) == MAX_THREADS);
g_assert (g_thread_pool_get_max_unused_threads () == MAX_UNUSED_THREADS);
g_assert (g_thread_pool_get_max_idle_time () == interval);
g_thread_pool_unprocessed (idle_pool)));
}
+ g_assert_cmpint (g_thread_pool_unprocessed (idle_pool), <=, limit);
+
g_timeout_add ((interval - 1000),
test_thread_idle_timeout,
GUINT_TO_POINTER (interval));