コード例 #1
0
ファイル: ow_connect.c プロジェクト: bootc/owfs-cvsimport
/* Based on a shallow copy of "in" if not NULL */
struct connection_in *NewIn(void)
{
	struct connection_in *now;

	// step through head_inbound_list linked list
	for (now = head_inbound_list; now != NULL; now = now->next) {
		if (now->state == connection_vacant) {
#if OW_MT
			my_pthread_mutex_init(&(now->bus_mutex), Mutex.pmattr);
#endif							/* OW_MT */
			now->state = connection_pending;
			return now;
		}
	}
	now = malloc(sizeof(struct connection_in));
	if (now != NULL) {
		memset(now, 0, sizeof(struct connection_in));
		now->next = head_inbound_list;	/* put in linked list at start */
		head_inbound_list = now;
		now->index = count_inbound_connections++;
		now->state = connection_pending;
#if OW_MT
		my_pthread_mutex_init(&(now->bus_mutex), Mutex.pmattr);
#endif							/* OW_MT */
	}
	return now;
}
コード例 #2
0
ファイル: hooks.c プロジェクト: shr-project/libhybris
static int my_pthread_mutex_lock (pthread_mutex_t *__mutex)
{
	pthread_mutex_t *realmutex = (pthread_mutex_t *) *(int *) __mutex;

	if (realmutex == NULL) {
#if 0
		realmutex = malloc(sizeof(pthread_mutex_t));
		*((int *)__mutex) = (int) realmutex;
		pthread_mutex_init(realmutex, NULL);
#endif
		my_pthread_mutex_init(__mutex, NULL);
	}
	else if(realmutex == 0x4000) /* recursive static initializer */
	{
		printf("RECURSIVE STATIC MUTEX: %x (value = %x)\n", __mutex, *(int **)__mutex);
		pthread_mutexattr_t my_recursive_mutexattr;
		pthread_mutexattr_init(&my_recursive_mutexattr);
		pthread_mutexattr_settype(&my_recursive_mutexattr, PTHREAD_MUTEX_RECURSIVE_NP);
		my_pthread_mutex_init(__mutex, &my_recursive_mutexattr);
	}
	else if(realmutex == 0x8000) /* errorcheck static initializer */
	{
		printf("ERRORCHECK STATIC MUTEX: %x (value = %x)\n", __mutex, *(int **)__mutex);
		pthread_mutexattr_t my_recursive_mutexattr;
		pthread_mutexattr_init(&my_recursive_mutexattr);
		pthread_mutexattr_settype(&my_recursive_mutexattr, PTHREAD_MUTEX_ERRORCHECK_NP);
		my_pthread_mutex_init(__mutex, &my_recursive_mutexattr);
	}

	realmutex = (pthread_mutex_t *) *(int *) __mutex;

	return pthread_mutex_lock(realmutex);
}