axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dami...@apache.org
Subject svn commit: r758153 - in /webservices/axis2/branches/c/new_thread_pool-25march2009/util: include/axutil_pool_queue.h src/pool_queue.c
Date Wed, 25 Mar 2009 06:17:19 GMT
Author: damitha
Date: Wed Mar 25 06:17:17 2009
New Revision: 758153

URL: http://svn.apache.org/viewvc?rev=758153&view=rev
Log:
Adding source for pool queue

Added:
    webservices/axis2/branches/c/new_thread_pool-25march2009/util/include/axutil_pool_queue.h
    webservices/axis2/branches/c/new_thread_pool-25march2009/util/src/pool_queue.c

Added: webservices/axis2/branches/c/new_thread_pool-25march2009/util/include/axutil_pool_queue.h
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/new_thread_pool-25march2009/util/include/axutil_pool_queue.h?rev=758153&view=auto
==============================================================================
--- webservices/axis2/branches/c/new_thread_pool-25march2009/util/include/axutil_pool_queue.h
(added)
+++ webservices/axis2/branches/c/new_thread_pool-25march2009/util/include/axutil_pool_queue.h
Wed Mar 25 06:17:17 2009
@@ -0,0 +1,97 @@
+#ifndef AXUTIL_POOL_QUEUE_H
+#define AXUTIL_POOL_QUEUE_H
+#include <stdlib.h>
+#include <axutil_thread_pool.h>
+#define MAX_QUEUE_MEMORY_SIZE 65536
+
+/**
+ * This code maintains jobs using two queues namely job queue and free queue. When a job
is assigned 
+ * to the thread pool it get a free node from the tail of unassigned queue(free queue) and
assign 
+ * the job to it and push it as the head of the job queue. A thread in the pool pop this
job node 
+ * from the head of the job queue and do work. Then it push this free node into the head
of the free 
+ * queue.
+ */
+
+/**
+ * Denote the work queue */
+typedef struct axutil_pool_queue_node
+{
+  axutil_thread_start_t func_to_dispatch;
+  void * func_arg;
+  axutil_thread_start_t cleanup_func;
+  void * cleanup_arg;
+  struct axutil_pool_queue_node * next;
+  struct axutil_pool_queue_node * prev;
+} axutil_pool_queue_node_t;
+
+/**
+ * Denote job in the queue */
+typedef struct axutil_pool_queue_head
+{
+	struct axutil_pool_queue_node * head;
+	struct axutil_pool_queue_node * tail;
+	struct axutil_pool_queue_node * freeHead;
+	struct axutil_pool_queue_node * freeTail;
+	int capacity;
+	int max_capacity;
+} axutil_pool_queue_head_t;
+
+
+AXIS2_EXTERN struct axutil_pool_queue_head * AXIS2_CALL
+axutil_pool_queue_make_queue(
+        int initial_cap);
+
+/**
+ * Add job to the worker queue. This will effectively push the job into the job queue.
+ * If there is a free node in the free queue assign the job to it and push it into the job
queue.
+ * Otherwise if maximum limit for nodes is not exceeded create a new free node and assign
the job
+ * to it and push into the job queue.
+ * @param queue_head pool object
+ * @param func1 job function
+ * @param arg1 arguement for job function
+ * @param func2 error handling function
+ * @param arg2 arguement to error handling function
+ * @return void
+ */
+AXIS2_EXTERN void AXIS2_CALL
+axutil_pool_queue_add_work_order(
+        axutil_pool_queue_head_t *pool_queue, 
+        axutil_thread_start_t func1, 
+        void *arg1, 
+        axutil_thread_start_t func2, 
+        void *arg2);
+
+/**
+ * This will pop jobs from the tail of the job queue. Once the job is retrieved it is considered
+ * a free node and added into the free queue.
+ * @param queue_head pool object
+ * @param func1 job function to be assigned from pooled job
+ * @param arg1 arguement for job function
+ * @param func2 error handling function to be assigned from pooled job
+ * @param arg2 arguement to error handling function
+ * @return void
+ */
+
+AXIS2_EXTERN void AXIS2_CALL
+axutil_pool_queue_get_work_order(
+        axutil_pool_queue_head_t *pool_queue, 
+        axutil_thread_start_t *func1, 
+        void ** arg1, 
+        axutil_thread_start_t *func2, 
+        void **arg2);
+
+/**
+ * If free queque has free nodes to accomodate jobs then this function returns true
+ */
+AXIS2_EXTERN int AXIS2_CALL
+axutil_pool_queue_can_accept_work(
+        struct axutil_pool_queue_head *pool_queue);
+
+/**
+ * If job queue has jobs to be done then this function returns true
+ */
+AXIS2_EXTERN int AXIS2_CALL
+axutil_pool_queue_is_job_available(
+        struct axutil_pool_queue_head *pool_queue);
+
+#endif                          /* AXUTIL_POOL_QUEUE_H */

Added: webservices/axis2/branches/c/new_thread_pool-25march2009/util/src/pool_queue.c
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/c/new_thread_pool-25march2009/util/src/pool_queue.c?rev=758153&view=auto
==============================================================================
--- webservices/axis2/branches/c/new_thread_pool-25march2009/util/src/pool_queue.c (added)
+++ webservices/axis2/branches/c/new_thread_pool-25march2009/util/src/pool_queue.c Wed Mar
25 06:17:17 2009
@@ -0,0 +1,185 @@
+#include <axutil_pool_queue.h>
+#include <stdio.h>
+#define MAX_QUEUE_MEMORY_SIZE 65536
+
+
+AXIS2_EXTERN struct axutil_pool_queue_head * AXIS2_CALL
+axutil_pool_queue_make_queue(
+        int initial_cap)
+{
+	axutil_pool_queue_head_t * pool_queue = 
+        (axutil_pool_queue_head_t *) malloc (sizeof(axutil_pool_queue_head_t));
+	int max_cap = MAX_QUEUE_MEMORY_SIZE / (sizeof(axutil_pool_queue_node_t)),i;
+	axutil_pool_queue_node_t * temp;
+	if(pool_queue == NULL)
+	{
+		perror("Out of memory on malloc\n");
+		exit(2);
+	}
+	if(initial_cap > max_cap)
+	{
+		initial_cap = max_cap;
+	}
+	if(initial_cap == 0)
+	{
+		perror("Attempting to create a queue that holds no work orders\n");
+		exit(2);
+	}
+	pool_queue->capacity =initial_cap;
+	pool_queue->max_capacity = max_cap;
+	pool_queue->head = NULL;
+	pool_queue->tail = NULL;
+	pool_queue->freeHead = (axutil_pool_queue_node_t *) malloc (sizeof(axutil_pool_queue_node_t));
+	if(pool_queue->freeHead == NULL)
+	{
+		perror("Out of memory on malloc\n");
+		exit(2);
+	}
+	pool_queue->freeTail = pool_queue->freeHead;
+
+	/* populate the free queue */
+	for(i = 1;i<=initial_cap;i++)
+	{
+		temp = (axutil_pool_queue_node_t *) malloc (sizeof(axutil_pool_queue_node_t));
+		if(temp == NULL)
+		{
+			perror("Out of memory on malloc\n");
+			exit(2);
+		}
+		temp->next = pool_queue->freeHead;
+		temp->prev = NULL;
+		pool_queue->freeHead->prev = temp;
+		pool_queue->freeHead=temp;
+	}
+
+	return pool_queue;
+}
+
+
+AXIS2_EXTERN void AXIS2_CALL
+axutil_pool_queue_add_work_order(
+        axutil_pool_queue_head_t *pool_queue, 
+        axutil_thread_start_t func1, 
+        void *arg1, 
+        axutil_thread_start_t func2, 
+        void *arg2)
+{
+	axutil_pool_queue_node_t * temp;
+		
+	if(pool_queue->freeTail == NULL)
+	{
+	    temp = (axutil_pool_queue_node_t *) malloc (sizeof(axutil_pool_queue_node_t));
+		if(temp == NULL)
+		{
+			perror("Out of memory on malloc\n");
+			exit(2);
+		}
+		temp->next = NULL;
+		temp->prev = NULL;
+		pool_queue->freeHead = temp;
+		pool_queue->freeTail = temp;
+		pool_queue->capacity++;
+	}
+	
+	temp = pool_queue->freeTail;
+	if(pool_queue->freeTail->prev == NULL)
+	{
+		pool_queue->freeTail = NULL;
+		pool_queue->freeHead = NULL;
+	}
+	else
+	{
+		pool_queue->freeTail->prev->next= NULL;
+		pool_queue->freeTail = pool_queue->freeTail->prev;
+		pool_queue->freeTail->next=NULL;
+	}
+	
+	temp->func_to_dispatch = func1;
+	temp->func_arg = arg1;
+	temp->cleanup_func = func2;
+	temp->cleanup_arg = arg2;
+
+	temp->prev=NULL;
+	if(pool_queue->head == NULL)
+	{
+		pool_queue->tail = temp;
+		pool_queue->head = temp;
+	}
+	else
+	{
+		temp->next=pool_queue->head;
+		pool_queue->head->prev = temp;
+		pool_queue->head=temp;
+	}
+}
+
+
+AXIS2_EXTERN void AXIS2_CALL
+axutil_pool_queue_get_work_order(
+        axutil_pool_queue_head_t *pool_queue, 
+        axutil_thread_start_t *func1, 
+        void **arg1, 
+        axutil_thread_start_t *func2, 
+        void **arg2)
+{
+	axutil_pool_queue_node_t * temp;
+		
+	temp = pool_queue->tail;
+	if(temp == NULL)
+	{
+		perror("Attempting to axutil_pool_queue_get_work_order from an empty queue.\n");
+		exit(2);
+	}
+
+	if(pool_queue->tail->prev == NULL)
+	{
+		pool_queue->tail = NULL;
+		pool_queue->head = NULL;
+	}
+	else
+	{
+		pool_queue->tail->prev->next = NULL;
+		pool_queue->tail = pool_queue->tail->prev;
+		pool_queue->tail->next=NULL;
+	}
+	
+	*func1 = temp->func_to_dispatch;
+	*arg1  = temp->func_arg;
+	*func2 = temp->cleanup_func;
+	*arg2  = temp->cleanup_arg;
+
+	temp->prev=NULL;
+	if(pool_queue->freeHead == NULL)
+	{
+		pool_queue->freeTail = temp;
+		pool_queue->freeHead = temp;
+		temp->prev=NULL;
+		
+	}
+	else
+	{
+		temp->next=pool_queue->freeHead;
+		pool_queue->freeHead->prev = temp;
+		pool_queue->freeHead=temp;
+	}
+}
+
+AXIS2_EXTERN int AXIS2_CALL
+axutil_pool_queue_can_accept_work(
+        struct axutil_pool_queue_head *pool_queue)
+{
+	return(pool_queue->freeTail != NULL
+	       || pool_queue->capacity <= pool_queue->max_capacity);
+}
+
+AXIS2_EXTERN int AXIS2_CALL
+axutil_pool_queue_is_job_available(
+        struct axutil_pool_queue_head *pool_queue)
+{
+  return(pool_queue->tail != NULL);
+}
+
+
+
+
+



Mime
View raw message