[netperf-dev] netperf4 commit notice r111 -
branches/glib_migration/src
raj at netperf.org
raj at netperf.org
Wed Mar 29 16:56:14 PST 2006
Author: raj
Date: 2006-03-29 16:56:12 -0800 (Wed, 29 Mar 2006)
New Revision: 111
Modified:
branches/glib_migration/src/netlib.c
branches/glib_migration/src/netlib.h
branches/glib_migration/src/netmsg.c
branches/glib_migration/src/netperf.c
branches/glib_migration/src/netperf.h
branches/glib_migration/src/netserver.c
Log:
Cut the strings and make the glib code the only code in the source files
Modified: branches/glib_migration/src/netlib.c
===================================================================
--- branches/glib_migration/src/netlib.c 2006-03-30 00:31:33 UTC (rev 110)
+++ branches/glib_migration/src/netlib.c 2006-03-30 00:56:12 UTC (rev 111)
@@ -103,14 +103,8 @@
#include <dlfcn.h>
#endif
-#ifdef WITH_GLIB
# include <glib.h>
# include <gmodule.h>
-#else
-# ifdef HAVE_PTHREAD_H
-# include <pthread.h>
-# endif
-#endif
#ifdef HAVE_WINSOCK2_H
#include <winsock2.h>
@@ -1183,13 +1177,10 @@
}
if (NULL != ld_library_path) {
-#ifdef WITH_GLIB
gchar **tokens;
int tok;
-#endif
/* OK, start trapsing down the path until we find a match */
strcpy(ld_library_path,temp);
-#ifdef WITH_GLIB
tokens = g_strsplit(ld_library_path,":",15);
for (tok = 0; tokens[tok] != NULL; tok++) {
g_snprintf(full_path,PATH_MAX,"%s%s%s",tokens[tok],NETPERF_PATH_SEP,la);
@@ -1203,21 +1194,6 @@
}
}
g_strfreev(tokens);
-#else
- s = ld_library_path;
- while ((temp = strtok_r(s,":",&last)) != NULL) {
- s = NULL;
- snprintf(full_path,PATH_MAX,"%s%s%s",temp,NETPERF_PATH_SEP,la);
- if (stat(full_path,&buf) == 0) {
- /* we have a winner, time to go */
- break;
- }
- else {
- /* put-back the original la file */
- strncpy(full_path,(char *)la,PATH_MAX);
- }
- }
-#endif
}
/* so, after all that, is it really a ".la" file or is it some other
@@ -1301,12 +1277,8 @@
xmlChar *fname;
GenReport func;
-#ifdef WITH_GLIB
gboolean ret;
GModule *lib_handle;
-#else
- void *lib_handle;
-#endif
/* first we do the xml stuff */
@@ -1325,38 +1297,22 @@
free(la_file);
/* now we do the dlopen/gmodule magic */
-#ifdef WITH_GLIB
lib_handle = g_module_open((const gchar *)lib_file,0);
-#else
- lib_handle = dlopen((char *)lib_file, RTLD_NOW || RTLD_GLOBAL);
-#endif
if (debug) {
fprintf(where,"open of library file '%s' returned %p\n",
(char *)lib_file, lib_handle);
if (lib_handle == NULL) {
-#ifdef WITH_GLIB
fprintf(where,"g_module_open error '%s'\n",g_module_error());
-#else
- fprintf (where,"dlopen error '%s'\n",dlerror());
-#endif
}
fflush(where);
}
-#ifdef WITH_GLIB
ret = g_module_symbol(lib_handle,fname,(gpointer *)&func);
-#else
- func = (GenReport)dlsym(lib_handle,(char *)fname);
-#endif
if (debug) {
fprintf(where,"symbol lookup of function '%s' returned %p\n",
fname, func);
if (func == NULL) {
-#ifdef WITH_GLIB
fprintf(where,"g_module_symbol error '%s'\n",g_module_error());
-#else
- fprintf (where,"dlsym error '%s'\n",dlerror());
-#endif
}
fflush(where);
}
@@ -1368,12 +1324,8 @@
get_test_function(test_t *test, const xmlChar *func)
{
int tmp = debug;
-#ifdef WITH_GLIB
GModule *lib_handle = test->library_handle;
gboolean ret;
-#else
- void *lib_handle = test->library_handle;
-#endif
xmlChar *fname;
void *fptr = NULL;
int fnlen = 0;
@@ -1404,20 +1356,12 @@
fflush(where);
}
free(la_file);
-#ifdef WITH_GLIB
lib_handle = g_module_open((const gchar *)lib_file,0);
-#else
- lib_handle = dlopen((char *)lib_file, RTLD_NOW || RTLD_GLOBAL);
-#endif
if (debug) {
fprintf(where,"open of library file '%s' returned handle %p\n",
(char *)lib_file, lib_handle);
if (lib_handle == NULL) {
-#ifdef WITH_GLIB
fprintf(where,"g_module_open error '%s'\n",g_module_error());
-#else
- fprintf(where,"dlopen error '%s'\n",dlerror());
-#endif
}
fflush(where);
}
@@ -1488,20 +1432,12 @@
fflush(where);
}
if (rc == NPE_SUCCESS) {
-#ifdef WITH_GLIB
ret = g_module_symbol(lib_handle,func_name,&fptr);
-#else
- fptr = dlsym(lib_handle,func_name);
-#endif
if (debug) {
fprintf(where,"symbol lookup of func_name '%s' returned %p\n",
func_name, fptr);
if (fptr == NULL) {
-#ifdef WITH_GLIB
fprintf(where,"g_module_symbol error '%s'\n",g_module_error());
-#else
- fprintf (where,"dlsym error '%s'\n",dlerror());
-#endif
}
fflush(where);
}
@@ -1551,16 +1487,11 @@
make netlib.h dependent on netperf.h and I'm not sure I want to do
that. raj 2006-03-02 */
int
-#ifdef WITH_GLIB
launch_thread(GThread **tid, void *(*start_routine)(void *), void *data)
-#else
-launch_thread(pthread_t *tid, void *(*start_routine)(void *), void *data)
-#endif
{
int rc;
-#ifdef WITH_GLIB
NETPERF_THREAD_T temp_tid;
temp_tid = g_thread_create(start_routine,data,FALSE,NULL);
@@ -1572,39 +1503,6 @@
else {
rc = -1;
}
-#else
-
- NETPERF_THREAD_T temp_tid;
- rc = pthread_create(&temp_tid, (pthread_attr_t *)NULL, start_routine, data);
- if (rc != 0) {
- if (debug) {
- fprintf(where,"launch_thread: pthread_create failed with %d\n",rc);
- fflush(where);
- }
- rc = NPE_PTHREAD_CREATE_FAILED;
- } else {
- /* pthread_create succeeded detach thread so we don't need to join */
- *tid = temp_tid;
- if (debug) {
- fprintf(where,"launch_thread: pthread_create succeeded id = %d\n",*tid);
- fflush(where);
- }
- rc = pthread_detach(temp_tid);
- if (rc != 0) {
- if (debug) {
- fprintf(where,"launch_thread: pthread_detach failed %d\n",rc);
- fflush(where);
- }
- rc = NPE_PTHREAD_DETACH_FAILED;
- } else {
- if (debug) {
- fprintf(where,"launch_thread: pthread_detach succeed %d\n",rc);
- fflush(where);
- }
- rc = NPE_SUCCESS;
- }
- }
-#endif
return(rc);
}
@@ -1681,11 +1579,7 @@
fprintf(where,"Sleeping on getaddrinfo EAI_AGAIN\n");
fflush(where);
}
-#ifdef WITH_GLIB
g_usleep(1000);
-#else
- sleep(1);
-#endif
}
} while ((error == EAI_AGAIN) && (count <= 5));
@@ -1828,11 +1722,7 @@
fprintf(where,"Sleeping on getaddrinfo EAI_AGAIN\n");
fflush(where);
}
-#ifdef WITH_GLIB
g_usleep(1000);
-#else
- sleep(1);
-#endif
}
} while ((error == EAI_AGAIN) && (count <= 5));
@@ -1873,11 +1763,7 @@
count);
fflush(where);
}
-#ifdef WITH_GLIB
g_usleep(1000);
-#else
- sleep(1);
-#endif
}
} while ((error == EAI_AGAIN) && (count <= 5));
@@ -2030,11 +1916,7 @@
netperf->source = source;
netperf->state = NSRV_PREINIT;
netperf->state_req = NSRV_WORK;
-#ifdef WITH_GLIB
netperf->thread_id = NULL;
-#else
- netperf->thread_id = -1;
-#endif
netperf->next = NULL;
add_server_to_specified_hash(global_state->server_hash, netperf, FALSE);
Modified: branches/glib_migration/src/netlib.h
===================================================================
--- branches/glib_migration/src/netlib.h 2006-03-30 00:31:33 UTC (rev 110)
+++ branches/glib_migration/src/netlib.h 2006-03-30 00:56:12 UTC (rev 111)
@@ -40,9 +40,7 @@
#include "config.h"
#endif
-#ifdef WITH_GLIB
#include <glib.h>
-#endif
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
@@ -106,11 +104,7 @@
const xmlChar *fromnid);
extern int32_t recv_control_message(int control_sock, xmlDocPtr *message);
extern void report_server_error(server_t *server);
-#ifdef WITH_GLIB
extern int launch_thread(GThread **tid, void *(*start_routine)(void *), void *data);
-#else
-extern int launch_thread(pthread_t *tid, void *(*start_routine)(void *), void *data);
-#endif
extern int set_thread_locality(test_t *test, char *loc_type, char *loc_value);
extern void break_args_explicit(char *s, char *arg1, char *arg2);
extern int parse_address_family(char family_string[]);
Modified: branches/glib_migration/src/netmsg.c
===================================================================
--- branches/glib_migration/src/netmsg.c 2006-03-30 00:31:33 UTC (rev 110)
+++ branches/glib_migration/src/netmsg.c 2006-03-30 00:56:12 UTC (rev 111)
@@ -595,15 +595,7 @@
test->state = TEST_IDLE;
/* I'd have liked to have abstracted this with the NETPERF_mumble
macros, but the return values differ. raj 2006-03-02 */
-#ifdef WITH_GLIB
g_cond_broadcast(test_hash[hash_value].condition);
-#else
- rc = pthread_cond_broadcast(test_hash[hash_value].condition);
- if (debug) {
- fprintf(where," new_state = %d\n",test->state);
- fflush(where);
- }
-#endif
}
if (debug) {
fprintf(where,"np_idle_message: unlocking mutex\n");
@@ -760,16 +752,10 @@
/* since the different cond broadcast calls return different
things, we cannot use the nice NETPERF_mumble abstractions. */
-#ifdef WITH_GLIB
g_cond_broadcast(test_hash[hash_value].condition);
-#else
- rc = NETPERF_COND_BROADCAST(test_hash[hash_value].condition);
-
-#endif
-
if (debug) {
fprintf(where," new_state = %d rc = %d\n",test->state,rc);
fflush(where);
Modified: branches/glib_migration/src/netperf.c
===================================================================
--- branches/glib_migration/src/netperf.c 2006-03-30 00:31:33 UTC (rev 110)
+++ branches/glib_migration/src/netperf.c 2006-03-30 00:56:12 UTC (rev 111)
@@ -43,15 +43,9 @@
#include <stdio.h>
#endif
-#ifdef WITH_GLIB
# ifdef HAVE_GLIB_H
# include <glib.h>
# endif
-#else
-# ifdef HAVE_PTHREAD_H
-# include <pthread.h>
-# endif
-#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
@@ -377,7 +371,6 @@
for (i = 0; i < SERVER_HASH_BUCKETS; i++) {
server_hash[i].server = NULL;
-#ifdef WITH_GLIB
server_hash[i].hash_lock = g_mutex_new();
if (NULL == server_hash[i].hash_lock) {
/* not sure we will even get here */
@@ -392,43 +385,10 @@
fflush(where);
exit(-2);
}
-#else
- server_hash[i].hash_lock =
- (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t));
-
- if (NULL == server_hash[i].hash_lock) {
- fprintf(where, "%s: unable to malloc a mutex \n",__func__);
- fflush(where);
- exit(-2);
- }
-
- rc = pthread_mutex_init(server_hash[i].hash_lock, NULL);
- if (rc) {
- fprintf(where, "%s: pthread_mutex_init error %d\n",__func__,rc);
- fflush(where);
- exit(-2);
- }
- server_hash[i].condition =
- (pthread_cond_t *)malloc(sizeof(pthread_cond_t));
-
- if (NULL == server_hash[i].condition) {
- fprintf(where, "%s: unable to malloc a pthread_cond_t \n",__func__);
- fflush(where);
- exit(-2);
- }
-
- rc = pthread_cond_init((server_hash[i].condition), NULL);
- if (rc) {
- fprintf(where, "netperf_init: pthread_cond_init error %d\n",rc);
- fflush(where);
- exit(-2);
- }
-#endif
}
for (i = 0; i < TEST_HASH_BUCKETS; i ++) {
test_hash[i].test = NULL;
-#ifdef WITH_GLIB
test_hash[i].hash_lock = g_mutex_new();
if (NULL == test_hash[i].hash_lock) {
/* not sure we will even get here */
@@ -443,39 +403,6 @@
fflush(where);
exit(-2);
}
-#else
- test_hash[i].hash_lock =
- (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t));
-
- if (NULL == test_hash[i].hash_lock) {
- fprintf(where, "%s: unable to malloc a mutex \n",__func__);
- fflush(where);
- exit(-2);
- }
-
- rc = pthread_mutex_init(test_hash[i].hash_lock, NULL);
- if (rc) {
- fprintf(where, "netperf_init: pthread_mutex_init error %d\n",rc);
- fflush(where);
- exit(-2);
- }
-
- test_hash[i].condition =
- (pthread_cond_t *)malloc(sizeof(pthread_cond_t));
-
- if (NULL == test_hash[i].condition) {
- fprintf(where, "netperf_init: unable to malloc a pthread_cond_t \n");
- fflush(where);
- exit(-2);
- }
-
- rc = pthread_cond_init((test_hash[i].condition), NULL);
- if (rc) {
- fprintf(where, "netperf_init: pthread_cond_init error %d\n",rc);
- fflush(where);
- exit(-2);
- }
-#endif
}
/* you know, it might not be a bad idea to also properly initialize
@@ -483,7 +410,6 @@
for (i = 0; i < TEST_SET_HASH_BUCKETS; i ++) {
test_set_hash[i].test_set = NULL;
-#ifdef WITH_GLIB
test_set_hash[i].hash_lock = g_mutex_new();
if (NULL == test_set_hash[i].hash_lock) {
/* not sure we will even get here */
@@ -498,39 +424,6 @@
fflush(where);
exit(-2);
}
-#else
- test_set_hash[i].hash_lock =
- (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t));
-
- if (NULL == test_set_hash[i].hash_lock) {
- fprintf(where, "%s: unable to malloc a mutex \n",__func__);
- fflush(where);
- exit(-2);
- }
-
- rc = pthread_mutex_init(test_set_hash[i].hash_lock, NULL);
- if (rc) {
- fprintf(where, "netperf_init: pthread_mutex_init error %d\n",rc);
- fflush(where);
- exit(-2);
- }
-
- test_set_hash[i].condition =
- (pthread_cond_t *)malloc(sizeof(pthread_cond_t));
-
- if (NULL == test_set_hash[i].condition) {
- fprintf(where, "netperf_init: unable to malloc a pthread_cond_t \n");
- fflush(where);
- exit(-2);
- }
-
- rc = pthread_cond_init((test_set_hash[i].condition), NULL);
- if (rc) {
- fprintf(where, "netperf_init: pthread_cond_init error %d\n",rc);
- fflush(where);
- exit(-2);
- }
-#endif
}
netlib_init();
@@ -847,17 +740,7 @@
new_server->id = netserverid;
if (add_server_to_hash(new_server) == NPE_SUCCESS) {
new_server->node = this_netserver;
-#ifdef WITH_GLIB
g_static_rw_lock_init(&new_server->rwlock);
-#else
- rc = pthread_rwlock_init(&new_server->rwlock, NULL);
- if (rc) {
- fprintf(where, "instaniate_netservers: ");
- fprintf(where, "pthread_rwlock_init error %d\n", rc);
- fflush(where);
- rc = NPE_PTHREAD_RWLOCK_INIT_FAILED;
- }
-#endif
if (rc == NPE_SUCCESS) {
rc = instantiate_tests(this_netserver, new_server);
}
@@ -1070,21 +953,9 @@
NETPERF_MUTEX_LOCK(h->hash_lock);
-#ifdef WITH_GLIB
g_get_current_time(&abstime);
g_time_val_add(&abstime,1000);
g_cond_timed_wait(h->condition, h->hash_lock, &abstime);
-#else
- get_expiration_time(&delta_time,&abstime);
-
-
- rc = pthread_cond_timedwait(h->condition, h->hash_lock, &abstime);
- if (debug) {
- fprintf(where,
- "resolve_dependency: pthread_cond_wait exited %d\n",rc);
- fflush(where);
- }
-#endif
} /* end wait */
/* test has reached at least the TEST_INIT state */
@@ -1408,20 +1279,9 @@
break;
}
/* test is not yet initialized wait for it */
-#ifdef WITH_GLIB
g_get_current_time(&abstime);
g_time_val_add(&abstime,1000);
g_cond_timed_wait(h->condition, h->hash_lock, &abstime);
-#else
- get_expiration_time(&delta_time,&abstime);
-
- prc = pthread_cond_timedwait(h->condition, h->hash_lock, &abstime);
- if (debug && (prc != 0)) {
- fprintf(where,
- "wait_for_tests_to_initialize: thread conditional wait returned %d\n",prc);
- fflush(where);
- }
-#endif
/* since the mutex was unlocked during the conditional wait
should the hash chain be restarted in case a new test was
inserted ? */
@@ -2253,9 +2113,7 @@
program_name = argv[0];
-#ifdef WITH_GLIB
g_thread_init(NULL);
-#endif
where = stderr;
Modified: branches/glib_migration/src/netperf.h
===================================================================
--- branches/glib_migration/src/netperf.h 2006-03-30 00:31:33 UTC (rev 110)
+++ branches/glib_migration/src/netperf.h 2006-03-30 00:56:12 UTC (rev 111)
@@ -68,7 +68,6 @@
#include <ws2tcpip.h>
#endif
-#ifdef WITH_GLIB
#include <glib.h>
#include <glib/gstdio.h>
#include <glib/gprintf.h>
@@ -86,25 +85,6 @@
#define NETPERF_RWLOCK_WRITER_UNLOCK g_static_rw_lock_writer_unlock
#define NETPERF_STAT g_stat
#define NETPERF_SNPRINTF g_snprintf
-#elif defined(HAVE_PTHREAD_H)
-#include <pthread.h>
-#define NETPERF_MUTEX_T pthread_mutex_t
-#define NETPERF_RWLOCK_T pthread_rwlock_t
-#define NETPERF_THREAD_T pthread_t
-#define NETPERF_COND_T pthread_cond_t
-#define NETPERF_ABS_TIMESPEC struct timespec
-#define NETPERF_ABS_TIMESET(base,a,b) base.tv_sec = a;base.tv_nsec=b;
-#define NETPERF_MUTEX_LOCK pthread_mutex_lock
-#define NETPERF_MUTEX_UNLOCK pthread_mutex_unlock
-#define NETPERF_COND_TIMEDWAIT pthread_cond_timedwait
-#define NETPERF_COND_BROADCAST pthread_cond_broadcast
-#define NETPERF_RWLOCK_WRLOCK pthread_rwlock_wrlock
-#define NETPERF_RWLOCK_WRITER_UNLOCK pthread_rwlock_unlock
-#define NETPERF_STAT stat
-#define NETPERF_SNPRINTF snprintf
-#else
-#error Netperf4 requires either glib or pthreads
-#endif
#define NETPERF_RING_BUFFER_STRING "netperf4 ring data"
Modified: branches/glib_migration/src/netserver.c
===================================================================
--- branches/glib_migration/src/netserver.c 2006-03-30 00:31:33 UTC (rev 110)
+++ branches/glib_migration/src/netserver.c 2006-03-30 00:56:12 UTC (rev 111)
@@ -35,11 +35,7 @@
#include "config.h"
#endif
-#ifdef WITH_GLIB
# include <glib.h>
-#else
-# error sorry, this netserver requires glib
-#endif
#ifdef HAVE_STDIO_H
#include <stdio.h>
@@ -899,7 +895,6 @@
for (i = 0; i < NETPERF_HASH_BUCKETS; i++) {
netperf_hash[i].server = NULL;
-#ifdef WITH_GLIB
netperf_hash[i].hash_lock = g_mutex_new();
if (NULL == netperf_hash[i].hash_lock) {
/* not sure we will even get here */
@@ -914,44 +909,10 @@
fflush(where);
exit(-2);
}
-#else
- netperf_hash[i].hash_lock =
- (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t));
-
- if (NULL == netperf_hash[i].hash_lock) {
- g_fprintf(where, "%s: unable to malloc a mutex \n",__func__);
- fflush(where);
- exit(-2);
- }
-
- rc = pthread_mutex_init(netperf_hash[i].hash_lock, NULL);
- if (rc) {
- g_fprintf(where, "%s: server pthread_mutex_init error %d\n", __func__, rc);
- fflush(where);
- exit(rc);
- }
-
- netperf_hash[i].condition =
- (pthread_cond_t *)malloc(sizeof(pthread_cond_t));
-
- if (NULL == netperf_hash[i].condition) {
- g_fprintf(where, "%s: unable to malloc a pthread_cond_t \n",__func__);
- fflush(where);
- exit(-2);
- }
-
- rc = pthread_cond_init(netperf_hash[i].condition, NULL);
- if (rc) {
- g_fprintf(where, "%s: server pthread_cond_init error %d\n", __func__, rc);
- fflush(where);
- exit(rc);
- }
-#endif
}
for (i = 0; i < TEST_HASH_BUCKETS; i ++) {
test_hash[i].test = NULL;
-#ifdef WITH_GLIB
test_hash[i].hash_lock = g_mutex_new();
if (NULL == test_hash[i].hash_lock) {
/* not sure we will even get here */
@@ -966,38 +927,6 @@
fflush(where);
exit(-2);
}
-#else
- test_hash[i].hash_lock =
- (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t));
-
- if (NULL == test_hash[i].hash_lock) {
- g_fprintf(where, "%s: unable to malloc a mutex \n",__func__);
- fflush(where);
- exit(-2);
- }
-
- rc = pthread_mutex_init(test_hash[i].hash_lock, NULL);
- if (rc) {
- g_fprintf(where, "%s: test pthread_mutex_init error %d\n", __func__, rc);
- fflush(where);
- exit(rc);
- }
- test_hash[i].condition =
- (pthread_cond_t *)malloc(sizeof(pthread_cond_t));
-
- if (NULL == test_hash[i].condition) {
- g_fprintf(where, "%s: unable to malloc a pthread_cond_t \n",__func__);
- fflush(where);
- exit(-2);
- }
-
- rc = pthread_cond_init(test_hash[i].condition, NULL);
- if (rc) {
- g_fprintf(where, "%s: test pthread_cond_init error %d\n", __func__, rc);
- fflush(where);
- exit(rc);
- }
-#endif
}
netlib_init();
@@ -1059,9 +988,7 @@
program_name = argv[0];
-#ifdef WITH_GLIB
g_thread_init(NULL);
-#endif
/* save-off the initial command-line stuff in case we need it for
daemonizing or spawning after an accept */
More information about the netperf-dev
mailing list