Changeset 27b76ca in mainline for uspace/srv/vfs/vfs_file.c


Ignore:
Timestamp:
2011-08-18T14:05:10Z (13 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
44451ee
Parents:
b33ec43
Message:

Synchronize VFS handle acceptor with VFS.

  • Introduce VFS_IN_WAIT_HANDLE.
  • Add vfs_wait_handle() to VFS.
  • Add fd_wait() to libc.
  • Use fd_wait() in loader.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/vfs/vfs_file.c

    rb33ec43 r27b76ca  
    4343#include <fibril.h>
    4444#include <fibril_synch.h>
     45#include <adt/list.h>
    4546#include "vfs.h"
    4647
     
    5051typedef struct {
    5152        fibril_mutex_t lock;
     53        fibril_condvar_t cv;
     54        list_t passed_handles;
    5255        vfs_file_t **files;
    5356} vfs_client_data_t;
     57
     58typedef struct {
     59        link_t link;
     60        int handle;
     61} vfs_boxed_handle_t;
    5462
    5563static int _vfs_fd_free(vfs_client_data_t *, int);
     
    8593       
    8694        free(vfs_data->files);
     95
     96        while (!list_empty(&vfs_data->passed_handles)) {
     97                link_t *lnk;
     98                vfs_boxed_handle_t *bh;
     99               
     100                lnk = list_first(&vfs_data->passed_handles);
     101                list_remove(lnk);
     102
     103                bh = list_get_instance(lnk, vfs_boxed_handle_t, link);
     104                free(bh);
     105        }
    87106}
    88107
     
    94113        if (vfs_data) {
    95114                fibril_mutex_initialize(&vfs_data->lock);
     115                fibril_condvar_initialize(&vfs_data->cv);
     116                list_initialize(&vfs_data->passed_handles);
    96117                vfs_data->files = NULL;
    97118        }
     
    331352        vfs_file_t *donor_file = NULL;
    332353        vfs_file_t *acceptor_file = NULL;
     354        vfs_boxed_handle_t *bh;
    333355        int acceptor_fd;
     356
     357        acceptor_data = async_get_client_data_by_hash(acceptor_hash);
     358        if (!acceptor_data)
     359                return;
     360
     361        bh = malloc(sizeof(vfs_boxed_handle_t));
     362        assert(bh);
     363
     364        link_initialize(&bh->link);
     365        bh->handle = -1;
    334366
    335367        donor_data = async_get_client_data_by_hash(donor_hash);
    336368        if (!donor_data)
    337                 return;
    338         acceptor_data = async_get_client_data_by_hash(acceptor_hash);
    339         if (!acceptor_data)
    340369                goto out;
    341370
     
    347376        if (acceptor_fd < 0)
    348377                goto out;
     378
     379        bh->handle = acceptor_fd;
    349380
    350381        /*
     
    364395
    365396out:
     397        fibril_mutex_lock(&acceptor_data->lock);
     398        list_append(&bh->link, &acceptor_data->passed_handles);
     399        fibril_condvar_broadcast(&acceptor_data->cv);
     400        fibril_mutex_unlock(&acceptor_data->lock);
     401
    366402        if (donor_data)
    367403                async_put_client_data_by_hash(donor_hash);
     
    372408        if (acceptor_file)
    373409                _vfs_file_put(acceptor_data, acceptor_file);
     410
     411}
     412
     413int vfs_wait_handle_internal(void)
     414{
     415        vfs_client_data_t *vfs_data = VFS_DATA;
     416        int fd;
     417       
     418        fibril_mutex_lock(&vfs_data->lock);
     419        while (list_empty(&vfs_data->passed_handles))
     420                fibril_condvar_wait(&vfs_data->cv, &vfs_data->lock);
     421        link_t *lnk = list_first(&vfs_data->passed_handles);
     422        list_remove(lnk);
     423        fibril_mutex_unlock(&vfs_data->lock);
     424
     425        vfs_boxed_handle_t *bh = list_get_instance(lnk, vfs_boxed_handle_t, link);
     426        fd = bh->handle;
     427        free(bh);
     428
     429        return fd;
    374430}
    375431
Note: See TracChangeset for help on using the changeset viewer.