forked from Imagelibrary/rtems
@@ -20,8 +20,8 @@
|
|||||||
#define _RTEMS_RTL_H_
|
#define _RTEMS_RTL_H_
|
||||||
|
|
||||||
#include <link.h>
|
#include <link.h>
|
||||||
#include <rtems.h>
|
|
||||||
#include <rtems/chain.h>
|
#include <rtems/chain.h>
|
||||||
|
#include <rtems/thread.h>
|
||||||
|
|
||||||
#include <rtems/rtl/rtl-allocator.h>
|
#include <rtems/rtl/rtl-allocator.h>
|
||||||
#include <rtems/rtl/rtl-fwd.h>
|
#include <rtems/rtl/rtl-fwd.h>
|
||||||
@@ -96,7 +96,7 @@ typedef void (*rtems_rtl_cdtor_t)(void);
|
|||||||
*/
|
*/
|
||||||
struct rtems_rtl_data_s
|
struct rtems_rtl_data_s
|
||||||
{
|
{
|
||||||
rtems_id lock; /**< The RTL lock id */
|
rtems_recursive_mutex lock; /**< The RTL lock */
|
||||||
rtems_rtl_alloc_data_t allocator; /**< The allocator data. */
|
rtems_rtl_alloc_data_t allocator; /**< The allocator data. */
|
||||||
rtems_chain_control objects; /**< List if loaded object files. */
|
rtems_chain_control objects; /**< List if loaded object files. */
|
||||||
const char* paths; /**< Search paths for archives. */
|
const char* paths; /**< Search paths for archives. */
|
||||||
@@ -183,11 +183,8 @@ rtems_rtl_data_t* rtems_rtl_lock (void);
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Unlock the Run-time Linker.
|
* Unlock the Run-time Linker.
|
||||||
*
|
|
||||||
* @return True The RTL is unlocked.
|
|
||||||
* @return False The RTL could not be unlocked. Not much you can do.
|
|
||||||
*/
|
*/
|
||||||
bool rtems_rtl_unlock (void);
|
void rtems_rtl_unlock (void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check a pointer is a valid object file descriptor returning the pointer as
|
* Check a pointer is a valid object file descriptor returning the pointer as
|
||||||
|
|||||||
@@ -31,13 +31,6 @@
|
|||||||
#include "rtl-string.h"
|
#include "rtl-string.h"
|
||||||
#include <rtems/rtl/rtl-trace.h>
|
#include <rtems/rtl/rtl-trace.h>
|
||||||
|
|
||||||
/**
|
|
||||||
* Semaphore configuration to create a mutex.
|
|
||||||
*/
|
|
||||||
#define RTEMS_MUTEX_ATTRIBS \
|
|
||||||
(RTEMS_PRIORITY | RTEMS_BINARY_SEMAPHORE | \
|
|
||||||
RTEMS_INHERIT_PRIORITY | RTEMS_NO_PRIORITY_CEILING | RTEMS_LOCAL)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Symbol table cache size. They can be big so the cache needs space to work.
|
* Symbol table cache size. They can be big so the cache needs space to work.
|
||||||
*/
|
*/
|
||||||
@@ -92,9 +85,6 @@ rtems_rtl_data_init (void)
|
|||||||
|
|
||||||
if (!rtl)
|
if (!rtl)
|
||||||
{
|
{
|
||||||
rtems_status_code sc;
|
|
||||||
rtems_id lock;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We cannot set an error in this code because there is no RTL data to
|
* We cannot set an error in this code because there is no RTL data to
|
||||||
* hold it.
|
* hold it.
|
||||||
@@ -129,26 +119,8 @@ rtems_rtl_data_init (void)
|
|||||||
/*
|
/*
|
||||||
* Create the RTL lock.
|
* Create the RTL lock.
|
||||||
*/
|
*/
|
||||||
sc = rtems_semaphore_create (rtems_build_name ('R', 'T', 'L', 'D'),
|
rtems_recursive_mutex_init (&rtl->lock, "Run-Time Linker");
|
||||||
1, RTEMS_MUTEX_ATTRIBS,
|
rtems_recursive_mutex_lock (&rtl->lock);
|
||||||
RTEMS_NO_PRIORITY, &lock);
|
|
||||||
if (sc != RTEMS_SUCCESSFUL)
|
|
||||||
{
|
|
||||||
free (rtl);
|
|
||||||
rtems_libio_unlock ();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
sc = rtems_semaphore_obtain (lock, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
|
|
||||||
if (sc != RTEMS_SUCCESSFUL)
|
|
||||||
{
|
|
||||||
rtems_semaphore_delete (lock);
|
|
||||||
free (rtl);
|
|
||||||
rtems_libio_unlock ();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
rtl->lock = lock;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialise the objects list and create any required services.
|
* Initialise the objects list and create any required services.
|
||||||
@@ -158,7 +130,7 @@ rtems_rtl_data_init (void)
|
|||||||
if (!rtems_rtl_symbol_table_open (&rtl->globals,
|
if (!rtems_rtl_symbol_table_open (&rtl->globals,
|
||||||
RTEMS_RTL_SYMS_GLOBAL_BUCKETS))
|
RTEMS_RTL_SYMS_GLOBAL_BUCKETS))
|
||||||
{
|
{
|
||||||
rtems_semaphore_delete (lock);
|
rtems_recursive_mutex_destroy (&rtl->lock);
|
||||||
free (rtl);
|
free (rtl);
|
||||||
rtems_libio_unlock ();
|
rtems_libio_unlock ();
|
||||||
return false;
|
return false;
|
||||||
@@ -168,7 +140,7 @@ rtems_rtl_data_init (void)
|
|||||||
RTEMS_RTL_UNRESOLVED_BLOCK_SIZE))
|
RTEMS_RTL_UNRESOLVED_BLOCK_SIZE))
|
||||||
{
|
{
|
||||||
rtems_rtl_symbol_table_close (&rtl->globals);
|
rtems_rtl_symbol_table_close (&rtl->globals);
|
||||||
rtems_semaphore_delete (lock);
|
rtems_recursive_mutex_destroy (&rtl->lock);
|
||||||
free (rtl);
|
free (rtl);
|
||||||
rtems_libio_unlock ();
|
rtems_libio_unlock ();
|
||||||
return false;
|
return false;
|
||||||
@@ -179,7 +151,7 @@ rtems_rtl_data_init (void)
|
|||||||
{
|
{
|
||||||
rtems_rtl_symbol_table_close (&rtl->globals);
|
rtems_rtl_symbol_table_close (&rtl->globals);
|
||||||
rtems_rtl_unresolved_table_close (&rtl->unresolved);
|
rtems_rtl_unresolved_table_close (&rtl->unresolved);
|
||||||
rtems_semaphore_delete (lock);
|
rtems_recursive_mutex_destroy (&rtl->lock);
|
||||||
free (rtl);
|
free (rtl);
|
||||||
rtems_libio_unlock ();
|
rtems_libio_unlock ();
|
||||||
return false;
|
return false;
|
||||||
@@ -191,7 +163,7 @@ rtems_rtl_data_init (void)
|
|||||||
rtems_rtl_obj_cache_close (&rtl->symbols);
|
rtems_rtl_obj_cache_close (&rtl->symbols);
|
||||||
rtems_rtl_unresolved_table_close (&rtl->unresolved);
|
rtems_rtl_unresolved_table_close (&rtl->unresolved);
|
||||||
rtems_rtl_symbol_table_close (&rtl->globals);
|
rtems_rtl_symbol_table_close (&rtl->globals);
|
||||||
rtems_semaphore_delete (lock);
|
rtems_recursive_mutex_destroy (&rtl->lock);
|
||||||
free (rtl);
|
free (rtl);
|
||||||
rtems_libio_unlock ();
|
rtems_libio_unlock ();
|
||||||
return false;
|
return false;
|
||||||
@@ -204,7 +176,7 @@ rtems_rtl_data_init (void)
|
|||||||
rtems_rtl_obj_cache_close (&rtl->symbols);
|
rtems_rtl_obj_cache_close (&rtl->symbols);
|
||||||
rtems_rtl_unresolved_table_close (&rtl->unresolved);
|
rtems_rtl_unresolved_table_close (&rtl->unresolved);
|
||||||
rtems_rtl_symbol_table_close (&rtl->globals);
|
rtems_rtl_symbol_table_close (&rtl->globals);
|
||||||
rtems_semaphore_delete (lock);
|
rtems_recursive_mutex_destroy (&rtl->lock);
|
||||||
free (rtl);
|
free (rtl);
|
||||||
rtems_libio_unlock ();
|
rtems_libio_unlock ();
|
||||||
return false;
|
return false;
|
||||||
@@ -218,7 +190,7 @@ rtems_rtl_data_init (void)
|
|||||||
rtems_rtl_obj_cache_close (&rtl->symbols);
|
rtems_rtl_obj_cache_close (&rtl->symbols);
|
||||||
rtems_rtl_unresolved_table_close (&rtl->unresolved);
|
rtems_rtl_unresolved_table_close (&rtl->unresolved);
|
||||||
rtems_rtl_symbol_table_close (&rtl->globals);
|
rtems_rtl_symbol_table_close (&rtl->globals);
|
||||||
rtems_semaphore_delete (lock);
|
rtems_recursive_mutex_destroy (&rtl->lock);
|
||||||
free (rtl);
|
free (rtl);
|
||||||
rtems_libio_unlock ();
|
rtems_libio_unlock ();
|
||||||
return false;
|
return false;
|
||||||
@@ -233,7 +205,7 @@ rtems_rtl_data_init (void)
|
|||||||
rtems_rtl_obj_cache_close (&rtl->symbols);
|
rtems_rtl_obj_cache_close (&rtl->symbols);
|
||||||
rtems_rtl_unresolved_table_close (&rtl->unresolved);
|
rtems_rtl_unresolved_table_close (&rtl->unresolved);
|
||||||
rtems_rtl_symbol_table_close (&rtl->globals);
|
rtems_rtl_symbol_table_close (&rtl->globals);
|
||||||
rtems_semaphore_delete (lock);
|
rtems_recursive_mutex_destroy (&rtl->lock);
|
||||||
free (rtl);
|
free (rtl);
|
||||||
rtems_libio_unlock ();
|
rtems_libio_unlock ();
|
||||||
return false;
|
return false;
|
||||||
@@ -343,36 +315,18 @@ rtems_rtl_obj_comp (rtems_rtl_obj_comp_t** decomp,
|
|||||||
rtems_rtl_data_t*
|
rtems_rtl_data_t*
|
||||||
rtems_rtl_lock (void)
|
rtems_rtl_lock (void)
|
||||||
{
|
{
|
||||||
rtems_status_code sc;
|
|
||||||
|
|
||||||
if (!rtems_rtl_data_init ())
|
if (!rtems_rtl_data_init ())
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
sc = rtems_semaphore_obtain (rtl->lock,
|
rtems_recursive_mutex_lock (&rtl->lock);
|
||||||
RTEMS_WAIT, RTEMS_NO_TIMEOUT);
|
|
||||||
if (sc != RTEMS_SUCCESSFUL)
|
|
||||||
{
|
|
||||||
errno = EINVAL;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return rtl;
|
return rtl;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
void
|
||||||
rtems_rtl_unlock (void)
|
rtems_rtl_unlock (void)
|
||||||
{
|
{
|
||||||
/*
|
rtems_recursive_mutex_unlock (&rtl->lock);
|
||||||
* Not sure any error should be returned or an assert.
|
|
||||||
*/
|
|
||||||
rtems_status_code sc;
|
|
||||||
sc = rtems_semaphore_release (rtl->lock);
|
|
||||||
if ((sc != RTEMS_SUCCESSFUL) && (errno == 0))
|
|
||||||
{
|
|
||||||
errno = EINVAL;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rtems_rtl_obj_t*
|
rtems_rtl_obj_t*
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ static void dl_init_rtl(void)
|
|||||||
*/
|
*/
|
||||||
rtems_test_assert(rtems_rtl_data () == NULL);
|
rtems_test_assert(rtems_rtl_data () == NULL);
|
||||||
rtems_test_assert(rtems_rtl_lock () != NULL);
|
rtems_test_assert(rtems_rtl_lock () != NULL);
|
||||||
rtems_test_assert(rtems_rtl_unlock () == true);
|
rtems_rtl_unlock ();
|
||||||
rtems_test_assert(rtems_rtl_data () != NULL);
|
rtems_test_assert(rtems_rtl_data () != NULL);
|
||||||
rtems_rtl_trace_set_mask(RTEMS_RTL_TRACE_ALL | RTEMS_RTL_TRACE_CACHE);
|
rtems_rtl_trace_set_mask(RTEMS_RTL_TRACE_ALL | RTEMS_RTL_TRACE_CACHE);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user