Changeset 8d54187 in rtems


Ignore:
Timestamp:
05/13/22 11:10:00 (8 weeks ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
5
Parents:
5d73509
git-author:
Sebastian Huber <sebastian.huber@…> (05/13/22 11:10:00)
git-committer:
Sebastian Huber <sebastian.huber@…> (05/17/22 13:27:50)
Message:

Synchronize all file descriptors in sync()

Synchronize all file descriptors and not just the ones associated with a FILE
object.

Close #4655.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libcsupport/src/sync.c

    r5d73509 r8d54187  
    11/**
    2  *  @file
     2 * @file
    33 *
    4  *  @brief Synchronize Data on Disk with Memory
    5  *  @ingroup libcsupport
     4 * @ingroup libcsupport
     5 *
     6 * @brief This source file contains the implementation of sync().
    67 */
    78
    89/*
    9  *  COPYRIGHT (c) 1989-2008.
    10  *  On-Line Applications Research Corporation (OAR).
     10 * Copyright (C) 2022 embedded brains GmbH
    1111 *
    1212 *  The license and distribution terms for this file may be
     
    1919#endif
    2020
    21 /* Since we compile with strict ANSI we need to undef it to get
    22  * prototypes for extensions
    23  */
    24 #undef __STRICT_ANSI__
    25 int fdatasync(int);        /* still not always prototyped */
     21#include <unistd.h>
    2622
     23#include <rtems/libio_.h>
    2724
    28 #include <unistd.h>
    29 #include <stdio.h>
     25void sync( void )
     26{
     27  int fd;
    3028
    31 #include <rtems.h>
    32 #include <rtems/score/thread.h>
    33 #include <rtems/score/percpu.h>
    34 
    35 /* XXX check standards -- Linux version appears to be void */
    36 void _fwalk(struct _reent *, void *);
    37 
    38 
    39 static void sync_wrapper(FILE *f)
    40 {
    41   int fn = fileno(f);
    42 
    43   /*
    44    * There is no way to report errors here.  So this is a best-effort approach.
    45    */
    46   (void) fsync(fn);
    47   (void) fdatasync(fn);
     29  for ( fd = 0; fd < (int) rtems_libio_number_iops; ++fd ) {
     30    (void) fsync( fd );
     31    (void) fdatasync( fd );
     32  }
    4833}
    49 
    50 /* iterate over all FILE *'s for this thread */
    51 static bool sync_per_thread(Thread_Control *t, void *arg)
    52 {
    53    struct _reent *current_reent;
    54    struct _reent *this_reent;
    55 
    56    /*
    57     *  The sync_wrapper() function will operate on the current thread's
    58     *  reent structure so we will temporarily use that.
    59     */
    60    this_reent = t->libc_reent;
    61    if ( this_reent ) {
    62      Thread_Control *executing = _Thread_Get_executing();
    63      current_reent = executing->libc_reent;
    64      executing->libc_reent = this_reent;
    65      _fwalk (t->libc_reent, sync_wrapper);
    66      executing->libc_reent = current_reent;
    67    }
    68 
    69    return false;
    70 }
    71 
    72 /*
    73  * _global_impure_ptr is not prototyped in any .h files.
    74  * We have to extern it here.
    75  */
    76 extern struct _reent * const _global_impure_ptr __ATTRIBUTE_IMPURE_PTR__;
    77 
    78 /**
    79  * This function operates by as follows:
    80  *    for all threads
    81  *      for all FILE *
    82  *         fsync()
    83  *         fdatasync()
    84  */
    85 void sync(void)
    86 {
    87 
    88   /*
    89    *  Walk the one used initially by RTEMS.
    90    */
    91   _fwalk(_global_impure_ptr, sync_wrapper);
    92 
    93   /*
    94    *  XXX Do we walk the one used globally by newlib?
    95    *  XXX Do we need the RTEMS global one?
    96    */
    97 
    98   /*
    99    *  Now walk all the per-thread reentrancy structures.
    100    */
    101   rtems_task_iterate(sync_per_thread, NULL);
    102 }
Note: See TracChangeset for help on using the changeset viewer.