Changeset 27b76ca in mainline for uspace/srv/vfs/vfs_file.c
- Timestamp:
- 2011-08-18T14:05:10Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 44451ee
- Parents:
- b33ec43
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/vfs/vfs_file.c
rb33ec43 r27b76ca 43 43 #include <fibril.h> 44 44 #include <fibril_synch.h> 45 #include <adt/list.h> 45 46 #include "vfs.h" 46 47 … … 50 51 typedef struct { 51 52 fibril_mutex_t lock; 53 fibril_condvar_t cv; 54 list_t passed_handles; 52 55 vfs_file_t **files; 53 56 } vfs_client_data_t; 57 58 typedef struct { 59 link_t link; 60 int handle; 61 } vfs_boxed_handle_t; 54 62 55 63 static int _vfs_fd_free(vfs_client_data_t *, int); … … 85 93 86 94 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 } 87 106 } 88 107 … … 94 113 if (vfs_data) { 95 114 fibril_mutex_initialize(&vfs_data->lock); 115 fibril_condvar_initialize(&vfs_data->cv); 116 list_initialize(&vfs_data->passed_handles); 96 117 vfs_data->files = NULL; 97 118 } … … 331 352 vfs_file_t *donor_file = NULL; 332 353 vfs_file_t *acceptor_file = NULL; 354 vfs_boxed_handle_t *bh; 333 355 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; 334 366 335 367 donor_data = async_get_client_data_by_hash(donor_hash); 336 368 if (!donor_data) 337 return;338 acceptor_data = async_get_client_data_by_hash(acceptor_hash);339 if (!acceptor_data)340 369 goto out; 341 370 … … 347 376 if (acceptor_fd < 0) 348 377 goto out; 378 379 bh->handle = acceptor_fd; 349 380 350 381 /* … … 364 395 365 396 out: 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 366 402 if (donor_data) 367 403 async_put_client_data_by_hash(donor_hash); … … 372 408 if (acceptor_file) 373 409 _vfs_file_put(acceptor_data, acceptor_file); 410 411 } 412 413 int 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; 374 430 } 375 431
Note:
See TracChangeset
for help on using the changeset viewer.