From: Michael R Sweet Date: Thu, 13 Sep 2018 20:19:47 +0000 (-0400) Subject: Change the threading model to keep track of a separate client thread count instead. X-Git-Tag: v2.3b6~98 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=80f5715924d86c6da0aba6474b0d8c78c19a7be2;p=thirdparty%2Fcups.git Change the threading model to keep track of a separate client thread count instead. --- diff --git a/cups/testclient.c b/cups/testclient.c index ad672e6e1a..3a9d4aae33 100644 --- a/cups/testclient.c +++ b/cups/testclient.c @@ -11,6 +11,7 @@ * Include necessary headers... */ +#include #include #include #include @@ -56,6 +57,8 @@ typedef struct _client_data_s * Local globals... */ +static int client_count = 0; +static _cups_mutex_t client_mutex = _CUPS_MUTEX_INITIALIZER; static int verbosity = 0; @@ -79,18 +82,16 @@ int /* O - Exit status */ main(int argc, /* I - Number of command-line arguments */ char *argv[]) /* I - Command-line arguments */ { - int i; /* Looping var */ - const char *opt; /* Current option */ - int num_clients = 0,/* Number of clients to simulate */ - total_clients; /* Total number of clients */ - _cups_thread_t clients[MAX_CLIENTS]; - /* Clients thread IDs */ - char scheme[32], /* URI scheme */ - userpass[256], /* Username:password */ - hostname[256], /* Hostname */ - resource[256]; /* Resource path */ + int i; /* Looping var */ + const char *opt; /* Current option */ + int num_clients = 0,/* Number of clients to simulate */ + clients_started = 0; + /* Number of clients that have been started */ + char scheme[32], /* URI scheme */ + userpass[256], /* Username:password */ + hostname[256], /* Hostname */ + resource[256]; /* Resource path */ _client_data_t data; /* Client data */ - int status = 0; /* Exit status */ /* @@ -240,28 +241,34 @@ main(int argc, /* I - Number of command-line arguments */ data.hostname = hostname; data.resource = resource; - for (i = 0, total_clients = 0; i < num_clients; i ++) + while (clients_started < num_clients) { - clients[i % MAX_CLIENTS] = _cupsThreadCreate((_cups_thread_func_t)run_client, &data); - - total_clients ++; - if (total_clients >= MAX_CLIENTS || (i + 1) >= num_clients) + _cupsMutexLock(&client_mutex); + if (client_count < MAX_CLIENTS) { - /* - * Wait for them to complete... - */ + _cups_thread_t tid; /* New thread */ - int j; - - for (j = 0; j < total_clients; j ++) - if (_cupsThreadWait(clients[j])) - status = 1; - - total_clients = 0; + client_count ++; + _cupsMutexUnlock(&client_mutex); + tid = _cupsThreadCreate((_cups_thread_func_t)run_client, &data); + _cupsThreadDetach(tid); + } + else + { + _cupsMutexUnlock(&client_mutex); + sleep(1); } } - return (status); + while (client_count > 0) + { + _cupsMutexLock(&client_mutex); + printf("%d RUNNING CLIENTS\n", client_count); + _cupsMutexUnlock(&client_mutex); + sleep(1); + } + + return (0); } @@ -937,6 +944,10 @@ run_client( _cupsThreadWait(monitor_id); + _cupsMutexLock(&client_mutex); + client_count --; + _cupsMutexUnlock(&client_mutex); + return (NULL); }