RTEMS 6.1-rc4
Loading...
Searching...
No Matches
shmimpl.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
10/*
11 * Copyright (c) 2016 Gedare Bloom.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 */
34
35#ifndef _RTEMS_POSIX_SHMIMPL_H
36#define _RTEMS_POSIX_SHMIMPL_H
37
38#include <rtems/fs.h>
39#include <rtems/libio.h>
41#include <rtems/posix/shm.h>
43
44#ifdef __cplusplus
45extern "C" {
46#endif
47
53static inline POSIX_Shm_Control *_POSIX_Shm_Allocate_unprotected( void )
54{
55 return (POSIX_Shm_Control *)
56 _Objects_Allocate_unprotected( &_POSIX_Shm_Information );
57}
58
64static inline void _POSIX_Shm_Free (
65 POSIX_Shm_Control *the_shm
66)
67{
68 _Objects_Free( &_POSIX_Shm_Information, &the_shm->Object );
69}
70
71static inline POSIX_Shm_Control *_POSIX_Shm_Get_by_name(
72 const char *name,
73 size_t *name_length_p,
74 Objects_Get_by_name_error *error
75)
76{
79 name,
80 name_length_p,
81 error
82 );
83}
84
85static inline void _POSIX_Shm_Update_atime(
87)
88{
89 struct timeval now;
90 gettimeofday( &now, 0 );
91 shm->atime = now.tv_sec;
92}
93
94static inline void _POSIX_Shm_Update_mtime_ctime(
96)
97{
98 struct timeval now;
99 gettimeofday( &now, 0 );
100 shm->mtime = now.tv_sec;
101 shm->ctime = now.tv_sec;
102}
103
104static inline POSIX_Shm_Control* iop_to_shm( rtems_libio_t *iop )
105{
106 return (POSIX_Shm_Control*) iop->data1;
107}
108
109static inline POSIX_Shm_Control* loc_to_shm(
111)
112{
113 return (POSIX_Shm_Control*) loc->node_access;
114}
115
116static inline int POSIX_Shm_Attempt_delete(
118)
119{
120 Objects_Control *obj;
121 ISR_lock_Context lock_ctx;
122 int err;
123
124 err = 0;
125
126 _Objects_Allocator_lock();
127 --shm->reference_count;
128 if ( shm->reference_count == 0 ) {
129 if ( (*shm->shm_object.ops->object_delete)( &shm->shm_object ) != 0 ) {
130 err = EIO;
131 }
132 }
133 /* check if the object has been unlinked yet. */
134 obj = _Objects_Get( shm->Object.id, &lock_ctx, &_POSIX_Shm_Information );
135 if ( obj == NULL ) {
136 /* if it was unlinked, then it can be freed. */
137 _POSIX_Shm_Free( shm );
138 } else {
139 /* it will be freed when it is unlinked. */
140 _ISR_lock_ISR_enable( &lock_ctx );
141 }
142 _Objects_Allocator_unlock();
143 return err;
144}
145
148#ifdef __cplusplus
149}
150#endif
151
152#endif
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:385
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:46
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:43
Basic Filesystem Types.
Basic IO API.
This header file provides interfaces used by the POSIX API implementation.
This header file provides interfaces of the Object Handler which are only used by the implementation.
Internal Support for POSIX Shared Memory.
Local ISR lock context for acquire and release pairs.
Definition: isrlock.h:94
Definition: objectdata.h:61
Objects_Id id
Definition: objectdata.h:65
Control for a POSIX Shared Memory Object.
Definition: shm.h:130
int(* object_delete)(POSIX_Shm_Object *shm_obj)
Deletes the shm_obj.
Definition: shm.h:107
const POSIX_Shm_Object_operations * ops
Implementation-specific operations on shm objects.
Definition: shm.h:75
File system location.
Definition: fs.h:72
An open file data structure.
Definition: libio.h:1338