rev 750 - in trunk: include/prothon modules/Prosist src

SVN User <[email protected]> Sun, 18 Jul 2004 04:34:05 -0400
Newsgroups gmane.comp.lang.prothon.cvs
Message-ID <[email protected]>
Author: mark
Date: 2004-07-18 04:34:02 -0400 (Sun, 18 Jul 2004)
New Revision: 750

Modified:
   trunk/include/prothon/prothon.h
   trunk/modules/Prosist/Prosist.c
   trunk/src/interp.c
   trunk/src/lock.c
   trunk/src/ob_malloc.c
   trunk/src/object.c
Log:
restructured object and ob_malloc for new object scanning, things may be broken

Modified: trunk/include/prothon/prothon.h
===================================================================
--- trunk/include/prothon/prothon.h	2004-07-18 04:26:50 UTC (rev 749)
+++ trunk/include/prothon/prothon.h	2004-07-18 08:34:02 UTC (rev 750)
@@ -246,13 +246,14 @@
 
 typedef struct obj_s {
 	objb_p			body;
+	obj_state_t		state			:2;
+	unsigned		scanned			:1;
+	unsigned		occupied		:1;
+	unsigned		del_locked		:1;
+	unsigned		wrlock_req_cnt	:11;
+	unsigned		rdlock_cnt		:16;
+	i32_t			wrlock;
 	objb_p			saved_body;
-	i32_t			wrlock;
-	unsigned		rdlock_cnt		:16;
-	unsigned		wrlock_req_cnt	:12;
-	unsigned		del_locked		:1;
-	unsigned		scanned			:1;
-	obj_state_t		state			:2;
 	obj_p			next_obj;
 } obj_t;
 

Modified: trunk/modules/Prosist/Prosist.c
===================================================================
--- trunk/modules/Prosist/Prosist.c	2004-07-18 04:26:50 UTC (rev 749)
+++ trunk/modules/Prosist/Prosist.c	2004-07-18 08:34:02 UTC (rev 750)
@@ -494,8 +494,7 @@
 			if (obj->body->data_type == DATA_TYPE_DATAPTR && obj->body->data.ptr) {
 				pr_free(obj->body->data.ptr);
 			}
-			memcpy(obj, res, sizeof(*obj)-2*sizeof(obj->next_obj));
-			obj->body->data = res->body->data;
+			memcpy(obj->body, res->body, sizeof(objb_t));
 			read_lock(ist, obj);
 		}
 	}

Modified: trunk/src/interp.c
===================================================================
--- trunk/src/interp.c	2004-07-18 04:26:50 UTC (rev 749)
+++ trunk/src/interp.c	2004-07-18 08:34:02 UTC (rev 750)
@@ -901,8 +901,6 @@
 		exc_exc_loc	= p->exc_loc;
 	}
 	while(TRUE){
-		if (debug_obj && (debug_obj->next_obj == debug_obj))
-			raise_exception(ist, OBJ(INTERPRETER_EXC), "DEBUG FAILURE");
 		while (have_exstk && (fr_pc <= exc_try_loc || fr_pc >= exc_exc_loc)) {
 			if (exc_final && fr_pc != exc_exc_loc) {
 				exc_final_return = fr_pc;

Modified: trunk/src/lock.c
===================================================================
--- trunk/src/lock.c	2004-07-18 04:26:50 UTC (rev 749)
+++ trunk/src/lock.c	2004-07-18 08:34:02 UTC (rev 750)
@@ -413,6 +413,9 @@
 }
 
 void del_unlock(obj_p obj) {
+	get_wrlock(obj, NO_WAIT);
+	obj->del_locked = FALSE; 
+	free_wrlock(obj);
 }
 
 int is_del_locked(obj_p obj) {

Modified: trunk/src/ob_malloc.c
===================================================================
--- trunk/src/ob_malloc.c	2004-07-18 04:26:50 UTC (rev 749)
+++ trunk/src/ob_malloc.c	2004-07-18 08:34:02 UTC (rev 750)
@@ -54,20 +54,17 @@
 
 #include "object.h"
 
-#undef  uchar
-#define uchar			u8_t	/* assuming == 8 bits  */
-#undef  ushort
-#define ushort			u16_t	/* assuming >= 16 bits */
-#undef  uint
-#define uint			u32_t	/* assuming >= 16 bits */
-#undef  ulong
-#define ulong			u32_t	/* assuming >= 32 bits */
 
+DECLARE_PR_LOCK(ob_malloc_lock);
+#define LOCK()	 pr_lock(&ob_malloc_lock)
+#define UNLOCK() pr_unlock(&ob_malloc_lock)
 
 typedef struct pool_hdr_s {
 	struct pool_hdr_s*	next;
 	struct pool_hdr_s*	prev;
-	uchar*				free;
+	struct pool_hdr_s*	objpool_next;
+	struct pool_hdr_s*	objpool_prev;
+	u8_t*				free;
 	u32_t				magic;
 	u16_t				count;
 	u16_t				capacity;
@@ -89,36 +86,34 @@
 
 #define POOL_MAGIC		  0x82dc3a7d
 
-DECLARE_PR_LOCK(ob_malloc_lock);
-#define LOCK()	 pr_lock(&ob_malloc_lock)
-#define UNLOCK() pr_unlock(&ob_malloc_lock)
+static u32_t  obj_size[2] = {OBJP_SIZE, OBJB_SIZE};
+static u32_t  arena_cnt   = 0;		        /* number of allocated arenas */
+static u32_t  watermark   = ARENA_NB_POOLS;	/* number of pools allocated from the current arena */
+static u8_t* arenalist  = NULL;		    /* list of allocated arenas */
+static u8_t* arenaproto = NULL;		    /* free space start address in current arena */
 
-static uint  obj_size[2] = {OBJP_SIZE, OBJB_SIZE};
-static uint  arena_cnt   = 0;		        /* number of allocated arenas */
-static uint  watermark   = ARENA_NB_POOLS;	/* number of pools allocated from the current arena */
-static uchar* arenalist  = NULL;		    /* list of allocated arenas */
-static uchar* arenaproto = NULL;		    /* free space start address in current arena */
-
 static pool_hdr_p obj_inuse[4] = { (pool_hdr_p)&obj_inuse[0], (pool_hdr_p)&obj_inuse[0], 
                                    (pool_hdr_p)&obj_inuse[2], (pool_hdr_p)&obj_inuse[2] };
 
 static pool_hdr_p freepools = NULL;
 
-uchar* ob_malloc(int is_body) {
-	uchar* res;
+static pool_hdr_p obj_pool_list[2] = {(pool_hdr_p)&obj_pool_list[0], (pool_hdr_p)&obj_pool_list[0]};
+
+u8_t* ob_malloc(int is_body) {
+	u8_t* res;
 	pool_hdr_p pool, next;
 	LOCK();
 	pool = obj_inuse[is_body*2];
 	if (pool->next != pool) {
 		pool->count++;
 		res = pool->free;
-		if ((pool->free = *(uchar**)res) != NULL) {
+		if ((pool->free = *(u8_t**)res) != NULL) {
 			UNLOCK();
 			return res;
 		}
 		if (pool->count < pool->capacity) {
-			pool->free = (uchar*)pool + POOL_HDR_SIZE + pool->count * obj_size[is_body];
-			*(uchar**)(pool->free) = NULL;
+			pool->free = (u8_t*)pool + POOL_HDR_SIZE + pool->count * obj_size[is_body];
+			*(u8_t**)(pool->free) = NULL;
 			UNLOCK();
 			return res;
 		}
@@ -141,9 +136,15 @@
 		pool->magic = POOL_MAGIC;
 		pool->count = 1;
 		pool->is_body = is_body;
-		res = (uchar*)pool + POOL_HDR_SIZE;
+		if (!is_body) {
+			pool->objpool_next =  obj_pool_list[0];
+			pool->objpool_prev = (pool_hdr_p)&obj_pool_list[0];
+			obj_pool_list[0]->prev = pool;
+			obj_pool_list[0] = pool;
+		}
+		res = (u8_t*)pool + POOL_HDR_SIZE;
 		pool->free = res + obj_size[is_body];
-		*(uchar**)(pool->free) = NULL;
+		*(u8_t**)(pool->free) = NULL;
 		pool->capacity = (POOL_SIZE - POOL_HDR_SIZE) / obj_size[is_body];
 		UNLOCK();
 		return res;
@@ -160,7 +161,7 @@
 		UNLOCK();
 		return malloc(sizeof(obj_t));
 	}
-	*(uchar**)res = arenalist;
+	*(u8_t**)res = arenalist;
 	arenalist = res;
 	arena_cnt++;
 	watermark = 0;
@@ -173,14 +174,15 @@
 	size_t offset;
 	int is_body;
 
-	if (p == NULL) return;
 	offset = (size_t) p & POOL_SIZE_MASK;
-	pool = (pool_hdr_p )((uchar*)p - offset);
+	pool = (pool_hdr_p )((u8_t*)p - offset);
 	pr_assert(pool->magic == POOL_MAGIC);
 
 	LOCK();
-	if ((*(uchar**)p = pool->free) == NULL) {
-		pool->free = (uchar*)p;
+	*((u8_t**)p+1) = NULL;
+	is_body = pool->is_body;
+	if ((*(u8_t**)p = pool->free) == NULL) {
+		pool->free = (u8_t*)p;
 		--pool->count;
 		is_body = pool->is_body;
 		next = obj_inuse[is_body*2];
@@ -192,11 +194,15 @@
 		UNLOCK();
 		return;
 	}
-	pool->free = (uchar*)p;
+	pool->free = (u8_t*)p;
 	if (--pool->count != 0) {
 		UNLOCK();
 		return;
 	}
+	if (!is_body) {
+		pool->objpool_next->prev = pool->objpool_prev;
+		pool->objpool_prev->next = pool->objpool_next;
+	}
 	next = pool->next;
 	prev = pool->prev;
 	next->prev = prev;

Modified: trunk/src/object.c
===================================================================
--- trunk/src/object.c	2004-07-18 04:26:50 UTC (rev 749)
+++ trunk/src/object.c	2004-07-18 08:34:02 UTC (rev 750)
@@ -297,6 +297,7 @@
 	memset(obj, 0, sizeof(obj_t));
 	memset(objb, 0, sizeof(objb_t));
 	obj->body = objb;
+	obj->occupied = TRUE;
 	if (!proto) proto = OBJ(OBJECT);
 	obj->body->rd_access = ACC_GUEST;
 	if (ist)