[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r25655 - gnunet/src/testbed
From: |
gnunet |
Subject: |
[GNUnet-SVN] r25655 - gnunet/src/testbed |
Date: |
Thu, 27 Dec 2012 14:26:49 +0100 |
Author: harsha
Date: 2012-12-27 14:26:49 +0100 (Thu, 27 Dec 2012)
New Revision: 25655
Modified:
gnunet/src/testbed/gnunet-service-testbed.c
gnunet/src/testbed/testbed_api_hosts.c
gnunet/src/testbed/testbed_api_operations.c
Log:
- use GNUNET_array_grow()
Modified: gnunet/src/testbed/gnunet-service-testbed.c
===================================================================
--- gnunet/src/testbed/gnunet-service-testbed.c 2012-12-27 13:12:27 UTC (rev
25654)
+++ gnunet/src/testbed/gnunet-service-testbed.c 2012-12-27 13:26:49 UTC (rev
25655)
@@ -920,22 +920,22 @@
/**
* The size of the host list
*/
-static uint32_t host_list_size;
+static unsigned int host_list_size;
/**
* The size of the route list
*/
-static uint32_t route_list_size;
+static unsigned int route_list_size;
/**
* The size of directly linked neighbours list
*/
-static uint32_t slave_list_size;
+static unsigned int slave_list_size;
/**
* The size of the peer list
*/
-static uint32_t peer_list_size;
+static unsigned int peer_list_size;
/*********/
/* Tasks */
@@ -1024,21 +1024,27 @@
/**
- * Similar to GNUNET_realloc; however clears tail part of newly allocated
memory
+ * Similar to GNUNET_array_grow(); however instead of calling
GNUNET_array_grow()
+ * several times we call it only once. The array is also made to grow in steps
+ * of LIST_GROW_STEP.
*
- * @param ptr the memory block to realloc
- * @param size the size of ptr
- * @param new_size the size to which ptr has to be realloc'ed
- * @return the newly reallocated memory block
+ * @param ptr the array pointer to grow
+ * @param size the size of array
+ * @param accommodate_size the size which the array has to accommdate; after
+ * this call the array will be big enough to accommdate sizes upto
+ * accommodate_size
*/
-static void *
-TESTBED_realloc (void *ptr, size_t size, size_t new_size)
-{
- ptr = GNUNET_realloc (ptr, new_size);
- if (new_size > size)
- (void) memset (ptr + size, 0, new_size - size);
- return ptr;
-}
+#define array_grow_large_enough(ptr, size, accommodate_size) \
+ do \
+ { \
+ unsigned int growth_size; \
+ GNUNET_assert (size <= accommodate_size); \
+ growth_size = size; \
+ while (growth_size <= accommodate_size) \
+ growth_size += LIST_GROW_STEP; \
+ GNUNET_array_grow (ptr, size, growth_size); \
+ GNUNET_assert (size > accommodate_size); \
+ } while (0)
/**
@@ -1052,20 +1058,10 @@
host_list_add (struct GNUNET_TESTBED_Host *host)
{
uint32_t host_id;
- uint32_t orig_size;
host_id = GNUNET_TESTBED_host_get_id_ (host);
- orig_size = host_list_size;
if (host_list_size <= host_id)
- {
- while (host_list_size <= host_id)
- host_list_size += LIST_GROW_STEP;
- host_list =
- TESTBED_realloc (host_list,
- sizeof (struct GNUNET_TESTBED_Host *) * orig_size,
- sizeof (struct GNUNET_TESTBED_Host *)
- * host_list_size);
- }
+ array_grow_large_enough (host_list, host_list_size, host_id);
if (NULL != host_list[host_id])
{
LOG_DEBUG ("A host with id: %u already exists\n", host_id);
@@ -1084,18 +1080,8 @@
static void
route_list_add (struct Route *route)
{
- uint32_t orig_size;
-
- orig_size = route_list_size;
if (route->dest >= route_list_size)
- {
- while (route->dest >= route_list_size)
- route_list_size += LIST_GROW_STEP;
- route_list =
- TESTBED_realloc (route_list,
- sizeof (struct Route *) * orig_size,
- sizeof (struct Route *) * route_list_size);
- }
+ array_grow_large_enough (route_list, route_list_size, route->dest);
GNUNET_assert (NULL == route_list[route->dest]);
route_list[route->dest] = route;
}
@@ -1109,17 +1095,8 @@
static void
slave_list_add (struct Slave *slave)
{
- uint32_t orig_size;
-
- orig_size = slave_list_size;
if (slave->host_id >= slave_list_size)
- {
- while (slave->host_id >= slave_list_size)
- slave_list_size += LIST_GROW_STEP;
- slave_list =
- TESTBED_realloc (slave_list, sizeof (struct Slave *) * orig_size,
- sizeof (struct Slave *) * slave_list_size);
- }
+ array_grow_large_enough (slave_list, slave_list_size, slave->host_id);
GNUNET_assert (NULL == slave_list[slave->host_id]);
slave_list[slave->host_id] = slave;
}
@@ -1133,17 +1110,8 @@
static void
peer_list_add (struct Peer *peer)
{
- uint32_t orig_size;
-
- orig_size = peer_list_size;
if (peer->id >= peer_list_size)
- {
- while (peer->id >= peer_list_size)
- peer_list_size += LIST_GROW_STEP;
- peer_list =
- TESTBED_realloc (peer_list, sizeof (struct Peer *) * orig_size,
- sizeof (struct Peer *) * peer_list_size);
- }
+ array_grow_large_enough (peer_list, peer_list_size, peer->id);
GNUNET_assert (NULL == peer_list[peer->id]);
peer_list[peer->id] = peer;
}
@@ -1157,8 +1125,8 @@
static void
peer_list_remove (struct Peer *peer)
{
+ unsigned int orig_size;
uint32_t id;
- uint32_t orig_size;
peer_list[peer->id] = NULL;
orig_size = peer_list_size;
Modified: gnunet/src/testbed/testbed_api_hosts.c
===================================================================
--- gnunet/src/testbed/testbed_api_hosts.c 2012-12-27 13:12:27 UTC (rev
25654)
+++ gnunet/src/testbed/testbed_api_hosts.c 2012-12-27 13:26:49 UTC (rev
25655)
@@ -127,7 +127,7 @@
/**
* The size of the available hosts list
*/
-static uint32_t host_list_size;
+static unsigned int host_list_size;
/**
@@ -230,7 +230,7 @@
const char *username, uint16_t port)
{
struct GNUNET_TESTBED_Host *host;
- uint32_t new_size;
+ unsigned int new_size;
if ((id < host_list_size) && (NULL != host_list[id]))
{
@@ -246,15 +246,8 @@
while (id >= new_size)
new_size += HOST_LIST_GROW_STEP;
if (new_size != host_list_size)
- {
- host_list =
- GNUNET_realloc (host_list,
- sizeof (struct GNUNET_TESTBED_Host *) * new_size);
- (void) memset (&host_list[host_list_size], 0,
- sizeof (struct GNUNET_TESTBED_Host *) * (new_size -
- host_list_size));
- host_list_size = new_size;
- }
+ GNUNET_array_grow (host_list, host_list_size, new_size);
+ GNUNET_assert (id < host_list_size);
LOG (GNUNET_ERROR_TYPE_DEBUG, "Adding host with id: %u\n", host->id);
host_list[id] = host;
return host;
Modified: gnunet/src/testbed/testbed_api_operations.c
===================================================================
--- gnunet/src/testbed/testbed_api_operations.c 2012-12-27 13:12:27 UTC (rev
25654)
+++ gnunet/src/testbed/testbed_api_operations.c 2012-12-27 13:26:49 UTC (rev
25655)
@@ -292,11 +292,7 @@
entry = GNUNET_malloc (sizeof (struct QueueEntry));
entry->op = operation;
GNUNET_CONTAINER_DLL_insert_tail (queue->head, queue->tail, entry);
- operation->queues =
- GNUNET_realloc (operation->queues,
- sizeof (struct OperationQueue *) *
- (++operation->nqueues));
- operation->queues[operation->nqueues - 1] = queue;
+ GNUNET_array_append (operation->queues, operation->nqueues, queue);
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r25655 - gnunet/src/testbed,
gnunet <=