rem: gSems[i].id = gNextSemID++;
add: gSems[i].id = gNextSemID;   if (++gNextSemID < 0) gNextSemID = 0;
context: create_sem_etc(int32 count, const char *name, team_id owner){	int i;	int state;	sem_id retval = B_NO_MORE_SEMS;	char *temp_name;	int name_len;	if (gSemsActive == false)		return B_NO_MORE_SEMS;	if (name == NULL)		name = "unnamed semaphore";	name_len = strlen(name) + 1;	name_len = min(name_len, SYS_MAX_OS_NAME_LEN);	temp_name = (char *)malloc(name_len);	if (temp_name == NULL)		return B_NO_MEMORY;	strlcpy(temp_name, name, name_len);	state = disable_interrupts();	GRAB_SEM_LIST_LOCK();	// find the first empty spot	for (i = 0; i < MAX_SEMS; i++) {		if (gSems[i].id == -1) {			// make the sem id be a multiple of the slot it's in			if (i >= gNextSemID % MAX_SEMS)				gNextSemID += i - gNextSemID % MAX_SEMS;			else				gNextSemID += MAX_SEMS - (gNextSemID % MAX_SEMS - i);			gSems[i].id = gNextSemID++;			// Set the owner while the sem list lock is hold, or else it			// might get lost if we have a sem_delete_owned_sems() running			// (although this should be impossible (if create_sem_etc() is			// just properly, I just feel better with it).			gSems[i].owner = owner;			gSems[i].lock = 0;			GRAB_SEM_LOCK(gSems[i]);			RELEASE_SEM_LIST_LOCK();			gSems[i].q.tail = NULL;			gSems[i].q.head = NULL;			gSems[i].count = count;			gSems[i].name = temp_name;			retval = gSems[i].id;			RELEASE_SEM_LOCK(gSems[i]);			goto out;		}	}	RELEASE_SEM_LIST_LOCK();	free(temp_name);out:	restore_interrupts(state);	return retval;}