/*
|
/*
|
* Region Manager
|
* Region Manager
|
*
|
*
|
*
|
*
|
* COPYRIGHT (c) 1989-1999.
|
* COPYRIGHT (c) 1989-1999.
|
* On-Line Applications Research Corporation (OAR).
|
* On-Line Applications Research Corporation (OAR).
|
*
|
*
|
* The license and distribution terms for this file may be
|
* The license and distribution terms for this file may be
|
* found in the file LICENSE in this distribution or at
|
* found in the file LICENSE in this distribution or at
|
* http://www.OARcorp.com/rtems/license.html.
|
* http://www.OARcorp.com/rtems/license.html.
|
*
|
*
|
* regiongetsegment.c,v 1.3 2002/07/01 22:32:31 joel Exp
|
* regiongetsegment.c,v 1.3 2002/07/01 22:32:31 joel Exp
|
*/
|
*/
|
|
|
#include <rtems/system.h>
|
#include <rtems/system.h>
|
#include <rtems/rtems/status.h>
|
#include <rtems/rtems/status.h>
|
#include <rtems/rtems/support.h>
|
#include <rtems/rtems/support.h>
|
#include <rtems/score/object.h>
|
#include <rtems/score/object.h>
|
#include <rtems/rtems/options.h>
|
#include <rtems/rtems/options.h>
|
#include <rtems/rtems/region.h>
|
#include <rtems/rtems/region.h>
|
#include <rtems/score/states.h>
|
#include <rtems/score/states.h>
|
#include <rtems/score/thread.h>
|
#include <rtems/score/thread.h>
|
#include <rtems/score/apimutex.h>
|
#include <rtems/score/apimutex.h>
|
|
|
/*PAGE
|
/*PAGE
|
*
|
*
|
* rtems_region_get_segment
|
* rtems_region_get_segment
|
*
|
*
|
* This directive will obtain a segment from the given region.
|
* This directive will obtain a segment from the given region.
|
*
|
*
|
* Input parameters:
|
* Input parameters:
|
* id - region id
|
* id - region id
|
* size - segment size in bytes
|
* size - segment size in bytes
|
* option_set - wait option
|
* option_set - wait option
|
* timeout - number of ticks to wait (0 means wait forever)
|
* timeout - number of ticks to wait (0 means wait forever)
|
* segment - pointer to segment address
|
* segment - pointer to segment address
|
*
|
*
|
* Output parameters:
|
* Output parameters:
|
* segment - pointer to segment address filled in
|
* segment - pointer to segment address filled in
|
* RTEMS_SUCCESSFUL - if successful
|
* RTEMS_SUCCESSFUL - if successful
|
* error code - if unsuccessful
|
* error code - if unsuccessful
|
*/
|
*/
|
|
|
rtems_status_code rtems_region_get_segment(
|
rtems_status_code rtems_region_get_segment(
|
Objects_Id id,
|
Objects_Id id,
|
unsigned32 size,
|
unsigned32 size,
|
rtems_option option_set,
|
rtems_option option_set,
|
rtems_interval timeout,
|
rtems_interval timeout,
|
void **segment
|
void **segment
|
)
|
)
|
{
|
{
|
register Region_Control *the_region;
|
register Region_Control *the_region;
|
Objects_Locations location;
|
Objects_Locations location;
|
Thread_Control *executing;
|
Thread_Control *executing;
|
void *the_segment;
|
void *the_segment;
|
|
|
*segment = NULL;
|
*segment = NULL;
|
|
|
if ( size == 0 )
|
if ( size == 0 )
|
return RTEMS_INVALID_SIZE;
|
return RTEMS_INVALID_SIZE;
|
|
|
_RTEMS_Lock_allocator();
|
_RTEMS_Lock_allocator();
|
executing = _Thread_Executing;
|
executing = _Thread_Executing;
|
the_region = _Region_Get( id, &location );
|
the_region = _Region_Get( id, &location );
|
switch ( location ) {
|
switch ( location ) {
|
case OBJECTS_REMOTE: /* this error cannot be returned */
|
case OBJECTS_REMOTE: /* this error cannot be returned */
|
_RTEMS_Unlock_allocator();
|
_RTEMS_Unlock_allocator();
|
return RTEMS_INTERNAL_ERROR;
|
return RTEMS_INTERNAL_ERROR;
|
|
|
case OBJECTS_ERROR:
|
case OBJECTS_ERROR:
|
_RTEMS_Unlock_allocator();
|
_RTEMS_Unlock_allocator();
|
return RTEMS_INVALID_ID;
|
return RTEMS_INVALID_ID;
|
|
|
case OBJECTS_LOCAL:
|
case OBJECTS_LOCAL:
|
if ( size > the_region->maximum_segment_size ) {
|
if ( size > the_region->maximum_segment_size ) {
|
_RTEMS_Unlock_allocator();
|
_RTEMS_Unlock_allocator();
|
return RTEMS_INVALID_SIZE;
|
return RTEMS_INVALID_SIZE;
|
}
|
}
|
|
|
_Region_Debug_Walk( the_region, 1 );
|
_Region_Debug_Walk( the_region, 1 );
|
|
|
the_segment = _Region_Allocate_segment( the_region, size );
|
the_segment = _Region_Allocate_segment( the_region, size );
|
|
|
_Region_Debug_Walk( the_region, 2 );
|
_Region_Debug_Walk( the_region, 2 );
|
|
|
if ( the_segment ) {
|
if ( the_segment ) {
|
the_region->number_of_used_blocks += 1;
|
the_region->number_of_used_blocks += 1;
|
_RTEMS_Unlock_allocator();
|
_RTEMS_Unlock_allocator();
|
*segment = the_segment;
|
*segment = the_segment;
|
return RTEMS_SUCCESSFUL;
|
return RTEMS_SUCCESSFUL;
|
}
|
}
|
|
|
if ( _Options_Is_no_wait( option_set ) ) {
|
if ( _Options_Is_no_wait( option_set ) ) {
|
_RTEMS_Unlock_allocator();
|
_RTEMS_Unlock_allocator();
|
return RTEMS_UNSATISFIED;
|
return RTEMS_UNSATISFIED;
|
}
|
}
|
|
|
executing->Wait.queue = &the_region->Wait_queue;
|
executing->Wait.queue = &the_region->Wait_queue;
|
executing->Wait.id = id;
|
executing->Wait.id = id;
|
executing->Wait.count = size;
|
executing->Wait.count = size;
|
executing->Wait.return_argument = (unsigned32 *) segment;
|
executing->Wait.return_argument = (unsigned32 *) segment;
|
|
|
_Thread_queue_Enter_critical_section( &the_region->Wait_queue );
|
_Thread_queue_Enter_critical_section( &the_region->Wait_queue );
|
|
|
_Thread_queue_Enqueue( &the_region->Wait_queue, timeout );
|
_Thread_queue_Enqueue( &the_region->Wait_queue, timeout );
|
|
|
_RTEMS_Unlock_allocator();
|
_RTEMS_Unlock_allocator();
|
return (rtems_status_code) executing->Wait.return_code;
|
return (rtems_status_code) executing->Wait.return_code;
|
}
|
}
|
|
|
return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */
|
return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */
|
}
|
}
|
|
|