source: rtems/cpukit/libcsupport/src/rtems_memalign.c @ 02733495

4.115
Last change on this file since 02733495 was 02733495, checked in by Sebastian Huber <sebastian.huber@…>, on 11/24/14 at 14:20:25

libcsupport: malloc_is_system_state_OK()

Move system state check to malloc_is_system_state_OK().

  • Property mode set to 100644
File size: 1.3 KB
Line 
1/**
2 *  @file
3 *
4 *  @brief RTEMS Variation on Aligned Memory Allocation
5 *  @ingroup MallocSupport
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.org/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#ifdef RTEMS_NEWLIB
22#include "malloc_p.h"
23
24#include <stdlib.h>
25#include <errno.h>
26
27int rtems_memalign(
28  void   **pointer,
29  size_t   alignment,
30  size_t   size
31)
32{
33  void *return_this;
34
35  /*
36   *  Parameter error checks
37   */
38  if ( !pointer )
39    return EINVAL;
40
41  *pointer = NULL;
42
43  /*
44   *  Do not attempt to allocate memory if not in correct system state.
45   */
46  if ( !malloc_is_system_state_OK() )
47    return EINVAL;
48
49  /*
50   *  If some free's have been deferred, then do them now.
51   */
52  malloc_deferred_frees_process();
53
54  /*
55   *  Perform the aligned allocation requested
56   */
57  return_this = _Protected_heap_Allocate_aligned(
58    RTEMS_Malloc_Heap,
59    size,
60    alignment
61  );
62  if ( !return_this )
63    return ENOMEM;
64
65  /*
66   *  If configured, update the more involved statistics
67   */
68  if ( rtems_malloc_statistics_helpers )
69    (*rtems_malloc_statistics_helpers->at_malloc)(pointer);
70
71  *pointer = return_this;
72  return 0;
73}
74#endif
Note: See TracBrowser for help on using the repository browser.