rem: sync.sem = create_sem(1, "poll");
add: sync.sem = create_sem(0, "poll");
context: common_poll(struct pollfd *fds, nfds_t numfds, bigtime_t timeout, bool kernel){	status_t status = B_OK;	int count = 0;	uint32 i;	// allocate resources	select_sync sync;	memset(&sync, 0, sizeof(select_sync));	sync.sem = create_sem(1, "poll");	if (sync.sem < B_OK)		return sync.sem;	set_sem_owner(sync.sem, B_SYSTEM_TEAM);	sync.set = (select_info*)malloc(numfds * sizeof(select_info));	if (sync.set == NULL) {		delete_sem(sync.sem);		return B_NO_MEMORY;	}	sync.count = numfds;	// start polling file descriptors (by selecting them)	for (i = 0; i < numfds; i++) {		int fd = fds[i].fd;		// check if fds are valid		if (!fd_is_valid(fd, kernel)) {			fds[i].revents = POLLNVAL;			continue;		}		// initialize events masks		fds[i].events &= ~POLLNVAL;		fds[i].revents = 0;		sync.set[i].selected_events = fds[i].events;		sync.set[i].events = 0;		count += select_events(&sync, fd, i, fds[i].events, kernel);	}	if (count < 1) {		count = B_BAD_VALUE;		goto err;	}	status = acquire_sem_etc(sync.sem, 1,		B_CAN_INTERRUPT | (timeout != -1 ? B_RELATIVE_TIMEOUT : 0), timeout);	// deselect file descriptors	for (i = 0; i < numfds; i++)		deselect_events(&sync, fds[i].fd, sync.set[i].selected_events, kernel);	// collect the events that are happened in the meantime	switch (status) {		case B_OK:			for (count = 0, i = 0; i < numfds; i++) {				if (fds[i].revents == POLLNVAL)					continue;				// POLLxxx flags and B_SELECT_xxx flags are compatible				fds[i].revents = sync.set[i].events;				if (fds[i].revents != 0)					count++;			}			break;		case B_INTERRUPTED:			count = B_INTERRUPTED;			break;		default:			// B_TIMED_OUT, and B_WOULD_BLOCK			count = 0;	}err:	delete_sem(sync.sem);	free(sync.set);	return count;}