harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From var...@apache.org
Subject svn commit: r477136 - in /harmony/enhanced/drlvm/trunk/vm/gc_gen/src/utils: ./ sync_pool.h sync_queue.h sync_stack.h vector_block.h
Date Mon, 20 Nov 2006 10:30:32 GMT
Author: varlax
Date: Mon Nov 20 02:30:28 2006
New Revision: 477136

URL: http://svn.apache.org/viewvc?view=rev&rev=477136
Log:
Adding new files missed in r476946 (HARMONY-2101).

Added:
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/utils/
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/utils/sync_pool.h
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/utils/sync_queue.h
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/utils/sync_stack.h
    harmony/enhanced/drlvm/trunk/vm/gc_gen/src/utils/vector_block.h

Added: harmony/enhanced/drlvm/trunk/vm/gc_gen/src/utils/sync_pool.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/gc_gen/src/utils/sync_pool.h?view=auto&rev=477136
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/gc_gen/src/utils/sync_pool.h (added)
+++ harmony/enhanced/drlvm/trunk/vm/gc_gen/src/utils/sync_pool.h Mon Nov 20 02:30:28 2006
@@ -0,0 +1,94 @@
+/*
+ *  Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/**
+ * @author Xiao-Feng Li, 2006/10/25
+ */
+ 
+#ifndef _SYNC_POOL_H_
+#define _SYNC_POOL_H_
+
+#include "sync_stack.h"
+
+typedef Sync_Stack Pool;
+
+inline Pool* sync_pool_create(unsigned int size){ return sync_stack_init(size); }
+inline void sync_pool_destruct(Pool* pool){ sync_stack_destruct(pool); }
+
+inline Boolean pool_is_empty(Pool* pool){ return stack_entry_count(pool)==0;}
+inline Vector_Block* pool_get_entry(Pool* pool)
+{ 
+  Vector_Block* block = (Vector_Block*)sync_stack_pop(pool);
+  assert( !block || (block->start == (unsigned int*)block->entries) );
+  assert( !block || (block->head <= block->tail && block->tail <=
block->end));
+ 
+  return block;
+}
+
+inline void pool_put_entry(Pool* pool, void* value){ assert(value); Boolean ok = sync_stack_push(pool,
(unsigned int)value); assert(ok);}
+
+inline void pool_iterator_init(Pool* pool){ sync_stack_iterate_init(pool);}
+inline Vector_Block* pool_iterator_next(Pool* pool){ return (Vector_Block*)sync_stack_iterate_next(pool);}
+
+#endif /* #ifndef _SYNC_POOL_H_ */
+
+/*
+ *  Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/**
+ * @author Xiao-Feng Li, 2006/10/25
+ */
+ 
+#ifndef _SYNC_POOL_H_
+#define _SYNC_POOL_H_
+
+#include "sync_stack.h"
+
+typedef Sync_Stack Pool;
+
+inline Pool* sync_pool_create(unsigned int size){ return sync_stack_init(size); }
+inline void sync_pool_destruct(Pool* pool){ sync_stack_destruct(pool); }
+
+inline Boolean pool_is_empty(Pool* pool){ return stack_entry_count(pool)==0;}
+inline Vector_Block* pool_get_entry(Pool* pool)
+{ 
+  Vector_Block* block = (Vector_Block*)sync_stack_pop(pool);
+  assert( !block || (block->start == (unsigned int*)block->entries) );
+  assert( !block || (block->head <= block->tail && block->tail <=
block->end));
+ 
+  return block;
+}
+
+inline void pool_put_entry(Pool* pool, void* value){ assert(value); Boolean ok = sync_stack_push(pool,
(unsigned int)value); assert(ok);}
+
+inline void pool_iterator_init(Pool* pool){ sync_stack_iterate_init(pool);}
+inline Vector_Block* pool_iterator_next(Pool* pool){ return (Vector_Block*)sync_stack_iterate_next(pool);}
+
+#endif /* #ifndef _SYNC_POOL_H_ */
+

Added: harmony/enhanced/drlvm/trunk/vm/gc_gen/src/utils/sync_queue.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/gc_gen/src/utils/sync_queue.h?view=auto&rev=477136
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/gc_gen/src/utils/sync_queue.h (added)
+++ harmony/enhanced/drlvm/trunk/vm/gc_gen/src/utils/sync_queue.h Mon Nov 20 02:30:28 2006
@@ -0,0 +1,260 @@
+/*
+ *  Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/**
+ * @author Xiao-Feng Li, 2006/10/05
+ */
+
+#ifndef _SYNC_QUEUE_H_
+#define _SYNC_QUEUE_H_
+
+/* an implementation of MSQ. FIXME:: only work in 32-bit machine */
+
+struct Queue_Node;
+
+typedef struct Queue_Link{
+	struct Queue_Node* ptr;
+	unsigned int count;
+}Queue_Link;
+
+typedef struct Queue_Node{
+	__declspec(align(8))
+	Queue_Link next; /* must be aligned to 8Byte*/
+	unsigned int* value;
+}Queue_Node;
+
+typedef struct Sync_Queue{
+	__declspec(align(8)) 
+	Queue_Link head; /* must be aligned to 8Byte*/
+	Queue_Link tail; 
+}Sync_Queue;
+
+inline Queue_Node * new_queue_node()
+{
+  Queue_Node* p_node = malloc(sizeof(Queue_Node));
+  assert( (unsigned int)node%8 == 0 );
+  return p_node;
+}
+
+inline void free_queue_node(Queue_Node* node)
+{   free( node ); }
+
+inline void sync_queue_init(Sync_Queue *queue)
+{
+  Queue_Node *node = new_queue_node();
+  node->next.ptr = NULL;
+	node->next.count = 0;
+  queue->head.ptr = queue->tail.ptr = node;
+	queue->head.count = queue->tail.count = 0;
+  return;
+}
+
+#define QLINK_PTR(x) ((unsigned long long*)&(x))
+#define QLINK_VAL(x) (*(QLINK_PTR(x)))
+
+inline void sync_queue_push(Sync_Queue* queue, unsigned int* value)
+{
+	Queue_Link tail, next, tmp1, tmp2;
+	Queue_Node* node = new_queue_node();
+	node->value = value;
+	node->next.ptr = NULL;
+	while(TRUE){
+		QLINK_VAL(tail) = QLINK_VAL(queue->tail);
+		QLINK_VAL(next) = QLINK_VAL(tail.ptr->next);
+		if( QLINK_VAL(tail) == QLINK_VAL(queue->tail)){
+			if( next.ptr==NULL ){
+				tmp1.ptr = node;
+				tmp1.count = next.count + 1;
+				node->next.count = tmp1.count; 
+				QLINK_VAL(tmp2) = atomic_cas64(QLINK_PTR(tail.ptr->next), QLINK_VAL(next), QLINK_VAL(tmp1))
+				if( QLINK_VAL(tmp1) == QLINK_VAL(tmp2))
+				  break;
+				  
+			}else{
+				tmp1.ptr = next.ptr;
+				tmp1.count = tail.count + 1;
+				atomic_cas64(QLINK_PTR(queue->tail), QLINK_VAL(tail), QLINK_VAL(tmp1));
+			}
+		}
+	}
+	tmp1.ptr = node;
+	tmp1.count = tail.count + 1;
+	atomic_cas64(QLINK_PTR(queue->tail), QLINK_VAL(tail), QLINK_VAL(tmp1));
+	return;
+}
+
+Boolean sync_queue_pull(Sync_Queue* queue, unsigned int * pvalue)
+{
+	Queue_Link head, tail, next, tmp1, tmp2;
+	while(TRUE){
+		QLINK_VAL(head) = QLINK_VAL(queue->head);
+		QLINK_VAL(tail) = QLINK_VAL(queue->tail);
+		QLINK_VAL(next) = QLINK_VAL(head.ptr->next);
+		
+		if( QLINK_VAL(head) == QLINK_VAL(queue->head)){
+			if( head.ptr== tail.ptr )
+				if( next.ptr == NULL )
+					return FALSE;
+				else{
+					tmp1.ptr = next.ptr;
+					tmp1.count = tail.count+1;
+        	atomic_cas64(QLINK_PTR(queue->tail), QLINK_VAL(tail), QLINK_VAL(tmp1));
+				}
+			else{
+				*pvalue = next.ptr->value;
+				tmp1.ptr = next.ptr;
+				tmp1.count = head.count+1;
+				QLINK_VAL(tmp2) =	atomic_cas64(QLINK_PTR(queue->head), QLINK_VAL(head), QLINK_VAL(tmp1));
+				if( QLINK_VAL(tmp2) == QLINK_VAL(tmp1))
+					break;
+			}
+		}
+	}
+	free( head.ptr );
+	return TRUE;
+}
+	
+#endif /* _SYNC_QUEUE_H_ */
+/*
+ *  Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/**
+ * @author Xiao-Feng Li, 2006/10/05
+ */
+
+#ifndef _SYNC_QUEUE_H_
+#define _SYNC_QUEUE_H_
+
+/* an implementation of MSQ. FIXME:: only work in 32-bit machine */
+
+struct Queue_Node;
+
+typedef struct Queue_Link{
+	struct Queue_Node* ptr;
+	unsigned int count;
+}Queue_Link;
+
+typedef struct Queue_Node{
+	__declspec(align(8))
+	Queue_Link next; /* must be aligned to 8Byte*/
+	unsigned int* value;
+}Queue_Node;
+
+typedef struct Sync_Queue{
+	__declspec(align(8)) 
+	Queue_Link head; /* must be aligned to 8Byte*/
+	Queue_Link tail; 
+}Sync_Queue;
+
+inline Queue_Node * new_queue_node()
+{
+  Queue_Node* p_node = malloc(sizeof(Queue_Node));
+  assert( (unsigned int)node%8 == 0 );
+  return p_node;
+}
+
+inline void free_queue_node(Queue_Node* node)
+{   free( node ); }
+
+inline void sync_queue_init(Sync_Queue *queue)
+{
+  Queue_Node *node = new_queue_node();
+  node->next.ptr = NULL;
+	node->next.count = 0;
+  queue->head.ptr = queue->tail.ptr = node;
+	queue->head.count = queue->tail.count = 0;
+  return;
+}
+
+#define QLINK_PTR(x) ((unsigned long long*)&(x))
+#define QLINK_VAL(x) (*(QLINK_PTR(x)))
+
+inline void sync_queue_push(Sync_Queue* queue, unsigned int* value)
+{
+	Queue_Link tail, next, tmp1, tmp2;
+	Queue_Node* node = new_queue_node();
+	node->value = value;
+	node->next.ptr = NULL;
+	while(TRUE){
+		QLINK_VAL(tail) = QLINK_VAL(queue->tail);
+		QLINK_VAL(next) = QLINK_VAL(tail.ptr->next);
+		if( QLINK_VAL(tail) == QLINK_VAL(queue->tail)){
+			if( next.ptr==NULL ){
+				tmp1.ptr = node;
+				tmp1.count = next.count + 1;
+				node->next.count = tmp1.count; 
+				QLINK_VAL(tmp2) = atomic_cas64(QLINK_PTR(tail.ptr->next), QLINK_VAL(next), QLINK_VAL(tmp1))
+				if( QLINK_VAL(tmp1) == QLINK_VAL(tmp2))
+				  break;
+				  
+			}else{
+				tmp1.ptr = next.ptr;
+				tmp1.count = tail.count + 1;
+				atomic_cas64(QLINK_PTR(queue->tail), QLINK_VAL(tail), QLINK_VAL(tmp1));
+			}
+		}
+	}
+	tmp1.ptr = node;
+	tmp1.count = tail.count + 1;
+	atomic_cas64(QLINK_PTR(queue->tail), QLINK_VAL(tail), QLINK_VAL(tmp1));
+	return;
+}
+
+Boolean sync_queue_pull(Sync_Queue* queue, unsigned int * pvalue)
+{
+	Queue_Link head, tail, next, tmp1, tmp2;
+	while(TRUE){
+		QLINK_VAL(head) = QLINK_VAL(queue->head);
+		QLINK_VAL(tail) = QLINK_VAL(queue->tail);
+		QLINK_VAL(next) = QLINK_VAL(head.ptr->next);
+		
+		if( QLINK_VAL(head) == QLINK_VAL(queue->head)){
+			if( head.ptr== tail.ptr )
+				if( next.ptr == NULL )
+					return FALSE;
+				else{
+					tmp1.ptr = next.ptr;
+					tmp1.count = tail.count+1;
+        	atomic_cas64(QLINK_PTR(queue->tail), QLINK_VAL(tail), QLINK_VAL(tmp1));
+				}
+			else{
+				*pvalue = next.ptr->value;
+				tmp1.ptr = next.ptr;
+				tmp1.count = head.count+1;
+				QLINK_VAL(tmp2) =	atomic_cas64(QLINK_PTR(queue->head), QLINK_VAL(head), QLINK_VAL(tmp1));
+				if( QLINK_VAL(tmp2) == QLINK_VAL(tmp1))
+					break;
+			}
+		}
+	}
+	free( head.ptr );
+	return TRUE;
+}
+	
+#endif /* _SYNC_QUEUE_H_ */

Added: harmony/enhanced/drlvm/trunk/vm/gc_gen/src/utils/sync_stack.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/gc_gen/src/utils/sync_stack.h?view=auto&rev=477136
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/gc_gen/src/utils/sync_stack.h (added)
+++ harmony/enhanced/drlvm/trunk/vm/gc_gen/src/utils/sync_stack.h Mon Nov 20 02:30:28 2006
@@ -0,0 +1,226 @@
+/*
+ *  Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/**
+ * @author Xiao-Feng Li, 2006/10/25
+ */
+ 
+#ifndef _SYNC_STACK_H_
+#define _SYNC_STACK_H_
+
+typedef struct Sync_Stack{
+  unsigned int* top; /* pointing to the first filled entry */
+  unsigned int* cur; /* pointing to the current accessed entry */
+  unsigned int* bottom; /* pointing to the pos right after the last entry */
+  unsigned int entries[1];
+}Sync_Stack;
+
+inline Sync_Stack* sync_stack_init(unsigned int num_entries)
+{
+  unsigned int size = ((num_entries-1) << 2) + sizeof(Sync_Stack);
+  Sync_Stack* stack = (Sync_Stack*)STD_MALLOC(size);
+  memset(stack, 0, size);
+  stack->bottom = &(stack->entries[num_entries]);
+  stack->top = stack->bottom; 
+  return stack;
+}
+
+inline void sync_stack_destruct(Sync_Stack* stack)
+{
+  STD_FREE(stack);
+  return;  
+}
+
+inline void sync_stack_iterate_init(Sync_Stack* stack)
+{
+  stack->cur = stack->top;
+  return;
+}
+
+inline unsigned int sync_stack_iterate_next(Sync_Stack* stack)
+{
+  unsigned int* entry = stack->cur;
+  unsigned int* new_entry = entry + 1;
+  unsigned int* last_entry = stack->bottom - 1;
+  while ( entry <= last_entry ){
+    unsigned int* temp = (unsigned int*)atomic_casptr((volatile void**)&stack->cur,
new_entry, entry);
+    if(temp == entry){ /* got it */  
+      return *entry;
+    }
+    entry = stack->cur;
+    new_entry = entry + 1;    
+  }  
+  return 0;
+}
+
+inline unsigned int sync_stack_pop(Sync_Stack* stack)
+{
+  volatile unsigned int* entry = stack->top;
+  unsigned int* new_entry = stack->top + 1;
+  unsigned int* last_entry = stack->bottom - 1;
+  while ( entry <= last_entry ){
+    unsigned int* temp = (unsigned int*)atomic_casptr((volatile void**)&stack->top,
new_entry, (const void*)entry);
+    if(temp == entry){ /* got it */ 
+      while(!*entry); /* has to have something */
+      unsigned int result = *entry;
+      *entry = NULL;  /* put NULL into it */
+      return result;
+    }
+    entry = (volatile unsigned int*)stack->top;
+    new_entry = (unsigned int*)(entry + 1);    
+  }  
+  return 0;
+}
+
+inline Boolean sync_stack_push(Sync_Stack* stack, unsigned int value)
+{
+  unsigned int* entry = stack->top;
+  volatile unsigned int* new_entry = stack->top - 1;
+  unsigned int* first_entry = stack->entries;
+  while ( entry >= first_entry ){
+    unsigned int* temp = (unsigned int*)atomic_casptr((volatile void**)&stack->top,
(void*)new_entry, entry);
+    if(temp == entry){ /* got it */  
+      while(*new_entry); /* has to be NULL before filled */
+      *new_entry = value;
+      return TRUE;
+    }
+    entry = stack->top;
+    new_entry = entry - 1;
+  }
+  return FALSE;
+}
+
+/* it does not matter whether this is atomic or not, because
+   it is only invoked when there is no contention or only for rough idea */
+inline unsigned int stack_entry_count(Sync_Stack* stack)
+{
+  return (stack->bottom - stack->top);
+}
+
+#endif /* _SYNC_STACK_H_ */
+/*
+ *  Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/**
+ * @author Xiao-Feng Li, 2006/10/25
+ */
+ 
+#ifndef _SYNC_STACK_H_
+#define _SYNC_STACK_H_
+
+typedef struct Sync_Stack{
+  unsigned int* top; /* pointing to the first filled entry */
+  unsigned int* cur; /* pointing to the current accessed entry */
+  unsigned int* bottom; /* pointing to the pos right after the last entry */
+  unsigned int entries[1];
+}Sync_Stack;
+
+inline Sync_Stack* sync_stack_init(unsigned int num_entries)
+{
+  unsigned int size = ((num_entries-1) << 2) + sizeof(Sync_Stack);
+  Sync_Stack* stack = (Sync_Stack*)STD_MALLOC(size);
+  memset(stack, 0, size);
+  stack->bottom = &(stack->entries[num_entries]);
+  stack->top = stack->bottom; 
+  return stack;
+}
+
+inline void sync_stack_destruct(Sync_Stack* stack)
+{
+  STD_FREE(stack);
+  return;  
+}
+
+inline void sync_stack_iterate_init(Sync_Stack* stack)
+{
+  stack->cur = stack->top;
+  return;
+}
+
+inline unsigned int sync_stack_iterate_next(Sync_Stack* stack)
+{
+  unsigned int* entry = stack->cur;
+  unsigned int* new_entry = entry + 1;
+  unsigned int* last_entry = stack->bottom - 1;
+  while ( entry <= last_entry ){
+    unsigned int* temp = (unsigned int*)atomic_casptr((volatile void**)&stack->cur,
new_entry, entry);
+    if(temp == entry){ /* got it */  
+      return *entry;
+    }
+    entry = stack->cur;
+    new_entry = entry + 1;    
+  }  
+  return 0;
+}
+
+inline unsigned int sync_stack_pop(Sync_Stack* stack)
+{
+  volatile unsigned int* entry = stack->top;
+  unsigned int* new_entry = stack->top + 1;
+  unsigned int* last_entry = stack->bottom - 1;
+  while ( entry <= last_entry ){
+    unsigned int* temp = (unsigned int*)atomic_casptr((volatile void**)&stack->top,
new_entry, (const void*)entry);
+    if(temp == entry){ /* got it */ 
+      while(!*entry); /* has to have something */
+      unsigned int result = *entry;
+      *entry = NULL;  /* put NULL into it */
+      return result;
+    }
+    entry = (volatile unsigned int*)stack->top;
+    new_entry = (unsigned int*)(entry + 1);    
+  }  
+  return 0;
+}
+
+inline Boolean sync_stack_push(Sync_Stack* stack, unsigned int value)
+{
+  unsigned int* entry = stack->top;
+  volatile unsigned int* new_entry = stack->top - 1;
+  unsigned int* first_entry = stack->entries;
+  while ( entry >= first_entry ){
+    unsigned int* temp = (unsigned int*)atomic_casptr((volatile void**)&stack->top,
(void*)new_entry, entry);
+    if(temp == entry){ /* got it */  
+      while(*new_entry); /* has to be NULL before filled */
+      *new_entry = value;
+      return TRUE;
+    }
+    entry = stack->top;
+    new_entry = entry - 1;
+  }
+  return FALSE;
+}
+
+/* it does not matter whether this is atomic or not, because
+   it is only invoked when there is no contention or only for rough idea */
+inline unsigned int stack_entry_count(Sync_Stack* stack)
+{
+  return (stack->bottom - stack->top);
+}
+
+#endif /* _SYNC_STACK_H_ */

Added: harmony/enhanced/drlvm/trunk/vm/gc_gen/src/utils/vector_block.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/gc_gen/src/utils/vector_block.h?view=auto&rev=477136
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/gc_gen/src/utils/vector_block.h (added)
+++ harmony/enhanced/drlvm/trunk/vm/gc_gen/src/utils/vector_block.h Mon Nov 20 02:30:28 2006
@@ -0,0 +1,144 @@
+/*
+ *  Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/**
+ * @author Xiao-Feng Li, 2006/10/25
+ */
+ 
+#ifndef _VECTOR_BLOCK_H_
+#define _VECTOR_BLOCK_H_
+
+typedef struct Vector_Block{
+  unsigned int* start; /* point to first entry, not needed actually */
+  unsigned int* end;   /* point to end of the block (right after the last entry) */
+  unsigned int* head;  /* point to the first filled entry */
+  unsigned int* tail;  /* point to the entry after the last filled one */
+  unsigned int* entries[1];
+}Vector_Block;
+
+inline void vector_block_init(Vector_Block* block, unsigned int size)
+{
+    block->start = (unsigned int*)block->entries;
+    block->end = (unsigned int*)((unsigned int)block + size);
+    block->head = block->start;
+    block->tail = block->start;
+    return;  
+}
+
+inline unsigned int vector_block_entry_count(Vector_Block* block)
+{ return (unsigned int)(block->tail - block->head); }
+
+inline Boolean vector_block_is_full(Vector_Block* block)
+{ return block->tail == block->end; }
+
+inline void vector_block_add_entry(Vector_Block* block, unsigned int value)
+{ 
+  assert(value && !*(block->tail));
+  *(block->tail++) = value; 
+}
+
+inline void vector_block_clear(Vector_Block* block)
+{
+#ifdef _DEBUG
+  memset(block->start, 0, (block->end - block->start)*BYTES_PER_WORD);
+#endif
+
+  block->tail = block->head; 
+}
+
+/* Below is for sequential local access */
+inline unsigned int* vector_block_iterator_init(Vector_Block* block)
+{  return block->head;  }
+
+inline unsigned int* vector_block_iterator_advance(Vector_Block* block, unsigned int* iter)
+{  return ++iter; }
+
+inline Boolean vector_block_iterator_end(Vector_Block* block, unsigned int* iter)
+{  return iter == block->tail; }
+
+#endif /* #ifndef _VECTOR_BLOCK_H_ */
+/*
+ *  Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+/**
+ * @author Xiao-Feng Li, 2006/10/25
+ */
+ 
+#ifndef _VECTOR_BLOCK_H_
+#define _VECTOR_BLOCK_H_
+
+typedef struct Vector_Block{
+  unsigned int* start; /* point to first entry, not needed actually */
+  unsigned int* end;   /* point to end of the block (right after the last entry) */
+  unsigned int* head;  /* point to the first filled entry */
+  unsigned int* tail;  /* point to the entry after the last filled one */
+  unsigned int* entries[1];
+}Vector_Block;
+
+inline void vector_block_init(Vector_Block* block, unsigned int size)
+{
+    block->start = (unsigned int*)block->entries;
+    block->end = (unsigned int*)((unsigned int)block + size);
+    block->head = block->start;
+    block->tail = block->start;
+    return;  
+}
+
+inline unsigned int vector_block_entry_count(Vector_Block* block)
+{ return (unsigned int)(block->tail - block->head); }
+
+inline Boolean vector_block_is_full(Vector_Block* block)
+{ return block->tail == block->end; }
+
+inline void vector_block_add_entry(Vector_Block* block, unsigned int value)
+{ 
+  assert(value && !*(block->tail));
+  *(block->tail++) = value; 
+}
+
+inline void vector_block_clear(Vector_Block* block)
+{
+#ifdef _DEBUG
+  memset(block->start, 0, (block->end - block->start)*BYTES_PER_WORD);
+#endif
+
+  block->tail = block->head; 
+}
+
+/* Below is for sequential local access */
+inline unsigned int* vector_block_iterator_init(Vector_Block* block)
+{  return block->head;  }
+
+inline unsigned int* vector_block_iterator_advance(Vector_Block* block, unsigned int* iter)
+{  return ++iter; }
+
+inline Boolean vector_block_iterator_end(Vector_Block* block, unsigned int* iter)
+{  return iter == block->tail; }
+
+#endif /* #ifndef _VECTOR_BLOCK_H_ */



Mime
View raw message