RTEMS  5.0.0
shmimpl.h
Go to the documentation of this file.
1 
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
26 extern "C" {
27 #endif
28 
34 RTEMS_INLINE_ROUTINE POSIX_Shm_Control *_POSIX_Shm_Allocate_unprotected( void )
35 {
36  return (POSIX_Shm_Control *)
38 }
39 
46  POSIX_Shm_Control *the_shm
47 )
48 {
49  _Objects_Free( &_POSIX_Shm_Information, &the_shm->Object );
50 }
51 
52 RTEMS_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 {
60  name,
61  name_length_p,
62  error
63  );
64 }
65 
66 RTEMS_INLINE_ROUTINE void _POSIX_Shm_Update_atime(
68 )
69 {
70  struct timeval now;
71  gettimeofday( &now, 0 );
72  shm->atime = now.tv_sec;
73 }
74 
75 RTEMS_INLINE_ROUTINE void _POSIX_Shm_Update_mtime_ctime(
77 )
78 {
79  struct timeval now;
80  gettimeofday( &now, 0 );
81  shm->mtime = now.tv_sec;
82  shm->ctime = now.tv_sec;
83 }
84 
85 static inline POSIX_Shm_Control* iop_to_shm( rtems_libio_t *iop )
86 {
87  return (POSIX_Shm_Control*) iop->data1;
88 }
89 
90 static inline POSIX_Shm_Control* loc_to_shm(
92 )
93 {
94  return (POSIX_Shm_Control*) loc->node_access;
95 }
96 
97 static inline int POSIX_Shm_Attempt_delete(
99 )
100 {
101  Objects_Control *obj;
102  ISR_lock_Context lock_ctx;
103  int err;
104 
105  err = 0;
106 
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  }
124  return err;
125 }
126 
129 #ifdef __cplusplus
130 }
131 #endif
132 
133 #endif
void _Objects_Free(Objects_Information *information, Objects_Control *the_object)
Frees an object.
Definition: objectfree.c:25
Basic IO API.
Definition: objectdata.h:39
Objects_Control * _Objects_Allocate_unprotected(Objects_Information *information)
Allocates an object without locking the allocator mutex.
Definition: objectallocate.c:33
Objects_Control * _Objects_Get_by_name(const Objects_Information *information, const char *name, size_t *name_length_p, Objects_Get_by_name_error *error)
Gets an object control block identified by its name.
Definition: objectnametoidstring.c:25
Internal Support for POSIX Shared Memory.
POSIX API Implementation.
#define RTEMS_INLINE_ROUTINE
Definition: basedefs.h:65
Objects_Control * _Objects_Get(Objects_Id id, ISR_lock_Context *lock_context, const Objects_Information *information)
Maps the specified object identifier to the associated local object control block.
Definition: objectgetlocal.c:28
Control for a POSIX Shared Memory Object.
Definition: shm.h:111
int(* object_delete)(POSIX_Shm_Object *shm_obj)
Deletes the shm_obj.
Definition: shm.h:88
RTEMS_INLINE_ROUTINE void _POSIX_Shm_Free(POSIX_Shm_Control *the_shm)
POSIX Shared Memory Free.
Definition: shmimpl.h:45
Objects_Information _POSIX_Shm_Information
The POSIX Shared Memory objects information.
#define _ISR_lock_ISR_enable(_context)
Restores the saved interrupt state of the ISR lock context.
Definition: isrlock.h:404
RTEMS_INLINE_ROUTINE void _Objects_Allocator_unlock(void)
Unlocks the object allocator mutex.
Definition: objectimpl.h:862
Basic Filesystem Types.
RTEMS_INLINE_ROUTINE void _Objects_Allocator_lock(void)
Locks the object allocator mutex.
Definition: objectimpl.h:850
An open file data structure.
Definition: libio.h:1320
Local ISR lock context for acquire and release pairs.
Definition: isrlock.h:65
Inlined Routines in the Object Handler.
const POSIX_Shm_Object_operations * ops
Implementation-specific operations on shm objects.
Definition: shm.h:56
#define NULL
Requests a GPIO pin group configuration.
Definition: bestcomm_api.h:77
File system location.
Definition: fs.h:53
Objects_Id id
Definition: objectdata.h:43