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 |
---|
26 | extern "C" { |
---|
27 | #endif |
---|
28 | |
---|
29 | /** |
---|
30 | * @ingroup POSIXShmPrivate |
---|
31 | * @{ |
---|
32 | */ |
---|
33 | |
---|
34 | extern Objects_Information _POSIX_Shm_Information; |
---|
35 | |
---|
36 | RTEMS_INLINE_ROUTINE POSIX_Shm_Control *_POSIX_Shm_Allocate_unprotected( void ) |
---|
37 | { |
---|
38 | return (POSIX_Shm_Control *) |
---|
39 | _Objects_Allocate_unprotected( &_POSIX_Shm_Information ); |
---|
40 | } |
---|
41 | |
---|
42 | /** |
---|
43 | * @brief POSIX Shared Memory Free |
---|
44 | * |
---|
45 | * This routine frees a shm control block. |
---|
46 | */ |
---|
47 | RTEMS_INLINE_ROUTINE void _POSIX_Shm_Free ( |
---|
48 | POSIX_Shm_Control *the_shm |
---|
49 | ) |
---|
50 | { |
---|
51 | _Objects_Free( &_POSIX_Shm_Information, &the_shm->Object ); |
---|
52 | } |
---|
53 | |
---|
54 | RTEMS_INLINE_ROUTINE POSIX_Shm_Control *_POSIX_Shm_Get_by_name( |
---|
55 | const char *name, |
---|
56 | size_t *name_length_p, |
---|
57 | Objects_Get_by_name_error *error |
---|
58 | ) |
---|
59 | { |
---|
60 | return (POSIX_Shm_Control *) _Objects_Get_by_name( |
---|
61 | &_POSIX_Shm_Information, |
---|
62 | name, |
---|
63 | name_length_p, |
---|
64 | error |
---|
65 | ); |
---|
66 | } |
---|
67 | |
---|
68 | RTEMS_INLINE_ROUTINE void _POSIX_Shm_Update_atime( |
---|
69 | POSIX_Shm_Control *shm |
---|
70 | ) |
---|
71 | { |
---|
72 | struct timeval now; |
---|
73 | gettimeofday( &now, 0 ); |
---|
74 | shm->atime = now.tv_sec; |
---|
75 | } |
---|
76 | |
---|
77 | RTEMS_INLINE_ROUTINE void _POSIX_Shm_Update_mtime_ctime( |
---|
78 | POSIX_Shm_Control *shm |
---|
79 | ) |
---|
80 | { |
---|
81 | struct timeval now; |
---|
82 | gettimeofday( &now, 0 ); |
---|
83 | shm->mtime = now.tv_sec; |
---|
84 | shm->ctime = now.tv_sec; |
---|
85 | } |
---|
86 | |
---|
87 | static inline POSIX_Shm_Control* iop_to_shm( rtems_libio_t *iop ) |
---|
88 | { |
---|
89 | return (POSIX_Shm_Control*) iop->data1; |
---|
90 | } |
---|
91 | |
---|
92 | static inline POSIX_Shm_Control* loc_to_shm( |
---|
93 | const rtems_filesystem_location_info_t *loc |
---|
94 | ) |
---|
95 | { |
---|
96 | return (POSIX_Shm_Control*) loc->node_access; |
---|
97 | } |
---|
98 | |
---|
99 | static inline int POSIX_Shm_Attempt_delete( |
---|
100 | POSIX_Shm_Control* shm |
---|
101 | ) |
---|
102 | { |
---|
103 | Objects_Control *obj; |
---|
104 | ISR_lock_Context lock_ctx; |
---|
105 | int err; |
---|
106 | |
---|
107 | err = 0; |
---|
108 | |
---|
109 | _Objects_Allocator_lock(); |
---|
110 | --shm->reference_count; |
---|
111 | if ( shm->reference_count == 0 ) { |
---|
112 | if ( (*shm->shm_object.ops->object_delete)( &shm->shm_object ) != 0 ) { |
---|
113 | err = EIO; |
---|
114 | } |
---|
115 | } |
---|
116 | /* check if the object has been unlinked yet. */ |
---|
117 | obj = _Objects_Get( shm->Object.id, &lock_ctx, &_POSIX_Shm_Information ); |
---|
118 | if ( obj == NULL ) { |
---|
119 | /* if it was unlinked, then it can be freed. */ |
---|
120 | _POSIX_Shm_Free( shm ); |
---|
121 | } else { |
---|
122 | /* it will be freed when it is unlinked. */ |
---|
123 | _ISR_lock_ISR_enable( &lock_ctx ); |
---|
124 | } |
---|
125 | _Objects_Allocator_unlock(); |
---|
126 | return err; |
---|
127 | } |
---|
128 | |
---|
129 | /** @} */ |
---|
130 | |
---|
131 | #ifdef __cplusplus |
---|
132 | } |
---|
133 | #endif |
---|
134 | |
---|
135 | #endif |
---|