source: rtems/cpukit/libcsupport/src/sync.c @ e22af78

4.11
Last change on this file since e22af78 was e22af78, checked in by Joel Sherrill <joel.sherrill@…>, on Nov 27, 2014 at 3:30:12 PM

sync.c: Add asserts to document and check assumptions

  • Property mode set to 100644
File size: 2.4 KB
RevLine 
[3750995]1/**
2 *  @file
[bed55af]3 *
[3750995]4 *  @brief Synchronize Data on Disk with Memory
5 *  @ingroup libcsupport
6 */
7
8/*
[d40da79b]9 *  COPYRIGHT (c) 1989-2008.
[bed55af]10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
[c499856]14 *  http://www.rtems.org/license/LICENSE.
[bed55af]15 */
16
17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
[07e9194e]21/* Since we compile with strict ANSI we need to undef it to get
22 * prototypes for extensions
23 */
24#undef __STRICT_ANSI__
25int fdatasync(int);        /* still not always prototyped */
26
27
[bed55af]28#include <unistd.h>
29#include <stdio.h>
30
31#include <rtems.h>
[e22af78]32#include <rtems/score/assert.h>
[bed55af]33
34/* XXX check standards -- Linux version appears to be void */
35void _fwalk(struct _reent *, void *);
36
[07e9194e]37
[bed55af]38static void sync_wrapper(FILE *f)
39{
40  int fn = fileno(f);
[e22af78]41  int rc;
[bed55af]42
[e6a92f8]43  /*
[e22af78]44   *  We are explicitly NOT checking the return values in non-debug builds
45   *  as it does not matter if they succeed.  We are just making a best
46   *  faith attempt at both and trusting that we were passed a good
47   *  FILE pointer.
[e6a92f8]48   */
[e22af78]49  rc = fsync(fn);
50  _Assert( rc == 0 );
51
52  rc = fdatasync(fn);
53  _Assert( rc == 0 );
[bed55af]54}
55
56/* iterate over all FILE *'s for this thread */
57static void sync_per_thread(Thread_Control *t)
58{
[65fd5ae]59   struct _reent *current_reent;
[336227d]60   struct _reent *this_reent;
[bed55af]61
62   /*
63    *  The sync_wrapper() function will operate on the current thread's
64    *  reent structure so we will temporarily use that.
65    */
[336227d]66   this_reent = t->libc_reent;
67   if ( this_reent ) {
[d566f33e]68     Thread_Control *executing = _Thread_Get_executing();
69     current_reent = executing->libc_reent;
70     executing->libc_reent = this_reent;
[336227d]71     _fwalk (t->libc_reent, sync_wrapper);
[d566f33e]72     executing->libc_reent = current_reent;
[336227d]73   }
[bed55af]74}
75
[f73fc29]76/*
[d40da79b]77 * _global_impure_ptr is not prototyped in any .h files.
[f73fc29]78 * We have to extern it here.
79 */
[d40da79b]80extern struct _reent * const _global_impure_ptr __ATTRIBUTE_IMPURE_PTR__;
[f73fc29]81
[3750995]82/**
83 * This function operates by as follows:
84 *    for all threads
85 *      for all FILE *
86 *         fsync()
87 *         fdatasync()
88 */
[fbb5097c]89void sync(void)
[bed55af]90{
[07e9194e]91
92  /*
93   *  Walk the one used initially by RTEMS.
94   */
[d40da79b]95  _fwalk(_global_impure_ptr, sync_wrapper);
[07e9194e]96
97  /*
98   *  XXX Do we walk the one used globally by newlib?
99   *  XXX Do we need the RTEMS global one?
100   */
101
102  /*
103   *  Now walk all the per-thread reentrancy structures.
104   */
[bed55af]105  rtems_iterate_over_all_threads(sync_per_thread);
106}
Note: See TracBrowser for help on using the repository browser.