add: TRACE(("create_port() done: port created %ld\n", id));
context: create_port(int32 queueLength, const char *name){	cpu_status state;	char nameBuffer[B_OS_NAME_LENGTH];	sem_id readSem, writeSem;	status_t status;	team_id	owner;	int32 slot;	TRACE(("create_port(queueLength = %ld, name = \"%s\")\n", queueLength, name));	if (!sPortsActive)		return B_BAD_PORT_ID;	// check queue length	if (queueLength < 1		|| queueLength > MAX_QUEUE_LENGTH)		return B_BAD_VALUE;	// check early on if there are any free port slots to use	if (atomic_add(&sUsedPorts, 1) >= sMaxPorts) {		status = B_NO_MORE_PORTS;		goto err1;	}	// check & dup name	if (name == NULL)		name = "unnamed port";	// ToDo: we could save the memory and use the semaphore name only instead	strlcpy(nameBuffer, name, B_OS_NAME_LENGTH);	name = strdup(nameBuffer);	if (name == NULL) {		status = B_NO_MEMORY;		goto err1;	}	// create read sem with owner set to -1	// ToDo: should be B_SYSTEM_TEAM	readSem = create_sem_etc(0, name, -1);	if (readSem < B_OK) {		status = readSem;		goto err2;	}	// create write sem	writeSem = create_sem_etc(queueLength, name, -1);	if (writeSem < B_OK) {		status = writeSem;		goto err3;	}	owner = team_get_current_team_id();	state = disable_interrupts();	GRAB_PORT_LIST_LOCK();	// find the first empty spot	for (slot = 0; slot < sMaxPorts; slot++) {		int32 i = (slot + sFirstFreeSlot) % sMaxPorts;		if (sPorts[i].id == -1) {			port_id id;			// make the port_id be a multiple of the slot it's in			if (i >= sNextPort % sMaxPorts)				sNextPort += i - sNextPort % sMaxPorts;			else				sNextPort += sMaxPorts - (sNextPort % sMaxPorts - i);			sFirstFreeSlot = slot + 1;			GRAB_PORT_LOCK(sPorts[i]);			sPorts[i].id = sNextPort++;			RELEASE_PORT_LIST_LOCK();			sPorts[i].capacity = queueLength;			sPorts[i].owner = owner;			sPorts[i].name = name;			sPorts[i].read_sem	= readSem;			sPorts[i].write_sem	= writeSem;			list_init(&sPorts[i].msg_queue);			sPorts[i].total_count = 0;			id = sPorts[i].id;			RELEASE_PORT_LOCK(sPorts[i]);			restore_interrupts(state);			return id;		}	}	// not enough ports...	// ToDo: due to sUsedPorts, this cannot happen anymore - as	//		long as sMaxPorts stays constant over the kernel run	//		time (which it should be). IOW we could simply panic()	//		here.	RELEASE_PORT_LIST_LOCK();	restore_interrupts(state);	status = B_NO_MORE_PORTS;	delete_sem(writeSem);err3:	delete_sem(readSem);err2:	free((char *)name);err1:	atomic_add(&sUsedPorts, -1);	return status;}