source: rtems/cpukit/include/rtems/posix/shmimpl.h @ 21275b58

5
Last change on this file since 21275b58 was 21275b58, checked in by Sebastian Huber <sebastian.huber@…>, on 11/22/18 at 18:14:51

score: Static Objects_Information initialization

Statically allocate the objects information together with the initial
set of objects either via <rtems/confdefs.h>. Provide default object
informations with zero objects via librtemscpu.a. This greatly
simplifies the workspace size estimate. RTEMS applications which do not
use the unlimited objects option are easier to debug since all objects
reside now in statically allocated objects of the right types.

Close #3621.

  • Property mode set to 100644
File size: 2.6 KB
Line 
1/**
2 * @file
3 *
4 * @brief Private Support Information for POSIX Shared Memory
5 *
6 */
7
8/*
9 * Copyright (c) 2016 Gedare Bloom.
10 *
11 * The license and distribution terms for this file may be
12 * found in the file LICENSE in this distribution or at
13 * http://www.rtems.org/license/LICENSE.
14 */
15
16#ifndef _RTEMS_POSIX_SHMIMPL_H
17#define _RTEMS_POSIX_SHMIMPL_H
18
19#include <rtems/fs.h>
20#include <rtems/libio.h>
21#include <rtems/posix/posixapi.h>
22#include <rtems/posix/shm.h>
23#include <rtems/score/objectimpl.h>
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
29/**
30 * @ingroup POSIXShmPrivate
31 * @{
32 */
33
34RTEMS_INLINE_ROUTINE POSIX_Shm_Control *_POSIX_Shm_Allocate_unprotected( void )
35{
36  return (POSIX_Shm_Control *)
37    _Objects_Allocate_unprotected( &_POSIX_Shm_Information );
38}
39
40/**
41 * @brief POSIX Shared Memory Free
42 *
43 * This routine frees a shm control block.
44 */
45RTEMS_INLINE_ROUTINE void _POSIX_Shm_Free (
46  POSIX_Shm_Control *the_shm
47)
48{
49  _Objects_Free( &_POSIX_Shm_Information, &the_shm->Object );
50}
51
52RTEMS_INLINE_ROUTINE POSIX_Shm_Control *_POSIX_Shm_Get_by_name(
53  const char                *name,
54  size_t                    *name_length_p,
55  Objects_Get_by_name_error *error
56)
57{
58  return (POSIX_Shm_Control *) _Objects_Get_by_name(
59    &_POSIX_Shm_Information,
60    name,
61    name_length_p,
62    error
63  );
64}
65
66RTEMS_INLINE_ROUTINE void _POSIX_Shm_Update_atime(
67  POSIX_Shm_Control *shm
68)
69{
70  struct timeval now;
71  gettimeofday( &now, 0 );
72  shm->atime = now.tv_sec;
73}
74
75RTEMS_INLINE_ROUTINE void _POSIX_Shm_Update_mtime_ctime(
76  POSIX_Shm_Control *shm
77)
78{
79  struct timeval now;
80  gettimeofday( &now, 0 );
81  shm->mtime = now.tv_sec;
82  shm->ctime = now.tv_sec;
83}
84
85static inline POSIX_Shm_Control* iop_to_shm( rtems_libio_t *iop )
86{
87  return (POSIX_Shm_Control*) iop->data1;
88}
89
90static inline POSIX_Shm_Control* loc_to_shm(
91    const rtems_filesystem_location_info_t *loc
92)
93{
94  return (POSIX_Shm_Control*) loc->node_access;
95}
96
97static inline int POSIX_Shm_Attempt_delete(
98    POSIX_Shm_Control* shm
99)
100{
101  Objects_Control       *obj;
102  ISR_lock_Context       lock_ctx;
103  int err;
104
105  err = 0;
106
107  _Objects_Allocator_lock();
108  --shm->reference_count;
109  if ( shm->reference_count == 0 ) {
110    if ( (*shm->shm_object.ops->object_delete)( &shm->shm_object ) != 0 ) {
111      err = EIO;
112    }
113  }
114  /* check if the object has been unlinked yet. */
115  obj = _Objects_Get( shm->Object.id, &lock_ctx, &_POSIX_Shm_Information );
116  if ( obj == NULL ) {
117    /* if it was unlinked, then it can be freed. */
118    _POSIX_Shm_Free( shm );
119  } else {
120    /* it will be freed when it is unlinked. */
121    _ISR_lock_ISR_enable( &lock_ctx );
122  }
123  _Objects_Allocator_unlock();
124  return err;
125}
126
127/** @} */
128
129#ifdef __cplusplus
130}
131#endif
132
133#endif
Note: See TracBrowser for help on using the repository browser.