src/server/twitpoollist.c
int newtwitpool( struct twitpoollist * restrict tpl, 
			struct twitpoollist_node ** restrict tplnode ){
	struct twitpoollist_node *newNode = NULL; // Must be initialized to NULL cause it is used as an error flag later
	int status = 0; // Must initialize to 0 cause status will only be changed if something wrong happens

	// Validate the parameters
	if ( tpl == NULL || tplnode == NULL ){
		errno = EINVAL;
		return ( -1 );
	}

	do{
		// Create the new node
		if ( ( newNode = malloc( sizeof( struct twitpoollist_node ) ) ) == NULL ){ status = -1; break; }

		// Initialize the new node as needed
		( void )inittwitpool( &newNode->tpln_twitpool );

		// Initialize the mutexes and conditions
		while ( pthread_mutex_init( &newNode->tpln_lock, NULL ) ){ continue; }
		while ( pthread_cond_init( &newNode->tpln_cond, NULL ) ){ continue; }

		// Link the new node at the beginning of the list
		newNode->tpln_next = tpl->tpl_head;
		if ( tpl->tpl_head != NULL ){
			tpl->tpl_head->tpln_previous = newNode;
		}
		tpl->tpl_head = newNode;

		// Inform client of the new node
		*tplnode = newNode;
	}while ( 0 );

	// Return the status
	return ( status );
}
// Create a node and insert it at the begining of the list. Store the address of the new node at *tplnode. 
Create a node and insert it at the begining of the list. Store the address of the new node at *tplnode.
Create a node and insert it at the begining of the list . Store the address of the new node at * tplnode .
int newtwitpool( struct twitpoollist * restrict tpl, 
			struct twitpoollist_node ** restrict tplnode ){
	struct twitpoollist_node *newNode = NULL; 
	int status = 0; 
	if ( tpl == NULL || tplnode == NULL ){
		errno = EINVAL;
		return ( -1 );
	}
	do{
		if ( ( newNode = malloc( sizeof( struct twitpoollist_node ) ) ) == NULL ){ status = -1; break; }
		( void )inittwitpool( &newNode->tpln_twitpool );
		while ( pthread_mutex_init( &newNode->tpln_lock, NULL ) ){ continue; }
		while ( pthread_cond_init( &newNode->tpln_cond, NULL ) ){ continue; }
		newNode->tpln_next = tpl->tpl_head;
		if ( tpl->tpl_head != NULL ){
			tpl->tpl_head->tpln_previous = newNode;
		}
		tpl->tpl_head = newNode;
		*tplnode = newNode;
	}while ( 0 );
	return ( status );
}
int newtwitpool ( struct twitpoollist * restrict tpl , struct twitpoollist_node * * restrict tplnode ) { struct twitpoollist_node * newNode = NULL ; int status = 0 ; if ( tpl == NULL || tplnode == NULL ) { errno = EINVAL ; return ( -1 ) ; } do { if ( ( newNode = malloc ( sizeof ( struct twitpoollist_node ) ) ) == NULL ) { status = -1 ; break ; } ( void ) inittwitpool ( & newNode -> tpln_twitpool ) ; while ( pthread_mutex_init ( & newNode -> tpln_lock , NULL ) ) { continue ; } while ( pthread_cond_init ( & newNode -> tpln_cond , NULL ) ) { continue ; } newNode -> tpln_next = tpl -> tpl_head ; if ( tpl -> tpl_head != NULL ) { tpl -> tpl_head -> tpln_previous = newNode ; } tpl -> tpl_head = newNode ; * tplnode = newNode ; } while ( 0 ) ; return ( status ) ; }
Create a node and insert it at the begining of the list.
Create a node and insert it at the begining of the list .
// Must be initialized to NULL cause it is used as an error flag later // Must initialize to 0 cause status will only be changed if something wrong happens // Validate the parameters // Create the new node // Initialize the new node as needed // Initialize the mutexes and conditions // Link the new node at the beginning of the list // Inform client of the new node // Return the status