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

4.115
Last change on this file since df40cc9 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 2.2 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>
32
33/* XXX check standards -- Linux version appears to be void */
34void _fwalk(struct _reent *, void *);
35
[07e9194e]36
[bed55af]37static void sync_wrapper(FILE *f)
38{
39  int fn = fileno(f);
40
[e6a92f8]41  /*
42   *  We are explicitly NOT checking the return values as it does not
43   *  matter if they succeed.  We are just making a best faith attempt
44   *  at both and trusting that we were passed a good FILE pointer.
45   */
[bed55af]46  fsync(fn);
47  fdatasync(fn);
48}
49
50/* iterate over all FILE *'s for this thread */
51static void sync_per_thread(Thread_Control *t)
52{
[65fd5ae]53   struct _reent *current_reent;
[336227d]54   struct _reent *this_reent;
[bed55af]55
56   /*
57    *  The sync_wrapper() function will operate on the current thread's
58    *  reent structure so we will temporarily use that.
59    */
[336227d]60   this_reent = t->libc_reent;
61   if ( this_reent ) {
[d566f33e]62     Thread_Control *executing = _Thread_Get_executing();
63     current_reent = executing->libc_reent;
64     executing->libc_reent = this_reent;
[336227d]65     _fwalk (t->libc_reent, sync_wrapper);
[d566f33e]66     executing->libc_reent = current_reent;
[336227d]67   }
[bed55af]68}
69
[f73fc29]70/*
[d40da79b]71 * _global_impure_ptr is not prototyped in any .h files.
[f73fc29]72 * We have to extern it here.
73 */
[d40da79b]74extern struct _reent * const _global_impure_ptr __ATTRIBUTE_IMPURE_PTR__;
[f73fc29]75
[3750995]76/**
77 * This function operates by as follows:
78 *    for all threads
79 *      for all FILE *
80 *         fsync()
81 *         fdatasync()
82 */
[fbb5097c]83void sync(void)
[bed55af]84{
[07e9194e]85
86  /*
87   *  Walk the one used initially by RTEMS.
88   */
[d40da79b]89  _fwalk(_global_impure_ptr, sync_wrapper);
[07e9194e]90
91  /*
92   *  XXX Do we walk the one used globally by newlib?
93   *  XXX Do we need the RTEMS global one?
94   */
95
96  /*
97   *  Now walk all the per-thread reentrancy structures.
98   */
[bed55af]99  rtems_iterate_over_all_threads(sync_per_thread);
100}
Note: See TracBrowser for help on using the repository browser.