[PD-cvs] pd/src m_fifo.c,1.1.2.14.2.6.2.1,1.1.2.14.2.6.2.2

Mathieu Bouchard matju at users.sourceforge.net
Tue Jan 9 18:09:46 CET 2007


Update of /cvsroot/pure-data/pd/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4867

Modified Files:
      Tag: desiredata
	m_fifo.c 
Log Message:
freebytes,getbytes -> free,malloc


Index: m_fifo.c
===================================================================
RCS file: /cvsroot/pure-data/pd/src/Attic/m_fifo.c,v
retrieving revision 1.1.2.14.2.6.2.1
retrieving revision 1.1.2.14.2.6.2.2
diff -C2 -d -r1.1.2.14.2.6.2.1 -r1.1.2.14.2.6.2.2
*** m_fifo.c	8 Dec 2006 06:35:17 -0000	1.1.2.14.2.6.2.1
--- m_fifo.c	9 Jan 2007 17:09:44 -0000	1.1.2.14.2.6.2.2
***************
*** 5,10 ****
  
  
! #include "stddef.h"
! 
  #include "m_pd.h"
  #include "m_fifo.h"
--- 5,10 ----
  
  
! #include <stddef.h>
! #include <stdlib.h>
  #include "m_pd.h"
  #include "m_fifo.h"
***************
*** 23,28 ****
  } t_fifocell;
  
! struct _fifo
! {
  	t_fifocell * head;
  	t_fifocell * tail;
--- 23,27 ----
  } t_fifocell;
  
! struct _fifo {
  	t_fifocell * head;
  	t_fifocell * tail;
***************
*** 30,84 ****
  };
  
! 
! t_fifo * fifo_init()
! {
! 	t_fifo* ret = (t_fifo*) getbytes(sizeof (t_fifo));
! 	t_fifocell * fifo_begin = (t_fifocell*) getbytes (sizeof (t_fifocell) );
! 	
! 	fifo_begin->data = NULL;
! 	fifo_begin->next = NULL;
! 
  	ret->head = fifo_begin;
  	ret->tail = fifo_begin;
! 	
! 	pthread_mutex_init(&ret->mutex, NULL);
! 	
  	pthread_mutex_unlock(&ret->mutex);
- 
  	return ret;
  }
  
! void fifo_destroy(t_fifo* fifo)
! {
! 	void * data;
! 	
! 	do
! 	{
! 		data = fifo_get(fifo);
! 	}
! 	while (data != NULL);
! 
  	pthread_mutex_lock(&fifo->mutex);
  	pthread_mutex_destroy(&fifo->mutex);
! 	
! 	freebytes(fifo, sizeof(t_fifo));
  	return;
  }
  
  /* fifo_put and fifo_get are the only threadsafe functions!!! */
! void fifo_put(t_fifo* fifo, void* data)
! {
! 	if (data != NULL)
! 	{
! 		t_fifocell * cell = (t_fifocell*) getbytes(sizeof(t_fifocell));
! 		
  		cell->data = data;
! 		cell->next = NULL;
! 		
  		pthread_mutex_lock(&fifo->mutex);
- 		
  		fifo->tail->next = cell;
  		fifo->tail = cell;
- 		
  		pthread_mutex_unlock(&fifo->mutex);
  	}
--- 29,62 ----
  };
  
! t_fifo *fifo_init(void) {
! 	t_fifo* ret = (t_fifo*)malloc(sizeof(t_fifo));
! 	t_fifocell * fifo_begin = (t_fifocell*)malloc(sizeof(t_fifocell));
! 	fifo_begin->data = 0;
! 	fifo_begin->next = 0;
  	ret->head = fifo_begin;
  	ret->tail = fifo_begin;
! 	pthread_mutex_init(&ret->mutex, 0);
  	pthread_mutex_unlock(&ret->mutex);
  	return ret;
  }
  
! void fifo_destroy(t_fifo* fifo) {
! 	void *data;
! 	do data = fifo_get(fifo); while (data);
  	pthread_mutex_lock(&fifo->mutex);
  	pthread_mutex_destroy(&fifo->mutex);
! 	free(fifo);
  	return;
  }
  
  /* fifo_put and fifo_get are the only threadsafe functions!!! */
! void fifo_put(t_fifo* fifo, void* data) {
! 	if (data) {
! 		t_fifocell * cell = (t_fifocell*)malloc(sizeof(t_fifocell));
  		cell->data = data;
! 		cell->next = 0;
  		pthread_mutex_lock(&fifo->mutex);
  		fifo->tail->next = cell;
  		fifo->tail = cell;
  		pthread_mutex_unlock(&fifo->mutex);
  	}
***************
*** 86,117 ****
  }
  
! 
! /* this fifo_get returns NULL if the fifo is empty 
!  * or locked by another thread */
! void* fifo_get(t_fifo* fifo)
! {
  	t_fifocell * cell;
! 	void* data;
! 	
! 	if(pthread_mutex_trylock(&fifo->mutex) != EBUSY)
! 	{
  		cell = fifo->head->next;
! 
! 		if (cell != NULL)
! 		{
  			fifo->head->next = cell->next;
  			if(cell == fifo->tail)
  				fifo->tail = fifo->head;
  			data = cell->data;
! 			
! 			freebytes (cell, sizeof(t_fifocell));
! 		}
! 		else
! 			data = NULL;
! 
  		pthread_mutex_unlock(&fifo->mutex);
! 	}
! 	else
! 		data = NULL;
  	return data;
  }
--- 64,82 ----
  }
  
! /* this fifo_get returns 0 if the fifo is empty or locked by another thread */
! void* fifo_get(t_fifo* fifo) {
  	t_fifocell * cell;
! 	void *data;
! 	if(pthread_mutex_trylock(&fifo->mutex) != EBUSY) {
  		cell = fifo->head->next;
! 		if (cell) {
  			fifo->head->next = cell->next;
  			if(cell == fifo->tail)
  				fifo->tail = fifo->head;
  			data = cell->data;
! 			free(cell);
! 		} else data = 0;
  		pthread_mutex_unlock(&fifo->mutex);
! 	} else data = 0;
  	return data;
  }
***************
*** 125,149 ****
  */
  
! 
! 
! typedef struct _fifocell
! {
! 	struct _fifocell* next;
! 	void* data;            /* pointer to our data */
  } t_fifocell;
  
! typedef struct _lifo
! {
  	unsigned long ic;       /* operation counter */
  	t_fifocell* top;        /* stack pointer */
  	unsigned long oc;       /* operation counter */
  #ifdef __POWERPC__
! 	long 	unused [5];		/* lifo size must be at least 32 bytes */
! 							/* to avoid livelock in multiprocessor */
  #endif
  } t_lifo;
  
! struct _fifo
! {
  	t_lifo in;
  	t_lifo out;
--- 90,109 ----
  */
  
! typedef struct _fifocell {
! 	struct _fifocell *next;
! 	void *data;            /* pointer to our data */
  } t_fifocell;
  
! typedef struct _lifo {
  	unsigned long ic;       /* operation counter */
  	t_fifocell* top;        /* stack pointer */
  	unsigned long oc;       /* operation counter */
  #ifdef __POWERPC__
! 	long 	unused [5];	/* lifo size must be at least 32 bytes */
! 				/* to avoid livelock in multiprocessor */
  #endif
  } t_lifo;
  
! struct _fifo {
  	t_lifo in;
  	t_lifo out;
***************
*** 160,165 ****
  #if defined(__GNUC__) && (defined(__POWERPC__) || defined(__PPC__))
  
! static void* lifo_pop(t_lifo* lifo)
! {
  	register void * data;
  	register volatile long a, b;
--- 120,124 ----
  #if defined(__GNUC__) && (defined(__POWERPC__) || defined(__PPC__))
  
! static void* lifo_pop(t_lifo* lifo) {
  	register void * data;
  	register volatile long a, b;
***************
*** 193,198 ****
  }
  
! static void* lifo_push(register t_lifo* lifo, register void* data)
! {
  	register volatile long t1;
  	register long t2=0;
--- 152,156 ----
  }
  
! static void* lifo_push(register t_lifo *lifo, register void *data) {
  	register volatile long t1;
  	register long t2=0;
***************
*** 221,227 ****
  #elif defined(__ppc__) && defined(__APPLE__)
  
! static void* lifo_pop(t_lifo* lifo)
! {
! 	register void * data;
  	register long a, b;
  	asm {
--- 179,184 ----
  #elif defined(__ppc__) && defined(__APPLE__)
  
! static void *lifo_pop(t_lifo *lifo) {
! 	register void *data;
  	register long a, b;
  	asm {
***************
*** 444,502 ****
  #endif
  
! 
! 
! static void lifo_init(t_lifo* lifo)
! {
  	lifo->ic = 0;
! 	lifo->top = NULL;
  	lifo->oc = 0;
  }
  
! t_fifo* fifo_init(void)
! {
! 	t_fifo* ret = (t_fifo*) getbytes(sizeof(t_fifo));
! 	
  	lifo_init(&ret->in);
  	lifo_init(&ret->out);
- 	
  	return ret;
  }
  
! 
! void fifo_destroy(t_fifo* fifo)
! {
! 	void * data;
! 	do
! 	{
! 		data = fifo_get(fifo);
! 	}
! 	while (data != NULL);
! 
! 	freebytes(fifo, sizeof(t_fifo));
  	return;
  }
  
! void fifo_put(t_fifo* fifo, void* data)
! {
! 	lifo_push(&fifo->in, data);
! }
  
! void* fifo_get(t_fifo* fifo)
! {
! 	void * data;
  	t_lifo *out = &fifo->out;
- 	
  	data = lifo_pop(out);
! 	
! 	if (!data)
! 	{
! 		void * tmp;
  		t_lifo *in = &fifo->in;
  		data = lifo_pop(in);
! 
! 		if (data)
! 		{
! 			while((tmp = lifo_pop(in)))
! 			{
  				lifo_push(out, data);
  				data = tmp;
--- 401,436 ----
  #endif
  
! static void lifo_init(t_lifo* lifo) {
  	lifo->ic = 0;
! 	lifo->top = 0;
  	lifo->oc = 0;
  }
  
! t_fifo *fifo_init(void) {
! 	t_fifo *ret = (t_fifo *)malloc(sizeof(t_fifo));
  	lifo_init(&ret->in);
  	lifo_init(&ret->out);
  	return ret;
  }
  
! void fifo_destroy(t_fifo *fifo) {
! 	void *data;
! 	do data = fifo_get(fifo); while (data);
! 	free(fifo);
  	return;
  }
  
! void fifo_put(t_fifo *fifo, void *data) {lifo_push(&fifo->in, data);}
  
! void* fifo_get(t_fifo *fifo) {
! 	void *data;
  	t_lifo *out = &fifo->out;
  	data = lifo_pop(out);
! 	if (!data) {
! 		void *tmp;
  		t_lifo *in = &fifo->in;
  		data = lifo_pop(in);
! 		if (data) {
! 			while((tmp = lifo_pop(in))) {
  				lifo_push(out, data);
  				data = tmp;
***************
*** 508,512 ****
  }
  
- 
- 
  #endif
--- 442,444 ----





More information about the Pd-cvs mailing list