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

4.115
Last change on this file since d7ce33f1 was 3750995, checked in by Alex Ivanov <alexivanov97@…>, on 12/10/12 at 19:51:23

libcsupport: Doxygen enhancement task #5

http://www.google-melange.com/gci/task/view/google/gci2012/7992211

  • Property mode set to 100644
File size: 2.3 KB
Line 
1/**
2 *  @file
3 *
4 *  @brief Synchronize Data on Disk with Memory
5 *  @ingroup libcsupport
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2008.
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
14 *  http://www.rtems.com/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
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
28#include <unistd.h>
29#include <stdio.h>
30
31#include <rtems.h>
32/*
33#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__
34
35#include <rtems/libio_.h>
36#include <rtems/seterr.h>
37*/
38
39/* XXX check standards -- Linux version appears to be void */
40void _fwalk(struct _reent *, void *);
41
42
43static void sync_wrapper(FILE *f)
44{
45  int fn = fileno(f);
46
47  /*
48   *  We are explicitly NOT checking the return values as it does not
49   *  matter if they succeed.  We are just making a best faith attempt
50   *  at both and trusting that we were passed a good FILE pointer.
51   */
52  fsync(fn);
53  fdatasync(fn);
54}
55
56/* iterate over all FILE *'s for this thread */
57static void sync_per_thread(Thread_Control *t)
58{
59   struct _reent *current_reent;
60   struct _reent *this_reent;
61
62   /*
63    *  The sync_wrapper() function will operate on the current thread's
64    *  reent structure so we will temporarily use that.
65    */
66   this_reent = t->libc_reent;
67   if ( this_reent ) {
68     current_reent = _Thread_Executing->libc_reent;
69     _Thread_Executing->libc_reent = this_reent;
70     _fwalk (t->libc_reent, sync_wrapper);
71     _Thread_Executing->libc_reent = current_reent;
72   }
73}
74
75/*
76 * _global_impure_ptr is not prototyped in any .h files.
77 * We have to extern it here.
78 */
79extern struct _reent * const _global_impure_ptr __ATTRIBUTE_IMPURE_PTR__;
80
81/**
82 * This function operates by as follows:
83 *    for all threads
84 *      for all FILE *
85 *         fsync()
86 *         fdatasync()
87 */
88void sync(void)
89{
90
91  /*
92   *  Walk the one used initially by RTEMS.
93   */
94  _fwalk(_global_impure_ptr, sync_wrapper);
95
96  /*
97   *  XXX Do we walk the one used globally by newlib?
98   *  XXX Do we need the RTEMS global one?
99   */
100
101  /*
102   *  Now walk all the per-thread reentrancy structures.
103   */
104  rtems_iterate_over_all_threads(sync_per_thread);
105}
Note: See TracBrowser for help on using the repository browser.