Example #1
0
static del_mem_list(my_mem_list_struct_t **header, char *ptr, int iline, char *pcfile)
{
	my_mem_list_struct_t *p, *pre;

	if (ptr == NULL) return;

	my_pthread_mutex_lock(&g_ptmmem);
	for (p=*header; p!=NULL; pre=p, p=p->pnext)
	{
		if (p->ptr == ptr)
			break;
	}

	if (p == NULL)
	{
		fprintf(stderr, "del_mem_list error in %s(%s %d %d).!", __FILE__, pcfile, iline, ptr);
		for (p = *header; p!=NULL; p=p->pnext)
			printf("%d ", p->ptr);
		my_pthread_mutex_unlock(&g_ptmmem);
//		return;
		exit(-1);
	}

	if (p == *header)
		*header = p->pnext;
	else
		pre->pnext = p->pnext;
	save_free(p->pcfile);
	save_free(p);
	my_pthread_mutex_unlock(&g_ptmmem);
}
Example #2
0
static add_mem_list(my_mem_list_struct_t **header, char *ptr, int isize, int iline, char *pcfile)
{
	my_mem_list_struct_t *p;
	if (ptr == NULL) return;

	my_pthread_mutex_lock(&g_ptmmem);
	for (p=*header; p!=NULL; p=p->pnext)
	{
		if (p->ptr == ptr)
		{
			fprintf(stderr, "add_mem_list error in %s(%s %d).!", __FILE__, pcfile, iline);
			my_pthread_mutex_unlock(&g_ptmmem);
			exit(-1);
		}
	}

	p = (my_mem_list_struct_t *)save_malloc(sizeof(my_mem_list_struct_t));
	if (p == NULL)
	{
		fprintf(stderr, "not enough memory in %s.\n", __FILE__);
		my_pthread_mutex_unlock(&g_ptmmem);
		exit(-1);
	}

	p->ptr = ptr;
	p->isize = isize;
	p->iline = iline;
	p->pcfile = save_strdup(pcfile);
	p->pnext = *header;
	*header = p;
	my_pthread_mutex_unlock(&g_ptmmem);
}
Example #3
0
static del_fp_list(my_fp_list_struct_t **header, FILE *fp, int iline, char *pcfile)
{
	my_fp_list_struct_t *p, *pre;
	pthread_t pid;

	if (fp == NULL) return;
	pid=0;//pid = pthread_self();
	my_pthread_mutex_lock(&g_ptmfp);

	for (p=*header; p!=NULL; pre=p, p=p->pnext)
	{
		if (p->fp == fp && p->pid == pid)
			break;
	}

	if (p == NULL)
	{
		fprintf(stderr, "del_fp_list error in %s(%s %d %d).!", __FILE__, pcfile, iline, fp);
		for (p = *header; p!=NULL; p=p->pnext)
			printf("%d ", p->fp);
		my_pthread_mutex_unlock(&g_ptmfp);
//		return;
		exit(-1);
	}

	if (p == *header)
		*header = p->pnext;
	else
		pre->pnext = p->pnext;
	save_free(p->pcfile);
	save_free(p);
	my_pthread_mutex_unlock(&g_ptmfp);
}
Example #4
0
static add_fp_list(my_fp_list_struct_t **header, FILE *fp, int iline, char *pcfile)
{
	pthread_t pid;
	my_fp_list_struct_t *p;
	if (fp == NULL) return;

	pid=0;//pid = pthread_self();
	my_pthread_mutex_lock(&g_ptmfp);
	for (p=*header; p!=NULL; p=p->pnext)
	{
		if (p->fp == fp && p->pid == pid)
		{
			fprintf(stderr, "add_fp_list error in %s(%s %d).!", __FILE__, pcfile, iline);
			my_pthread_mutex_unlock(&g_ptmfp);
			exit(-1);
		}
	}

	p = (my_fp_list_struct_t *)save_malloc(sizeof(my_fp_list_struct_t));
	if (p == NULL)
	{
		fprintf(stderr, "not enough memory in %s.\n", __FILE__);
		my_pthread_mutex_unlock(&g_ptmfp);
		exit(-1);
	}

	p->fp = fp;
	p->iline = iline;
	p->pcfile = save_strdup(pcfile);
	p->pnext = *header;
	p->pid = pid;
	*header = p;
	my_pthread_mutex_unlock(&g_ptmfp);
}
void *doit(void *vptr)
{
     int    i = 0;
     int    val = 0;

     for (i = 0; i < NLOOP; i++)
     {
         my_pthread_mutex_lock(&counter_mutex);

         val = counter;
         printf("%d: %d\n",
                 pthread_self(), val + 1);
         counter = val + 1;

         my_pthread_mutex_unlock(&counter_mutex);
     }

     return (NULL);
}
Example #6
0
struct servent *getservbyname_r(const char *name, const char *proto, struct servent *result, char *buf, size_t buflen)
{
#ifdef HAVE_PTHREAD
	static pthread_mutex_t getservbyname_lock = PTHREAD_MUTEX_INITIALIZER;
#endif
	struct servent *res;
	(void) buf;					// not used
	(void) buflen;				// not used

#ifdef HAVE_PTHREAD
	my_pthread_mutex_lock(&getservbyname_lock);
#endif
	res = getservbyname(name, proto);
	if (res)
		memcpy(result, res, sizeof(struct servent));
#ifdef HAVE_PTHREAD
	my_pthread_mutex_unlock(&getservbyname_lock);
#endif
	return res;
}
Example #7
0
struct hostent *gethostbyaddr_r(const char *name, int len, int type, struct hostent *result, char *buf, size_t buflen, int *h_errnop)
{
#ifdef HAVE_PTHREAD
	static pthread_mutex_t gethostbyaddr_lock = PTHREAD_MUTEX_INITIALIZER;
#endif
	struct hostent *res;
	(void) buf;					// not used
	(void) buflen;				// not used

#ifdef HAVE_PTHREAD
	my_pthread_mutex_lock(&gethostbyaddr_lock);
#endif
	res = gethostbyaddr(name, len, type);
	if (res) {
		memcpy(result, res, sizeof(struct hostent));
	} else {
		*h_errnop = errno;
	}
#ifdef HAVE_PTHREAD
	my_pthread_mutex_unlock(&gethostbyaddr_lock);
#endif
	return res;
}