RTEMS
partreturnbuffer.c
1 /*
2  * Partition Manager
3  *
4  *
5  * COPYRIGHT (c) 1989-2014.
6  * On-Line Applications Research Corporation (OAR).
7  *
8  * The license and distribution terms for this file may be
9  * found in the file LICENSE in this distribution or at
10  * http://www.rtems.org/license/LICENSE.
11  */
12 
13 #ifdef HAVE_CONFIG_H
14 #include "config.h"
15 #endif
16 
17 #include <rtems/rtems/partimpl.h>
18 
20  rtems_id id,
21  void *buffer
22 )
23 {
24  Partition_Control *the_partition;
25  ISR_lock_Context lock_context;
26 
27  the_partition = _Partition_Get( id, &lock_context );
28 
29  if ( the_partition == NULL ) {
30 #if defined(RTEMS_MULTIPROCESSING)
31  return _Partition_MP_Return_buffer( id, buffer );
32 #else
33  return RTEMS_INVALID_ID;
34 #endif
35  }
36 
37  _Partition_Acquire_critical( the_partition, &lock_context );
38 
39  if ( !_Partition_Is_buffer_valid( buffer, the_partition ) ) {
40  _Partition_Release( the_partition, &lock_context );
41  return RTEMS_INVALID_ADDRESS;
42  }
43 
44  _Partition_Free_buffer( the_partition, buffer );
45  the_partition->number_of_used_blocks -= 1;
46  _Partition_Release( the_partition, &lock_context );
47  return RTEMS_SUCCESSFUL;
48 }
static __inline__ void _Partition_Free_buffer(Partition_Control *the_partition, Chain_Node *the_buffer)
Frees the_buffer to the_partition.
Definition: partimpl.h:56
rtems_status_code rtems_partition_return_buffer(rtems_id id, void *buffer)
Returns a buffer to the specified partition.
This status code indicates successful completion.
Definition: status.h:86
rtems_status_code
This enumeration provides status codes for directives of the Classic API.
Definition: status.h:82
uintptr_t number_of_used_blocks
Definition: partdata.h:51
This status code indicates that a specified address was invalid.
Definition: status.h:133
static __inline__ bool _Partition_Is_buffer_valid(Chain_Node *the_buffer, Partition_Control *the_partition)
Checks whether the_buffer is a valid buffer from the_partition.
Definition: partimpl.h:91
This status code indicates that an object identifier was invalid.
Definition: status.h:106
Objects_Id rtems_id
Values of this type identify an RTEMS object.
Definition: types.h:99
Classic Partition Manager Implementation.
Local ISR lock context for acquire and release pairs.
Definition: isrlock.h:65