apicompatanamdw/bcdrivers/os/ossrv/glib/tests/threadpool-test.c
author shrivatsa
Thu, 22 Apr 2010 17:15:08 +0530
changeset 2 0cb2248d0edc
child 8 d8ef7a232001
permissions -rw-r--r--
New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer, Startup List Management, Flash viewer framework, Network Status, Profile engine wrapper, Drm helper, OMA Drm CAF Agent, SIP, Connection settings & UI, BLID, Landmarks, Send UI, Media Fetch, WebServices, Cellular services, Device services, Graphics, Kernel and OSSrv, XML Services, Multimedia.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
     1
/*
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
     2
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
     3
* All rights reserved.
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
     4
* This component and the accompanying materials are made available
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
     6
* which accompanies this distribution, and is available
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
     8
*
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
     9
* Initial Contributors:
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    11
*
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    12
* Contributors:
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    13
*
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    14
* Description:
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    15
*
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    16
*/
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    17
#undef G_DISABLE_ASSERT
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    18
#undef G_LOG_DOMAIN
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    19
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    20
#include <config.h>
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    21
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    22
#include <glib.h>
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    23
#include <stdio.h>
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    24
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    25
#ifdef SYMBIAN
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    26
#include <glib_global.h>
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    27
#include "mrt2_glib2_test.h"
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    28
#endif /*SYMBIAN*/
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    29
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    30
#define DEBUG_MSG(x)  
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    31
/* #define DEBUG_MSG(args) g_printerr args ; g_printerr ("\n");  */
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    32
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    33
#define WAIT                5    /* seconds */
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    34
#define MAX_THREADS         10
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    35
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    36
/* if > 0 the test will run continously (since the test ends when
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    37
 * thread count is 0), if -1 it means no limit to unused threads  
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    38
 * if 0 then no unused threads are possible */
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    39
#define MAX_UNUSED_THREADS -1    
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    40
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    41
G_LOCK_DEFINE_STATIC (thread_counter_pools);
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    42
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    43
static gulong abs_thread_counter = 0;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    44
static gulong running_thread_counter = 0;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    45
static gulong leftover_task_counter = 0;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    46
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    47
G_LOCK_DEFINE_STATIC (last_thread);
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    48
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    49
static guint last_thread_id = 0;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    50
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    51
G_LOCK_DEFINE_STATIC (thread_counter_sort);
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    52
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    53
static gulong sort_thread_counter = 0;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    54
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    55
static GThreadPool *idle_pool = NULL;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    56
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    57
static GMainLoop *main_loop = NULL;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    58
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    59
static void
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    60
test_thread_functions (void)
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    61
{
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    62
  gint max_unused_threads;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    63
  guint max_idle_time;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    64
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    65
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    66
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    67
  /* This function attempts to call functions which don't need a
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    68
   * threadpool to operate to make sure no uninitialised pointers
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    69
   * accessed and no errors occur.
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    70
   */
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    71
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    72
  max_unused_threads = 3;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    73
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    74
  DEBUG_MSG (("[funcs] Setting max unused threads to %d", 
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    75
	      max_unused_threads));
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    76
  g_thread_pool_set_max_unused_threads (max_unused_threads);
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    77
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    78
  DEBUG_MSG (("[funcs] Getting max unused threads = %d", 
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    79
	     g_thread_pool_get_max_unused_threads ()));
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    80
  g_assert (g_thread_pool_get_max_unused_threads() == max_unused_threads);
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    81
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    82
  DEBUG_MSG (("[funcs] Getting num unused threads = %d", 
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    83
	     g_thread_pool_get_num_unused_threads ()));
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    84
  g_assert (g_thread_pool_get_num_unused_threads () == 0);
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    85
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    86
  DEBUG_MSG (("[funcs] Stopping unused threads"));
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    87
  g_thread_pool_stop_unused_threads ();
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    88
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    89
  max_idle_time = 10 * G_USEC_PER_SEC;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    90
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    91
  DEBUG_MSG (("[funcs] Setting max idle time to %d", 
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    92
	      max_idle_time));
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    93
  g_thread_pool_set_max_idle_time (max_idle_time);
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    94
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    95
  DEBUG_MSG (("[funcs] Getting max idle time = %d", 
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    96
	     g_thread_pool_get_max_idle_time ()));
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    97
  g_assert (g_thread_pool_get_max_idle_time () == max_idle_time);
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    98
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
    99
  DEBUG_MSG (("[funcs] Setting max idle time to 0"));
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   100
  g_thread_pool_set_max_idle_time (0);
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   101
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   102
  DEBUG_MSG (("[funcs] Getting max idle time = %d", 
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   103
	     g_thread_pool_get_max_idle_time ()));
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   104
  g_assert (g_thread_pool_get_max_idle_time () == 0);
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   105
}
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   106
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   107
static void
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   108
test_count_threads_foreach (GThread *thread, 
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   109
			    guint   *count)
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   110
{
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   111
   ++*count;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   112
}
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   113
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   114
static guint
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   115
test_count_threads (void)
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   116
{
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   117
  guint count = 0;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   118
  
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   119
  g_thread_foreach ((GFunc) test_count_threads_foreach, &count);
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   120
  
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   121
  /* Exclude main thread */
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   122
  return count - 1;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   123
}
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   124
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   125
static void
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   126
test_thread_stop_unused (void)
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   127
{ 
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   128
   GThreadPool *pool;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   129
   guint i;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   130
   guint limit = 100;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   131
   
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   132
   /* Spawn a few threads. */
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   133
   g_thread_pool_set_max_unused_threads (-1);
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   134
   pool = g_thread_pool_new ((GFunc) g_usleep, NULL, -1, FALSE, NULL);
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   135
   
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   136
   for (i = 0; i < limit; i++)
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   137
     g_thread_pool_push (pool, GUINT_TO_POINTER (1000), NULL);
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   138
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   139
   DEBUG_MSG (("[unused] ===> pushed %d threads onto the idle pool",
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   140
	       limit));
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   141
   
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   142
   /* Wait for the threads to migrate. */
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   143
   g_usleep (G_USEC_PER_SEC); 
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   144
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   145
   DEBUG_MSG (("[unused] current threads %d",
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   146
	       test_count_threads()));
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   147
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   148
   DEBUG_MSG (("[unused] stopping unused threads"));
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   149
   g_thread_pool_stop_unused_threads ();
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   150
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   151
   DEBUG_MSG (("[unused] waiting ONE second for threads to die"));
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   152
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   153
   /* Some time for threads to die. */
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   154
   g_usleep (G_USEC_PER_SEC); 
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   155
   
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   156
   DEBUG_MSG (("[unused] stopped idle threads, %d remain, %d threads still exist",
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   157
	       g_thread_pool_get_num_unused_threads (), 
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   158
	       test_count_threads ()));
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   159
   
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   160
   g_assert (g_thread_pool_get_num_unused_threads () == test_count_threads ());
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   161
   g_assert (g_thread_pool_get_num_unused_threads () == 0);
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   162
   
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   163
   g_thread_pool_set_max_unused_threads (MAX_THREADS);
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   164
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   165
   DEBUG_MSG (("[unused] cleaning up thread pool"));
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   166
   g_thread_pool_free (pool, FALSE, TRUE);
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   167
}
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   168
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   169
static void
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   170
test_thread_pools_entry_func (gpointer data, gpointer user_data)
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   171
{
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   172
  guint id = 0;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   173
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   174
  id = GPOINTER_TO_UINT (data);
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   175
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   176
  DEBUG_MSG (("[pool] ---> [%3.3d] entered thread.", id));
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   177
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   178
  G_LOCK (thread_counter_pools);
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   179
  abs_thread_counter++;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   180
  running_thread_counter++;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   181
  G_UNLOCK (thread_counter_pools);
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   182
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   183
  g_usleep (g_random_int_range (0, 4000));
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   184
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   185
  G_LOCK (thread_counter_pools);
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   186
  running_thread_counter--;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   187
  leftover_task_counter--;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   188
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   189
  DEBUG_MSG (("[pool] ---> [%3.3d] exiting thread (abs count:%ld, "
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   190
	      "running count:%ld, left over:%ld)", 
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   191
	      id, abs_thread_counter, 
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   192
	      running_thread_counter, leftover_task_counter)); 
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   193
  G_UNLOCK (thread_counter_pools);
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   194
}
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   195
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   196
static void
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   197
test_thread_pools (void)
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   198
{
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   199
  GThreadPool *pool1, *pool2, *pool3;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   200
  guint runs;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   201
  guint i;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   202
  
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   203
  pool1 = g_thread_pool_new ((GFunc)test_thread_pools_entry_func, NULL, 3, FALSE, NULL);
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   204
  pool2 = g_thread_pool_new ((GFunc)test_thread_pools_entry_func, NULL, 5, TRUE, NULL);
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   205
  pool3 = g_thread_pool_new ((GFunc)test_thread_pools_entry_func, NULL, 7, TRUE, NULL);
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   206
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   207
  runs = 300;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   208
  for (i = 0; i < runs; i++)
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   209
    {
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   210
      g_thread_pool_push (pool1, GUINT_TO_POINTER (i + 1), NULL);
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   211
      g_thread_pool_push (pool2, GUINT_TO_POINTER (i + 1), NULL);
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   212
      g_thread_pool_push (pool3, GUINT_TO_POINTER (i + 1), NULL);
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   213
      leftover_task_counter += 3;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   214
    } 
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   215
  
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   216
  g_thread_pool_free (pool1, TRUE, TRUE);
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   217
  g_thread_pool_free (pool2, FALSE, TRUE);
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   218
  g_thread_pool_free (pool3, FALSE, TRUE);
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   219
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   220
  g_assert (runs * 3 == abs_thread_counter + leftover_task_counter);
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   221
  g_assert (running_thread_counter == 0);  
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   222
}
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   223
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   224
static gint
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   225
test_thread_sort_compare_func (gconstpointer a, gconstpointer b, gpointer user_data)
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   226
{
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   227
  guint32 id1, id2;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   228
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   229
  id1 = GPOINTER_TO_UINT (a);
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   230
  id2 = GPOINTER_TO_UINT (b);
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   231
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   232
  return (id1 > id2 ? +1 : id1 == id2 ? 0 : -1); 
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   233
}
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   234
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   235
static void
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   236
test_thread_sort_entry_func (gpointer data, gpointer user_data)
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   237
{
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   238
  guint thread_id;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   239
  gboolean is_sorted;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   240
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   241
  G_LOCK (last_thread);
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   242
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   243
  thread_id = GPOINTER_TO_UINT (data);
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   244
  is_sorted = GPOINTER_TO_INT (user_data);
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   245
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   246
  DEBUG_MSG (("%s ---> entered thread:%2.2d, last thread:%2.2d", 
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   247
	      is_sorted ? "[  sorted]" : "[unsorted]", 
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   248
	      thread_id, last_thread_id));
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   249
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   250
  if (is_sorted) {
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   251
    static gboolean last_failed = FALSE;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   252
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   253
    if (last_thread_id > thread_id) {
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   254
      if (last_failed) {
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   255
	g_assert (last_thread_id <= thread_id);  
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   256
      }
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   257
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   258
      /* Here we remember one fail and if it concurrently fails, it
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   259
       * can not be sorted. the last thread id might be < this thread
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   260
       * id if something is added to the queue since threads were
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   261
       * created  
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   262
       */
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   263
      last_failed = TRUE;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   264
    } else {
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   265
      last_failed = FALSE;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   266
    }
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   267
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   268
    last_thread_id = thread_id;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   269
  }
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   270
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   271
  G_UNLOCK (last_thread);
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   272
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   273
  g_usleep (WAIT * 1000);
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   274
}
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   275
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   276
static void
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   277
test_thread_sort (gboolean sort)
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   278
{
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   279
  GThreadPool *pool;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   280
  guint limit;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   281
  guint max_threads;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   282
  gint i;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   283
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   284
  limit = MAX_THREADS * 10;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   285
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   286
  if (sort) {
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   287
    max_threads = 1;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   288
  } else {
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   289
    max_threads = MAX_THREADS;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   290
  }
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   291
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   292
  /* It is important that we only have a maximum of 1 thread for this
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   293
   * test since the results can not be guranteed to be sorted if > 1.
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   294
   * 
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   295
   * Threads are scheduled by the operating system and are executed at
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   296
   * random. It cannot be assumed that threads are executed in the
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   297
   * order they are created. This was discussed in bug #334943.
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   298
   */
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   299
  
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   300
  pool = g_thread_pool_new (test_thread_sort_entry_func, 
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   301
			    GINT_TO_POINTER (sort), 
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   302
			    max_threads, 
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   303
			    FALSE,
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   304
			    NULL);
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   305
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   306
  g_thread_pool_set_max_unused_threads (MAX_UNUSED_THREADS); 
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   307
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   308
  if (sort) {
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   309
    g_thread_pool_set_sort_function (pool, 
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   310
				     test_thread_sort_compare_func,
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   311
				     GUINT_TO_POINTER (69));
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   312
  }
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   313
  
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   314
  for (i = 0; i < limit; i++) {
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   315
    guint id;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   316
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   317
    id = g_random_int_range (1, limit) + 1;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   318
    g_thread_pool_push (pool, GUINT_TO_POINTER (id), NULL);
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   319
    DEBUG_MSG (("%s ===> pushed new thread with id:%d, number "
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   320
		"of threads:%d, unprocessed:%d",
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   321
		sort ? "[  sorted]" : "[unsorted]", 
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   322
		id, 
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   323
		g_thread_pool_get_num_threads (pool),
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   324
		g_thread_pool_unprocessed (pool)));
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   325
  }
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   326
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   327
  g_assert (g_thread_pool_get_max_threads (pool) == max_threads);
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   328
  g_assert (g_thread_pool_get_num_threads (pool) == g_thread_pool_get_max_threads (pool));
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   329
}
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   330
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   331
static void
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   332
test_thread_idle_time_entry_func (gpointer data, gpointer user_data)
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   333
{
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   334
  guint thread_id;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   335
  
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   336
  thread_id = GPOINTER_TO_UINT (data);
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   337
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   338
  DEBUG_MSG (("[idle] ---> entered thread:%2.2d", thread_id));
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   339
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   340
  g_usleep (WAIT * 1000);
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   341
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   342
  DEBUG_MSG (("[idle] <--- exiting thread:%2.2d", thread_id));
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   343
}
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   344
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   345
static gboolean 
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   346
test_thread_idle_timeout (gpointer data)
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   347
{
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   348
  guint interval;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   349
  gint i;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   350
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   351
  interval = GPOINTER_TO_UINT (data);
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   352
  
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   353
  for (i = 0; i < 2; i++) {
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   354
    g_thread_pool_push (idle_pool, GUINT_TO_POINTER (100 + i), NULL); 
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   355
    DEBUG_MSG (("[idle] ===> pushed new thread with id:%d, number "
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   356
		"of threads:%d, unprocessed:%d",
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   357
		100 + i, 
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   358
		g_thread_pool_get_num_threads (idle_pool),
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   359
		g_thread_pool_unprocessed (idle_pool)));
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   360
  }
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   361
  
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   362
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   363
  return FALSE;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   364
}
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   365
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   366
static void
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   367
test_thread_idle_time ()
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   368
{
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   369
  guint limit = 50;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   370
  guint interval = 10000;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   371
  gint i;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   372
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   373
  idle_pool = g_thread_pool_new (test_thread_idle_time_entry_func, 
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   374
				 NULL, 
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   375
				 MAX_THREADS,
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   376
				 FALSE,
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   377
				 NULL);
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   378
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   379
  g_thread_pool_set_max_unused_threads (MAX_UNUSED_THREADS);  
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   380
  g_thread_pool_set_max_idle_time (interval); 
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   381
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   382
  g_assert (g_thread_pool_get_max_unused_threads () == MAX_UNUSED_THREADS);   
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   383
  g_assert (g_thread_pool_get_max_idle_time () == interval);
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   384
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   385
  for (i = 0; i < limit; i++) {
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   386
    g_thread_pool_push (idle_pool, GUINT_TO_POINTER (i + 1), NULL); 
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   387
    DEBUG_MSG (("[idle] ===> pushed new thread with id:%d, "
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   388
		"number of threads:%d, unprocessed:%d",
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   389
		i,
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   390
		g_thread_pool_get_num_threads (idle_pool),
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   391
		g_thread_pool_unprocessed (idle_pool)));
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   392
  }
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   393
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   394
  g_timeout_add ((interval - 1000),
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   395
		 test_thread_idle_timeout, 
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   396
		 GUINT_TO_POINTER (interval));
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   397
}
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   398
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   399
static gboolean
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   400
test_check_start_and_stop (gpointer user_data)
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   401
{
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   402
  static guint test_number = 0;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   403
  static gboolean run_next = FALSE;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   404
  gboolean continue_timeout = TRUE;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   405
  gboolean quit = TRUE;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   406
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   407
  if (test_number == 0) {
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   408
    run_next = TRUE;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   409
    DEBUG_MSG (("***** RUNNING TEST %2.2d *****", test_number)); 
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   410
  }
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   411
   
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   412
  if (run_next) {
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   413
    test_number++;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   414
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   415
    switch (test_number) {
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   416
    case 1:
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   417
      test_thread_functions ();
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   418
      break;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   419
    case 2:
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   420
      test_thread_stop_unused ();
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   421
      break;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   422
    case 3:
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   423
      test_thread_pools ();   
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   424
      break;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   425
    case 4:
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   426
      test_thread_sort (FALSE);  
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   427
      break;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   428
    case 5:
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   429
      test_thread_sort (TRUE);  
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   430
      break;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   431
    case 6:
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   432
      test_thread_idle_time ();   
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   433
      break;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   434
    default:
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   435
      DEBUG_MSG (("***** END OF TESTS *****")); 
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   436
      g_main_loop_quit (main_loop);
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   437
      continue_timeout = FALSE;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   438
      break;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   439
    }
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   440
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   441
    run_next = FALSE;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   442
    return TRUE;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   443
  }
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   444
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   445
  if (test_number == 3) {
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   446
    G_LOCK (thread_counter_pools); 
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   447
    quit &= running_thread_counter <= 0;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   448
    DEBUG_MSG (("***** POOL RUNNING THREAD COUNT:%ld", 
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   449
		running_thread_counter)); 
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   450
    G_UNLOCK (thread_counter_pools); 
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   451
  }
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   452
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   453
  if (test_number == 4 || test_number == 5) {
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   454
    G_LOCK (thread_counter_sort);
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   455
    quit &= sort_thread_counter <= 0;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   456
    DEBUG_MSG (("***** POOL SORT THREAD COUNT:%ld", 
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   457
		sort_thread_counter)); 
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   458
    G_UNLOCK (thread_counter_sort); 
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   459
  }
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   460
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   461
  if (test_number == 6) {
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   462
    guint idle;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   463
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   464
    idle = g_thread_pool_get_num_unused_threads ();
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   465
    quit &= idle < 1;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   466
    DEBUG_MSG (("***** POOL IDLE THREAD COUNT:%d, UNPROCESSED JOBS:%d",
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   467
		idle, g_thread_pool_unprocessed (idle_pool)));
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   468
  }    
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   469
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   470
  if (quit) {
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   471
    run_next = TRUE;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   472
  }
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   473
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   474
  return continue_timeout;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   475
}
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   476
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   477
int 
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   478
main (int argc, char *argv[])
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   479
{
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   480
  /* Only run the test, if threads are enabled and a default thread
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   481
     implementation is available */
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   482
  #ifdef SYMBIAN
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   483
  guint g_thread_pool_unprocessed_op = -1;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   484
  guint res;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   485
  #endif //SYMBIAN
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   486
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   487
#if defined(G_THREADS_ENABLED) && ! defined(G_THREADS_IMPL_NONE)
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   488
  g_thread_init (NULL);
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   489
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   490
  DEBUG_MSG (("Starting... (in one second)"));
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   491
  g_timeout_add (1000, test_check_start_and_stop, NULL); 
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   492
  
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   493
  main_loop = g_main_loop_new (NULL, FALSE);
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   494
  g_main_loop_run (main_loop);
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   495
#endif
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   496
#ifdef SYMBIAN
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   497
  testResultXml("threadpool-test");
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   498
#endif /* EMULATOR */
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   499
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   500
  return 0;
0cb2248d0edc New BC drivers added are - Phonebook, Speed dial utility control, MMS Client MTM, Plugin Bio control, Organizer,
shrivatsa
parents:
diff changeset
   501
}