diff options
Diffstat (limited to 'cpukit/posix')
-rw-r--r-- | cpukit/posix/src/key.c | 175 | ||||
-rw-r--r-- | cpukit/posix/src/keycreate.c | 119 | ||||
-rw-r--r-- | cpukit/posix/src/keyzerokvp.c | 36 | ||||
-rw-r--r-- | cpukit/posix/src/mqueue.c | 81 | ||||
-rw-r--r-- | cpukit/posix/src/mqueueopen.c | 12 | ||||
-rw-r--r-- | cpukit/posix/src/psxsemaphore.c | 72 | ||||
-rw-r--r-- | cpukit/posix/src/psxtimercreate.c | 17 | ||||
-rw-r--r-- | cpukit/posix/src/pthread.c | 191 | ||||
-rw-r--r-- | cpukit/posix/src/pthreadcreate.c | 138 | ||||
-rw-r--r-- | cpukit/posix/src/ptimer.c | 94 | ||||
-rw-r--r-- | cpukit/posix/src/semopen.c | 12 | ||||
-rw-r--r-- | cpukit/posix/src/shm.c | 66 | ||||
-rw-r--r-- | cpukit/posix/src/shmopen.c | 12 |
13 files changed, 510 insertions, 515 deletions
diff --git a/cpukit/posix/src/key.c b/cpukit/posix/src/key.c index a39e8d6479..0309a26da5 100644 --- a/cpukit/posix/src/key.c +++ b/cpukit/posix/src/key.c @@ -1,158 +1,47 @@ /** * @file * - * @brief POSIX Keys Manager Initialization - * @ingroup POSIX_KEY Key + * @ingroup POSIX_KEY + * + * @brief POSIX Keys Information with Zero Objects */ /* - * Copyright (c) 2012 Zhongwei Yao. - * COPYRIGHT (c) 1989-2014. - * On-Line Applications Research Corporation (OAR). - * Copyright (c) 2016 embedded brains GmbH. + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (C) 2018 embedded brains GmbH * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. */ #if HAVE_CONFIG_H #include "config.h" #endif -#include <limits.h> - -#include <rtems/config.h> -#include <rtems/sysinit.h> - -#include <rtems/posix/keyimpl.h> -#include <rtems/score/userextimpl.h> -#include <rtems/score/wkspace.h> - -Objects_Information _POSIX_Keys_Information; - -Freechain_Control _POSIX_Keys_Keypool; - -static uint32_t _POSIX_Keys_Get_keypool_bump_count( void ) -{ - uint32_t max = Configuration.maximum_key_value_pairs; - - return _Objects_Is_unlimited( max ) ? - _Objects_Maximum_per_allocation( max ) : 0; -} - -static uint32_t _POSIX_Keys_Get_initial_keypool_size( void ) -{ - uint32_t max = Configuration.maximum_key_value_pairs; - - return _Objects_Maximum_per_allocation( max ); -} - -static void _POSIX_Keys_Initialize_keypool( void ) -{ - _Freechain_Initialize( - &_POSIX_Keys_Keypool, - _Workspace_Allocate_or_fatal_error, - _POSIX_Keys_Get_initial_keypool_size(), - sizeof( POSIX_Keys_Key_value_pair ) - ); -} - -POSIX_Keys_Key_value_pair * _POSIX_Keys_Key_value_allocate( void ) -{ - return (POSIX_Keys_Key_value_pair *) _Freechain_Get( - &_POSIX_Keys_Keypool, - _Workspace_Allocate, - _POSIX_Keys_Get_keypool_bump_count(), - sizeof( POSIX_Keys_Key_value_pair ) - ); -} - -static void _POSIX_Keys_Run_destructors( Thread_Control *the_thread ) -{ - while ( true ) { - ISR_lock_Context lock_context; - RBTree_Node *node; - - _Objects_Allocator_lock(); - _POSIX_Keys_Key_value_acquire( the_thread, &lock_context ); - - node = _RBTree_Root( &the_thread->Keys.Key_value_pairs ); - if ( node != NULL ) { - POSIX_Keys_Key_value_pair *key_value_pair; - pthread_key_t key; - void *value; - POSIX_Keys_Control *the_key; - void ( *destructor )( void * ); - - key_value_pair = POSIX_KEYS_RBTREE_NODE_TO_KEY_VALUE_PAIR( node ); - key = key_value_pair->key; - value = key_value_pair->value; - _RBTree_Extract( - &the_thread->Keys.Key_value_pairs, - &key_value_pair->Lookup_node - ); - - _POSIX_Keys_Key_value_release( the_thread, &lock_context ); - _POSIX_Keys_Key_value_free( key_value_pair ); - - the_key = _POSIX_Keys_Get( key ); - _Assert( the_key != NULL ); - destructor = the_key->destructor; - - _Objects_Allocator_unlock(); - - if ( destructor != NULL && value != NULL ) { - ( *destructor )( value ); - } - } else { - _POSIX_Keys_Key_value_release( the_thread, &lock_context ); - _Objects_Allocator_unlock(); - break; - } - } -} - -static void _POSIX_Keys_Restart_run_destructors( - Thread_Control *executing, - Thread_Control *the_thread -) -{ - (void) executing; - _POSIX_Keys_Run_destructors( the_thread ); -} - -static User_extensions_Control _POSIX_Keys_Extensions = { - .Callouts = { - .thread_restart = _POSIX_Keys_Restart_run_destructors, - .thread_terminate = _POSIX_Keys_Run_destructors - } -}; - -/** - * @brief This routine performs the initialization necessary for this manager. - */ -static void _POSIX_Keys_Manager_initialization(void) -{ - _Objects_Initialize_information( - &_POSIX_Keys_Information, /* object information table */ - OBJECTS_POSIX_API, /* object API */ - OBJECTS_POSIX_KEYS, /* object class */ - Configuration.maximum_keys, - /* maximum objects of this class */ - sizeof( POSIX_Keys_Control ), - /* size of this object's control block */ - OBJECTS_NO_STRING_NAME, /* maximum length of each object's name */ - NULL /* Proxy extraction support callout */ - ); - - _POSIX_Keys_Initialize_keypool(); - - _User_extensions_Add_API_set( &_POSIX_Keys_Extensions ); -} +#include <rtems/posix/key.h> -RTEMS_SYSINIT_ITEM( - _POSIX_Keys_Manager_initialization, - RTEMS_SYSINIT_POSIX_KEYS, - RTEMS_SYSINIT_ORDER_MIDDLE +OBJECTS_INFORMATION_DEFINE_ZERO( + _POSIX_Keys, + OBJECTS_POSIX_API, + OBJECTS_POSIX_KEYS, + OBJECTS_NO_STRING_NAME ); diff --git a/cpukit/posix/src/keycreate.c b/cpukit/posix/src/keycreate.c index 432bfd86b6..b4f1c87335 100644 --- a/cpukit/posix/src/keycreate.c +++ b/cpukit/posix/src/keycreate.c @@ -20,6 +20,9 @@ #endif #include <rtems/posix/keyimpl.h> +#include <rtems/score/userextimpl.h> +#include <rtems/score/wkspace.h> +#include <rtems/sysinit.h> #include <errno.h> @@ -47,3 +50,119 @@ int pthread_key_create( _Objects_Allocator_unlock(); return 0; } + +Freechain_Control _POSIX_Keys_Keypool; + +static uint32_t _POSIX_Keys_Get_keypool_bump_count( void ) +{ + uint32_t max; + + max = _POSIX_Keys_Key_value_pair_maximum; + return _Objects_Is_unlimited( max ) ? + _Objects_Maximum_per_allocation( max ) : 0; +} + +static uint32_t _POSIX_Keys_Get_initial_keypool_size( void ) +{ + uint32_t max; + + max = _POSIX_Keys_Key_value_pair_maximum; + return _Objects_Maximum_per_allocation( max ); +} + +static void _POSIX_Keys_Initialize_keypool( void ) +{ + _Freechain_Initialize( + &_POSIX_Keys_Keypool, + _POSIX_Keys_Key_value_pairs, + _POSIX_Keys_Get_initial_keypool_size(), + sizeof( _POSIX_Keys_Key_value_pairs[ 0 ] ) + ); +} + +POSIX_Keys_Key_value_pair * _POSIX_Keys_Key_value_allocate( void ) +{ + return (POSIX_Keys_Key_value_pair *) _Freechain_Get( + &_POSIX_Keys_Keypool, + _Workspace_Allocate, + _POSIX_Keys_Get_keypool_bump_count(), + sizeof( POSIX_Keys_Key_value_pair ) + ); +} + +static void _POSIX_Keys_Run_destructors( Thread_Control *the_thread ) +{ + while ( true ) { + ISR_lock_Context lock_context; + RBTree_Node *node; + + _Objects_Allocator_lock(); + _POSIX_Keys_Key_value_acquire( the_thread, &lock_context ); + + node = _RBTree_Root( &the_thread->Keys.Key_value_pairs ); + if ( node != NULL ) { + POSIX_Keys_Key_value_pair *key_value_pair; + pthread_key_t key; + void *value; + POSIX_Keys_Control *the_key; + void ( *destructor )( void * ); + + key_value_pair = POSIX_KEYS_RBTREE_NODE_TO_KEY_VALUE_PAIR( node ); + key = key_value_pair->key; + value = key_value_pair->value; + _RBTree_Extract( + &the_thread->Keys.Key_value_pairs, + &key_value_pair->Lookup_node + ); + + _POSIX_Keys_Key_value_release( the_thread, &lock_context ); + _POSIX_Keys_Key_value_free( key_value_pair ); + + the_key = _POSIX_Keys_Get( key ); + _Assert( the_key != NULL ); + destructor = the_key->destructor; + + _Objects_Allocator_unlock(); + + if ( destructor != NULL && value != NULL ) { + ( *destructor )( value ); + } + } else { + _POSIX_Keys_Key_value_release( the_thread, &lock_context ); + _Objects_Allocator_unlock(); + break; + } + } +} + +static void _POSIX_Keys_Restart_run_destructors( + Thread_Control *executing, + Thread_Control *the_thread +) +{ + (void) executing; + _POSIX_Keys_Run_destructors( the_thread ); +} + +static User_extensions_Control _POSIX_Keys_Extensions = { + .Callouts = { + .thread_restart = _POSIX_Keys_Restart_run_destructors, + .thread_terminate = _POSIX_Keys_Run_destructors + } +}; + +/** + * @brief This routine performs the initialization necessary for this manager. + */ +static void _POSIX_Keys_Manager_initialization(void) +{ + _Objects_Initialize_information( &_POSIX_Keys_Information ); + _POSIX_Keys_Initialize_keypool(); + _User_extensions_Add_API_set( &_POSIX_Keys_Extensions ); +} + +RTEMS_SYSINIT_ITEM( + _POSIX_Keys_Manager_initialization, + RTEMS_SYSINIT_POSIX_KEYS, + RTEMS_SYSINIT_ORDER_MIDDLE +); diff --git a/cpukit/posix/src/keyzerokvp.c b/cpukit/posix/src/keyzerokvp.c new file mode 100644 index 0000000000..0419678821 --- /dev/null +++ b/cpukit/posix/src/keyzerokvp.c @@ -0,0 +1,36 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (C) 2018 embedded brains GmbH + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#include <rtems/posix/key.h> + +POSIX_Keys_Key_value_pair _POSIX_Keys_Key_value_pairs[ 0 ]; + +const uint32_t _POSIX_Keys_Key_value_pair_maximum; diff --git a/cpukit/posix/src/mqueue.c b/cpukit/posix/src/mqueue.c index 192d853c35..21c5feb8be 100644 --- a/cpukit/posix/src/mqueue.c +++ b/cpukit/posix/src/mqueue.c @@ -1,66 +1,49 @@ /** * @file * - * @brief Initializes message_queue Manager Related Data Structures - * @ingroup POSIX_MQUEUE_P Message Queues Private Support Information + * @ingroup POSIX_MQUEUE_P + * + * @brief POSIX Message Queue Information with Zero Objects */ /* - * COPYRIGHT (c) 1989-2008. - * On-Line Applications Research Corporation (OAR). + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (C) 2018 embedded brains GmbH * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. */ #if HAVE_CONFIG_H #include "config.h" #endif -#include <stdarg.h> - -#include <pthread.h> -#include <errno.h> -#include <fcntl.h> -#include <mqueue.h> -#include <limits.h> - -#include <rtems/system.h> -#include <rtems/config.h> -#include <rtems/sysinit.h> -#include <rtems/score/watchdog.h> -#include <rtems/seterr.h> #include <rtems/posix/mqueueimpl.h> -Objects_Information _POSIX_Message_queue_Information; - -/* - * _POSIX_Message_queue_Manager_initialization - * - * This routine initializes all message_queue manager related data structures. - * - * Input parameters: NONE - * - * Output parameters: NONE - */ - -static void _POSIX_Message_queue_Manager_initialization(void) -{ - _Objects_Initialize_information( - &_POSIX_Message_queue_Information, /* object information table */ - OBJECTS_POSIX_API, /* object API */ - OBJECTS_POSIX_MESSAGE_QUEUES, /* object class */ - _Configuration_POSIX_Maximum_message_queues, - sizeof( POSIX_Message_queue_Control ), - /* size of this object's control block */ - _POSIX_PATH_MAX, /* maximum length of each object's name */ - NULL /* Proxy extraction support callout */ - ); -} +#include <limits.h> -RTEMS_SYSINIT_ITEM( - _POSIX_Message_queue_Manager_initialization, - RTEMS_SYSINIT_POSIX_MESSAGE_QUEUE, - RTEMS_SYSINIT_ORDER_MIDDLE +OBJECTS_INFORMATION_DEFINE_ZERO( + _POSIX_Message_queue, + OBJECTS_POSIX_API, + OBJECTS_POSIX_MESSAGE_QUEUES, + _POSIX_PATH_MAX ); diff --git a/cpukit/posix/src/mqueueopen.c b/cpukit/posix/src/mqueueopen.c index fe63d4ea6e..4bb8025e65 100644 --- a/cpukit/posix/src/mqueueopen.c +++ b/cpukit/posix/src/mqueueopen.c @@ -32,6 +32,7 @@ #include <rtems/posix/mqueueimpl.h> #include <rtems/score/wkspace.h> +#include <rtems/sysinit.h> #include <stdarg.h> #include <fcntl.h> @@ -191,3 +192,14 @@ mqd_t mq_open( _Objects_Allocator_unlock(); return status; } + +static void _POSIX_Message_queue_Manager_initialization( void ) +{ + _Objects_Initialize_information( &_POSIX_Message_queue_Information ); +} + +RTEMS_SYSINIT_ITEM( + _POSIX_Message_queue_Manager_initialization, + RTEMS_SYSINIT_POSIX_MESSAGE_QUEUE, + RTEMS_SYSINIT_ORDER_MIDDLE +); diff --git a/cpukit/posix/src/psxsemaphore.c b/cpukit/posix/src/psxsemaphore.c index a26ba7563e..952587a19f 100644 --- a/cpukit/posix/src/psxsemaphore.c +++ b/cpukit/posix/src/psxsemaphore.c @@ -1,57 +1,49 @@ /** * @file * - * @brief POSIX Function Initializes Semaphore Manager - * @ingroup POSIXAPI + * @ingroup POSIXSemaphorePrivate + * + * @brief POSIX Semaphore Information with Zero Objects */ /* - * COPYRIGHT (c) 1989-2008. - * On-Line Applications Research Corporation (OAR). + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (C) 2018 embedded brains GmbH + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. */ #if HAVE_CONFIG_H #include "config.h" #endif -#include <rtems/posix/semaphoreimpl.h> -#include <rtems/config.h> -#include <rtems/sysinit.h> +#include <rtems/posix/semaphore.h> #include <limits.h> -Objects_Information _POSIX_Semaphore_Information; - -/* - * _POSIX_Semaphore_Manager_initialization - * - * This routine initializes all semaphore manager related data structures. - * - * Input parameters: NONE - * - * Output parameters: NONE - */ - -static void _POSIX_Semaphore_Manager_initialization(void) -{ - _Objects_Initialize_information( - &_POSIX_Semaphore_Information, /* object information table */ - OBJECTS_POSIX_API, /* object API */ - OBJECTS_POSIX_SEMAPHORES, /* object class */ - _Configuration_POSIX_Maximum_named_semaphores, - sizeof( POSIX_Semaphore_Control ), - /* size of this object's control block */ - _POSIX_PATH_MAX, /* maximum length of each object's name */ - NULL /* Proxy extraction support callout */ - ); -} - -RTEMS_SYSINIT_ITEM( - _POSIX_Semaphore_Manager_initialization, - RTEMS_SYSINIT_POSIX_SEMAPHORE, - RTEMS_SYSINIT_ORDER_MIDDLE +OBJECTS_INFORMATION_DEFINE_ZERO( + _POSIX_Semaphore, + OBJECTS_POSIX_API, + OBJECTS_POSIX_SEMAPHORES, + _POSIX_PATH_MAX ); diff --git a/cpukit/posix/src/psxtimercreate.c b/cpukit/posix/src/psxtimercreate.c index 5123071d99..ba5d066194 100644 --- a/cpukit/posix/src/psxtimercreate.c +++ b/cpukit/posix/src/psxtimercreate.c @@ -24,12 +24,12 @@ #include <errno.h> #include <signal.h> -#include <rtems/system.h> -#include <rtems/seterr.h> -#include <rtems/score/thread.h> #include <rtems/posix/sigset.h> #include <rtems/posix/timerimpl.h> +#include <rtems/score/thread.h> #include <rtems/score/watchdogimpl.h> +#include <rtems/seterr.h> +#include <rtems/sysinit.h> int timer_create( clockid_t clock_id, @@ -99,3 +99,14 @@ int timer_create( _Objects_Allocator_unlock(); return 0; } + +static void _POSIX_Timer_Manager_initialization( void ) +{ + _Objects_Initialize_information( &_POSIX_Timer_Information ); +} + +RTEMS_SYSINIT_ITEM( + _POSIX_Timer_Manager_initialization, + RTEMS_SYSINIT_POSIX_TIMER, + RTEMS_SYSINIT_ORDER_MIDDLE +); diff --git a/cpukit/posix/src/pthread.c b/cpukit/posix/src/pthread.c index 0a790f9371..18c8635497 100644 --- a/cpukit/posix/src/pthread.c +++ b/cpukit/posix/src/pthread.c @@ -17,192 +17,11 @@ #if HAVE_CONFIG_H #include "config.h" #endif -#include <stdio.h> -#include <errno.h> -#include <pthread.h> -#include <limits.h> -#include <assert.h> +#include <rtems/posix/pthread.h> -#include <rtems/system.h> -#include <rtems/config.h> -#include <rtems/sysinit.h> -#include <rtems/score/stack.h> -#include <rtems/score/threadimpl.h> -#include <rtems/score/threadqimpl.h> -#include <rtems/score/userextimpl.h> -#include <rtems/score/wkspace.h> -#include <rtems/posix/pthreadimpl.h> -#include <rtems/posix/priorityimpl.h> -#if defined(RTEMS_POSIX_API) -#include <rtems/posix/psignalimpl.h> -#endif -#include <rtems/posix/config.h> -#include <rtems/posix/keyimpl.h> -#include <rtems/score/assert.h> -#include <rtems/score/schedulerimpl.h> - -Thread_Information _POSIX_Threads_Information; - -#if defined(RTEMS_POSIX_API) -void _POSIX_Threads_Sporadic_timer( Watchdog_Control *watchdog ) -{ - POSIX_API_Control *api; - Thread_Control *the_thread; - Thread_queue_Context queue_context; - - api = RTEMS_CONTAINER_OF( watchdog, POSIX_API_Control, Sporadic.Timer ); - the_thread = api->Sporadic.thread; - - _Thread_queue_Context_initialize( &queue_context ); - _Thread_queue_Context_clear_priority_updates( &queue_context ); - _Thread_Wait_acquire( the_thread, &queue_context ); - - if ( _Priority_Node_is_active( &api->Sporadic.Low_priority ) ) { - _Thread_Priority_add( - the_thread, - &the_thread->Real_priority, - &queue_context - ); - _Thread_Priority_remove( - the_thread, - &api->Sporadic.Low_priority, - &queue_context - ); - _Priority_Node_set_inactive( &api->Sporadic.Low_priority ); - } - - _Watchdog_Per_CPU_remove_ticks( &api->Sporadic.Timer ); - _POSIX_Threads_Sporadic_timer_insert( the_thread, api ); - - _Thread_Wait_release( the_thread, &queue_context ); - _Thread_Priority_update( &queue_context ); -} - -void _POSIX_Threads_Sporadic_budget_callout( Thread_Control *the_thread ) -{ - POSIX_API_Control *api; - Thread_queue_Context queue_context; - - api = the_thread->API_Extensions[ THREAD_API_POSIX ]; - - _Thread_queue_Context_initialize( &queue_context ); - _Thread_queue_Context_clear_priority_updates( &queue_context ); - _Thread_Wait_acquire( the_thread, &queue_context ); - - /* - * This will prevent the thread from consuming its entire "budget" - * while at low priority. - */ - the_thread->cpu_time_budget = UINT32_MAX; - - if ( !_Priority_Node_is_active( &api->Sporadic.Low_priority ) ) { - _Thread_Priority_add( - the_thread, - &api->Sporadic.Low_priority, - &queue_context - ); - _Thread_Priority_remove( - the_thread, - &the_thread->Real_priority, - &queue_context - ); - } - - _Thread_Wait_release( the_thread, &queue_context ); - _Thread_Priority_update( &queue_context ); -} - -/* - * _POSIX_Threads_Create_extension - * - * This method is invoked for each thread created. - */ - -static bool _POSIX_Threads_Create_extension( - Thread_Control *executing RTEMS_UNUSED, - Thread_Control *created -) -{ - POSIX_API_Control *api; - - api = created->API_Extensions[ THREAD_API_POSIX ]; - - api->Sporadic.thread = created; - _Watchdog_Preinitialize( &api->Sporadic.Timer, _Per_CPU_Get_by_index( 0 ) ); - _Watchdog_Initialize( &api->Sporadic.Timer, _POSIX_Threads_Sporadic_timer ); - _Priority_Node_set_inactive( &api->Sporadic.Low_priority ); - - return true; -} - -static void _POSIX_Threads_Terminate_extension( Thread_Control *executing ) -{ - POSIX_API_Control *api; - ISR_lock_Context lock_context; - - api = executing->API_Extensions[ THREAD_API_POSIX ]; - - _Thread_State_acquire( executing, &lock_context ); - _Watchdog_Per_CPU_remove_ticks( &api->Sporadic.Timer ); - _Thread_State_release( executing, &lock_context ); -} -#endif - -/* - * _POSIX_Threads_Exitted_extension - * - * This method is invoked each time a thread exits. - */ -static void _POSIX_Threads_Exitted_extension( - Thread_Control *executing -) -{ - /* - * If the executing thread was not created with the POSIX API, then this - * API do not get to define its exit behavior. - */ - if ( _Objects_Get_API( executing->Object.id ) == OBJECTS_POSIX_API ) - pthread_exit( executing->Wait.return_argument ); -} - -User_extensions_Control _POSIX_Threads_User_extensions = { - .Callouts = { -#if defined(RTEMS_POSIX_API) - .thread_create = _POSIX_Threads_Create_extension, - .thread_terminate = _POSIX_Threads_Terminate_extension, -#endif - .thread_exitted = _POSIX_Threads_Exitted_extension - } -}; - -/* - * _POSIX_Threads_Manager_initialization - * - * This routine initializes all threads manager related data structures. - */ -static void _POSIX_Threads_Manager_initialization(void) -{ - _Thread_Initialize_information( - &_POSIX_Threads_Information, /* object information table */ - OBJECTS_POSIX_API, /* object API */ - OBJECTS_POSIX_THREADS, /* object class */ - _Configuration_POSIX_Maximum_threads - ); - - /* - * Add all the extensions for this API - */ - _User_extensions_Add_API_set( &_POSIX_Threads_User_extensions ); - - /* - * If we supported MP, then here we would ... - * Register the MP Process Packet routine. - */ -} - -RTEMS_SYSINIT_ITEM( - _POSIX_Threads_Manager_initialization, - RTEMS_SYSINIT_POSIX_THREADS, - RTEMS_SYSINIT_ORDER_MIDDLE +THREAD_INFORMATION_DEFINE_ZERO( + _POSIX_Threads, + OBJECTS_POSIX_API, + OBJECTS_POSIX_THREADS ); diff --git a/cpukit/posix/src/pthreadcreate.c b/cpukit/posix/src/pthreadcreate.c index 39a241350f..b70be00217 100644 --- a/cpukit/posix/src/pthreadcreate.c +++ b/cpukit/posix/src/pthreadcreate.c @@ -26,6 +26,9 @@ #include <errno.h> #include <rtems/posix/priorityimpl.h> +#if defined(RTEMS_POSIX_API) +#include <rtems/posix/psignalimpl.h> +#endif #include <rtems/posix/pthreadimpl.h> #include <rtems/posix/pthreadattrimpl.h> #include <rtems/score/assert.h> @@ -33,6 +36,8 @@ #include <rtems/score/apimutex.h> #include <rtems/score/stackimpl.h> #include <rtems/score/schedulerimpl.h> +#include <rtems/score/userextimpl.h> +#include <rtems/sysinit.h> static inline size_t _POSIX_Threads_Ensure_minimum_stack ( size_t size @@ -299,3 +304,136 @@ int pthread_create( _Objects_Allocator_unlock(); return 0; } + +#if defined(RTEMS_POSIX_API) +void _POSIX_Threads_Sporadic_timer( Watchdog_Control *watchdog ) +{ + POSIX_API_Control *api; + Thread_Control *the_thread; + Thread_queue_Context queue_context; + + api = RTEMS_CONTAINER_OF( watchdog, POSIX_API_Control, Sporadic.Timer ); + the_thread = api->Sporadic.thread; + + _Thread_queue_Context_initialize( &queue_context ); + _Thread_queue_Context_clear_priority_updates( &queue_context ); + _Thread_Wait_acquire( the_thread, &queue_context ); + + if ( _Priority_Node_is_active( &api->Sporadic.Low_priority ) ) { + _Thread_Priority_add( + the_thread, + &the_thread->Real_priority, + &queue_context + ); + _Thread_Priority_remove( + the_thread, + &api->Sporadic.Low_priority, + &queue_context + ); + _Priority_Node_set_inactive( &api->Sporadic.Low_priority ); + } + + _Watchdog_Per_CPU_remove_ticks( &api->Sporadic.Timer ); + _POSIX_Threads_Sporadic_timer_insert( the_thread, api ); + + _Thread_Wait_release( the_thread, &queue_context ); + _Thread_Priority_update( &queue_context ); +} + +void _POSIX_Threads_Sporadic_budget_callout( Thread_Control *the_thread ) +{ + POSIX_API_Control *api; + Thread_queue_Context queue_context; + + api = the_thread->API_Extensions[ THREAD_API_POSIX ]; + + _Thread_queue_Context_initialize( &queue_context ); + _Thread_queue_Context_clear_priority_updates( &queue_context ); + _Thread_Wait_acquire( the_thread, &queue_context ); + + /* + * This will prevent the thread from consuming its entire "budget" + * while at low priority. + */ + the_thread->cpu_time_budget = UINT32_MAX; + + if ( !_Priority_Node_is_active( &api->Sporadic.Low_priority ) ) { + _Thread_Priority_add( + the_thread, + &api->Sporadic.Low_priority, + &queue_context + ); + _Thread_Priority_remove( + the_thread, + &the_thread->Real_priority, + &queue_context + ); + } + + _Thread_Wait_release( the_thread, &queue_context ); + _Thread_Priority_update( &queue_context ); +} + +static bool _POSIX_Threads_Create_extension( + Thread_Control *executing RTEMS_UNUSED, + Thread_Control *created +) +{ + POSIX_API_Control *api; + + api = created->API_Extensions[ THREAD_API_POSIX ]; + + api->Sporadic.thread = created; + _Watchdog_Preinitialize( &api->Sporadic.Timer, _Per_CPU_Get_by_index( 0 ) ); + _Watchdog_Initialize( &api->Sporadic.Timer, _POSIX_Threads_Sporadic_timer ); + _Priority_Node_set_inactive( &api->Sporadic.Low_priority ); + + return true; +} + +static void _POSIX_Threads_Terminate_extension( Thread_Control *executing ) +{ + POSIX_API_Control *api; + ISR_lock_Context lock_context; + + api = executing->API_Extensions[ THREAD_API_POSIX ]; + + _Thread_State_acquire( executing, &lock_context ); + _Watchdog_Per_CPU_remove_ticks( &api->Sporadic.Timer ); + _Thread_State_release( executing, &lock_context ); +} +#endif + +static void _POSIX_Threads_Exitted_extension( + Thread_Control *executing +) +{ + /* + * If the executing thread was not created with the POSIX API, then this + * API do not get to define its exit behavior. + */ + if ( _Objects_Get_API( executing->Object.id ) == OBJECTS_POSIX_API ) + pthread_exit( executing->Wait.return_argument ); +} + +static User_extensions_Control _POSIX_Threads_User_extensions = { + .Callouts = { +#if defined(RTEMS_POSIX_API) + .thread_create = _POSIX_Threads_Create_extension, + .thread_terminate = _POSIX_Threads_Terminate_extension, +#endif + .thread_exitted = _POSIX_Threads_Exitted_extension + } +}; + +static void _POSIX_Threads_Manager_initialization( void ) +{ + _Thread_Initialize_information( &_POSIX_Threads_Information ); + _User_extensions_Add_API_set( &_POSIX_Threads_User_extensions ); +} + +RTEMS_SYSINIT_ITEM( + _POSIX_Threads_Manager_initialization, + RTEMS_SYSINIT_POSIX_THREADS, + RTEMS_SYSINIT_ORDER_MIDDLE +); diff --git a/cpukit/posix/src/ptimer.c b/cpukit/posix/src/ptimer.c index f3af1710b8..311bc0b909 100644 --- a/cpukit/posix/src/ptimer.c +++ b/cpukit/posix/src/ptimer.c @@ -1,77 +1,47 @@ /** * @file * - * @brief Process Timer - * @ingroup POSIXAPI + * @ingroup POSIX_INTERNAL_TIMERS + * + * @brief POSIX Timer Information with Zero Objects */ /* - * COPYRIGHT (c) 1989-2008. - * On-Line Applications Research Corporation (OAR). + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (C) 2018 embedded brains GmbH * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. */ #if HAVE_CONFIG_H #include "config.h" #endif -#include <time.h> -#include <errno.h> -#include <limits.h> /* _POSIX_PATH_MAX */ - -#include <rtems/system.h> -#include <rtems/config.h> -#include <rtems/score/isr.h> -#include <rtems/score/thread.h> - - -/************************************/ -/* These includes are now necessary */ -/************************************/ - -#include <unistd.h> -#include <rtems/sysinit.h> -#include <rtems/rtems/status.h> -#include <rtems/rtems/types.h> -#include <rtems/rtems/timer.h> -#include <rtems/rtems/clock.h> -#include <rtems/score/wkspace.h> -#include <pthread.h> -#include <stdio.h> -#include <signal.h> - -#include <rtems/posix/timerimpl.h> - -Objects_Information _POSIX_Timer_Information; - -/* - * _POSIX_Timer_Manager_initialization - * - * Description: - * - * Initialize the internal structure in which the data of all - * the timers are stored - */ - -static void _POSIX_Timer_Manager_initialization(void) -{ - _Objects_Initialize_information( - &_POSIX_Timer_Information, /* object information table */ - OBJECTS_POSIX_API, /* object API */ - OBJECTS_POSIX_TIMERS, /* object class */ - _Configuration_POSIX_Maximum_timers, - sizeof( POSIX_Timer_Control ), - /* size of this object's control block */ - OBJECTS_NO_STRING_NAME, /* maximum length of an object name */ - NULL /* Proxy extraction support callout */ - ); -} +#include <rtems/posix/timer.h> -RTEMS_SYSINIT_ITEM( - _POSIX_Timer_Manager_initialization, - RTEMS_SYSINIT_POSIX_TIMER, - RTEMS_SYSINIT_ORDER_MIDDLE +OBJECTS_INFORMATION_DEFINE_ZERO( + _POSIX_Timer, + OBJECTS_POSIX_API, + OBJECTS_POSIX_TIMERS, + OBJECTS_NO_STRING_NAME ); diff --git a/cpukit/posix/src/semopen.c b/cpukit/posix/src/semopen.c index 63915fca57..86bd6a615e 100644 --- a/cpukit/posix/src/semopen.c +++ b/cpukit/posix/src/semopen.c @@ -20,6 +20,7 @@ #include <rtems/posix/semaphoreimpl.h> #include <rtems/score/wkspace.h> +#include <rtems/sysinit.h> #include <stdarg.h> #include <fcntl.h> @@ -172,3 +173,14 @@ sem_t *sem_open( _Objects_Allocator_unlock(); return sem; } + +static void _POSIX_Semaphore_Manager_initialization( void ) +{ + _Objects_Initialize_information( &_POSIX_Semaphore_Information ); +} + +RTEMS_SYSINIT_ITEM( + _POSIX_Semaphore_Manager_initialization, + RTEMS_SYSINIT_POSIX_SEMAPHORE, + RTEMS_SYSINIT_ORDER_MIDDLE +); diff --git a/cpukit/posix/src/shm.c b/cpukit/posix/src/shm.c index 5030a9376e..8ab14f4e0f 100644 --- a/cpukit/posix/src/shm.c +++ b/cpukit/posix/src/shm.c @@ -1,47 +1,49 @@ /** * @file + * + * @ingroup POSIXShmPrivate + * + * @brief POSIX Shared Memory Information with Zero Objects */ /* - * Copyright (c) 2016 Gedare Bloom. + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (C) 2018 embedded brains GmbH + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.org/license/LICENSE. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. */ #if HAVE_CONFIG_H #include "config.h" #endif -#include <sys/stat.h> -#include <fcntl.h> -#include <limits.h> - -#include <rtems/system.h> -#include <rtems/config.h> -#include <rtems/libio.h> -#include <rtems/sysinit.h> -#include <rtems/posix/shmimpl.h> +#include <rtems/posix/shm.h> -Objects_Information _POSIX_Shm_Information; - -static void _POSIX_Shm_Manager_initialization( void ) -{ - _Objects_Initialize_information( - &_POSIX_Shm_Information, /* object information table */ - OBJECTS_POSIX_API, /* object API */ - OBJECTS_POSIX_SHMS, /* object class */ - _Configuration_POSIX_Maximum_shms, - sizeof( POSIX_Shm_Control ), - /* size of this object's control block */ - _POSIX_PATH_MAX, /* maximum length of each object's name */ - NULL /* Proxy extraction support callout */ - ); -} +#include <limits.h> -RTEMS_SYSINIT_ITEM( - _POSIX_Shm_Manager_initialization, - RTEMS_SYSINIT_POSIX_SHM, - RTEMS_SYSINIT_ORDER_MIDDLE +OBJECTS_INFORMATION_DEFINE_ZERO( + _POSIX_Shm, + OBJECTS_POSIX_API, + OBJECTS_POSIX_SHMS, + _POSIX_PATH_MAX ); diff --git a/cpukit/posix/src/shmopen.c b/cpukit/posix/src/shmopen.c index 8913e19c15..ca8da00140 100644 --- a/cpukit/posix/src/shmopen.c +++ b/cpukit/posix/src/shmopen.c @@ -25,6 +25,7 @@ #include <rtems/posix/shmimpl.h> #include <rtems/score/wkspace.h> +#include <rtems/sysinit.h> static const rtems_filesystem_file_handlers_r shm_handlers; @@ -314,3 +315,14 @@ static const rtems_filesystem_file_handlers_r shm_handlers = { .readv_h = rtems_filesystem_default_readv, .writev_h = rtems_filesystem_default_writev }; + +static void _POSIX_Shm_Manager_initialization( void ) +{ + _Objects_Initialize_information( &_POSIX_Shm_Information ); +} + +RTEMS_SYSINIT_ITEM( + _POSIX_Shm_Manager_initialization, + RTEMS_SYSINIT_POSIX_SHM, + RTEMS_SYSINIT_ORDER_MIDDLE +); |