Changeset 3ccfb583 in rtems


Ignore:
Timestamp:
05/13/22 11:10:00 (8 weeks ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
81962136
Parents:
135d527
git-author:
Sebastian Huber <sebastian.huber@…> (05/13/22 11:10:00)
git-committer:
Sebastian Huber <sebastian.huber@…> (05/17/22 13:20:37)
Message:

Synchronize all file descriptors in sync()

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

Close #4656.

File:
1 edited

Legend:

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

    r135d527 r3ccfb583  
    22
    33/**
    4  *  @file
     4 * @file
    55 *
    6  *  @brief Synchronize Data on Disk with Memory
    7  *  @ingroup libcsupport
     6 * @ingroup libcsupport
     7 *
     8 * @brief This source file contains the implementation of sync().
    89 */
    910
    1011/*
    11  *  COPYRIGHT (c) 1989-2008.
    12  *  On-Line Applications Research Corporation (OAR).
     12 * Copyright (C) 2022 embedded brains GmbH
    1313 *
    1414 * Redistribution and use in source and binary forms, with or without
     
    3838#endif
    3939
    40 #include <sys/reent.h>
    4140#include <unistd.h>
    42 #include <stdio.h>
    4341
    44 #include <rtems.h>
    45 #include <rtems/score/thread.h>
    46 #include <rtems/score/percpu.h>
     42#include <rtems/libio_.h>
    4743
    48 /* In Newlib this function is declared in a private header file */
    49 int _fwalk_reent (struct _reent *, int (*)(struct _reent *, FILE *));
     44void sync( void )
     45{
     46  int fd;
    5047
    51 static int sync_wrapper(struct _reent *reent, FILE *f)
    52 {
    53   int fn = fileno(f);
    54 
    55   (void) reent;
    56 
    57   /*
    58    * There is no way to report errors here.  So this is a best-effort approach.
    59    */
    60   (void) fsync(fn);
    61   (void) fdatasync(fn);
    62 
    63   return 0;
     48  for ( fd = 0; fd < (int) rtems_libio_number_iops; ++fd ) {
     49    (void) fsync( fd );
     50    (void) fdatasync( fd );
     51  }
    6452}
    65 
    66 /* iterate over all FILE *'s for this thread */
    67 static bool sync_per_thread(Thread_Control *t, void *arg)
    68 {
    69    struct _reent *current_reent;
    70    struct _reent *this_reent;
    71 
    72    /*
    73     *  The sync_wrapper() function will operate on the current thread's
    74     *  reent structure so we will temporarily use that.
    75     */
    76    this_reent = t->libc_reent;
    77    if ( this_reent ) {
    78      Thread_Control *executing = _Thread_Get_executing();
    79      current_reent = executing->libc_reent;
    80      executing->libc_reent = this_reent;
    81      _fwalk_reent (this_reent, sync_wrapper);
    82      executing->libc_reent = current_reent;
    83    }
    84 
    85    return false;
    86 }
    87 
    88 /**
    89  * This function operates by as follows:
    90  *    for all threads
    91  *      for all FILE *
    92  *         fsync()
    93  *         fdatasync()
    94  */
    95 void sync(void)
    96 {
    97 
    98   /*
    99    *  Walk the one used initially by RTEMS.
    100    */
    101   _fwalk_reent(_GLOBAL_REENT, sync_wrapper);
    102 
    103   /*
    104    *  XXX Do we walk the one used globally by newlib?
    105    *  XXX Do we need the RTEMS global one?
    106    */
    107 
    108   /*
    109    *  Now walk all the per-thread reentrancy structures.
    110    */
    111   rtems_task_iterate(sync_per_thread, NULL);
    112 }
Note: See TracChangeset for help on using the changeset viewer.