From 05f9b02e3c0927e69f96bafaac359a53c7f92322 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Fri, 20 May 2016 07:01:03 +0200 Subject: posix: Add and use _POSIX_Get_object_body() --- cpukit/posix/include/rtems/posix/posixapi.h | 32 +++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'cpukit/posix/include/rtems/posix/posixapi.h') diff --git a/cpukit/posix/include/rtems/posix/posixapi.h b/cpukit/posix/include/rtems/posix/posixapi.h index 0348e28e16..f2378c184a 100644 --- a/cpukit/posix/include/rtems/posix/posixapi.h +++ b/cpukit/posix/include/rtems/posix/posixapi.h @@ -21,6 +21,7 @@ #include #include +#include #include /** @@ -59,6 +60,37 @@ RTEMS_INLINE_ROUTINE int _POSIX_Get_by_name_error( return _POSIX_Get_by_name_error_table[ error ]; } +/** + * @brief Macro to generate a function body to get a POSIX object by + * identifier. + * + * Generates a function body to get the object for the specified indentifier. + * Performs automatic initialization if requested and necessary. This is an + * ugly macro, since C lacks support for templates. + */ +#define _POSIX_Get_object_body( \ + type, \ + id, \ + lock_context, \ + info, \ + initializer, \ + init \ +) \ + Objects_Control *the_object; \ + if ( id == NULL ) { \ + return NULL; \ + } \ + the_object = _Objects_Get_local( (Objects_Id) *id, lock_context, info ); \ + if ( the_object == NULL ) { \ + _Once_Lock(); \ + if ( *id == initializer ) { \ + init( id, NULL ); \ + } \ + _Once_Unlock(); \ + the_object = _Objects_Get_local( (Objects_Id) *id, lock_context, info ); \ + } \ + return (type *) the_object + /** @} */ #endif -- cgit v1.2.3