Lines Matching refs:context

46 static struct file_descriptor* get_fd_locked(struct io_context* context,
48 static struct file_descriptor* remove_fd(struct io_context* context, int fd);
94 fd_close_on_exec(struct io_context* context, int fd)
96 return CHECK_BIT(context->fds_close_on_exec[fd / 8], fd & 7) ? true : false;
101 fd_set_close_on_exec(struct io_context* context, int fd, bool closeFD)
104 context->fds_close_on_exec[fd / 8] |= (1 << (fd & 7));
106 context->fds_close_on_exec[fd / 8] &= ~(1 << (fd & 7));
110 /*! Searches a free slot in the FD table of the provided I/O context, and
114 new_fd_etc(struct io_context* context, struct file_descriptor* descriptor,
120 if (firstIndex < 0 || (uint32)firstIndex >= context->table_size)
123 mutex_lock(&context->io_mutex);
125 for (i = firstIndex; i < context->table_size; i++) {
126 if (!context->fds[i]) {
136 TFD(NewFD(context, fd, descriptor));
138 context->fds[fd] = descriptor;
139 context->num_used_fds++;
143 mutex_unlock(&context->io_mutex);
150 new_fd(struct io_context* context, struct file_descriptor* descriptor)
152 return new_fd_etc(context, descriptor, 0);
202 close_fd(struct io_context* context, struct file_descriptor* descriptor)
206 vfs_release_posix_lock(context, descriptor);
218 close_fd_index(struct io_context* context, int fd)
220 struct file_descriptor* descriptor = remove_fd(context, fd);
225 close_fd(context, descriptor);
254 get_fd_locked(struct io_context* context, int fd)
256 if (fd < 0 || (uint32)fd >= context->table_size)
259 struct file_descriptor* descriptor = context->fds[fd];
266 TFD(GetFD(context, fd, descriptor));
275 get_fd(struct io_context* context, int fd)
277 MutexLocker _(context->io_mutex);
279 return get_fd_locked(context, fd);
284 get_open_fd(struct io_context* context, int fd)
286 MutexLocker _(context->io_mutex);
288 file_descriptor* descriptor = get_fd_locked(context, fd);
301 remove_fd(struct io_context* context, int fd)
308 mutex_lock(&context->io_mutex);
310 if ((uint32)fd < context->table_size)
311 descriptor = context->fds[fd];
318 TFD(RemoveFD(context, fd, descriptor));
320 context->fds[fd] = NULL;
321 fd_set_close_on_exec(context, fd, false);
322 context->num_used_fds--;
324 selectInfos = context->select_infos[fd];
325 context->select_infos[fd] = NULL;
333 mutex_unlock(&context->io_mutex);
342 struct io_context* context = get_current_io_context(kernel);
349 descriptor = get_fd(context, fd);
354 status = new_fd(context, descriptor);
358 mutex_lock(&context->io_mutex);
359 fd_set_close_on_exec(context, status, false);
360 mutex_unlock(&context->io_mutex);
377 struct io_context* context;
385 // Get current I/O context and lock it
386 context = get_current_io_context(kernel);
387 mutex_lock(&context->io_mutex);
391 if ((uint32)oldfd >= context->table_size
392 || (uint32)newfd >= context->table_size
393 || context->fds[oldfd] == NULL
394 || (context->fds[oldfd]->open_mode & O_DISCONNECTED) != 0) {
395 mutex_unlock(&context->io_mutex);
404 TFD(Dup2FD(context, oldfd, newfd));
406 evicted = context->fds[newfd];
407 select_info* selectInfos = context->select_infos[newfd];
408 context->select_infos[newfd] = NULL;
409 atomic_add(&context->fds[oldfd]->ref_count, 1);
410 atomic_add(&context->fds[oldfd]->open_count, 1);
411 context->fds[newfd] = context->fds[oldfd];
414 context->num_used_fds++;
419 fd_set_close_on_exec(context, newfd, false);
421 mutex_unlock(&context->io_mutex);
425 close_fd(context, evicted);
443 // get the I/O context for the team in question
457 // create a new FD in the target I/O context
526 // define before the context locker, so it will be destroyed after it
528 io_context* context = get_current_io_context(kernel);
529 MutexLocker locker(context->io_mutex);
531 descriptor.SetTo(get_fd_locked(context, fd));
566 // Add the info to the IO context. Even if nothing has been selected -- we
569 if (context->fds[fd] != descriptor.Get()) {
576 close_fd(context, descriptor.Get());
582 info->next = context->select_infos[fd];
583 context->select_infos[fd] = info;
605 // define before the context locker, so it will be destroyed after it
607 io_context* context = get_current_io_context(kernel);
608 MutexLocker locker(context->io_mutex);
610 descriptor.SetTo(get_fd_locked(context, fd));
614 // remove the info from the IO context
616 select_info** infoLocation = &context->select_infos[fd];
646 context. It can be used for a quick check; the fd is not locked
902 // get I/O context and FD