forked from Imagelibrary/rtems
posix: Use interal mutex for once implementation
Enable pthread_once() for all configurations. The pthread_once() function is one means to initialize POSIX keys. Another use case is the C++ support.
This commit is contained in:
@@ -36,7 +36,6 @@ include_rtems_posix_HEADERS += include/rtems/posix/mqueue.h
|
|||||||
include_rtems_posix_HEADERS += include/rtems/posix/mqueueimpl.h
|
include_rtems_posix_HEADERS += include/rtems/posix/mqueueimpl.h
|
||||||
include_rtems_posix_HEADERS += include/rtems/posix/mutex.h
|
include_rtems_posix_HEADERS += include/rtems/posix/mutex.h
|
||||||
include_rtems_posix_HEADERS += include/rtems/posix/muteximpl.h
|
include_rtems_posix_HEADERS += include/rtems/posix/muteximpl.h
|
||||||
include_rtems_posix_HEADERS += include/rtems/posix/onceimpl.h
|
|
||||||
include_rtems_posix_HEADERS += include/rtems/posix/priorityimpl.h
|
include_rtems_posix_HEADERS += include/rtems/posix/priorityimpl.h
|
||||||
include_rtems_posix_HEADERS += include/rtems/posix/psignal.h
|
include_rtems_posix_HEADERS += include/rtems/posix/psignal.h
|
||||||
include_rtems_posix_HEADERS += include/rtems/posix/psignalimpl.h
|
include_rtems_posix_HEADERS += include/rtems/posix/psignalimpl.h
|
||||||
@@ -113,9 +112,6 @@ libposix_a_SOURCES += src/mutexattrdestroy.c src/mutexattrgetprioceiling.c \
|
|||||||
src/mutexlocksupp.c src/mutexsetprioceiling.c src/mutextimedlock.c \
|
src/mutexlocksupp.c src/mutexsetprioceiling.c src/mutextimedlock.c \
|
||||||
src/mutextranslatereturncode.c src/mutextrylock.c src/mutexunlock.c
|
src/mutextranslatereturncode.c src/mutextrylock.c src/mutexunlock.c
|
||||||
|
|
||||||
## ONCE_C_FILES
|
|
||||||
libposix_a_SOURCES += src/once.c src/pthreadonce.c
|
|
||||||
|
|
||||||
## PTHREAD_C_FILES
|
## PTHREAD_C_FILES
|
||||||
libposix_a_SOURCES += src/pthreadatfork.c src/pthreadattrdestroy.c \
|
libposix_a_SOURCES += src/pthreadatfork.c src/pthreadattrdestroy.c \
|
||||||
src/pthreadattrgetdetachstate.c src/pthreadattrgetinheritsched.c \
|
src/pthreadattrgetdetachstate.c src/pthreadattrgetinheritsched.c \
|
||||||
@@ -160,6 +156,9 @@ libposix_a_SOURCES += src/key.c src/keycreate.c src/keydelete.c \
|
|||||||
src/keygetspecific.c src/keyfreememory.c src/keyrundestructors.c \
|
src/keygetspecific.c src/keyfreememory.c src/keyrundestructors.c \
|
||||||
src/keysetspecific.c
|
src/keysetspecific.c
|
||||||
|
|
||||||
|
## ONCE_C_FILES
|
||||||
|
libposix_a_SOURCES += src/pthreadonce.c
|
||||||
|
|
||||||
libposix_a_SOURCES += src/sigaddset.c src/sigdelset.c src/sigfillset.c \
|
libposix_a_SOURCES += src/sigaddset.c src/sigdelset.c src/sigfillset.c \
|
||||||
src/sigemptyset.c src/sigismember.c
|
src/sigemptyset.c src/sigismember.c
|
||||||
|
|
||||||
|
|||||||
@@ -1,57 +0,0 @@
|
|||||||
/**
|
|
||||||
* @file
|
|
||||||
*
|
|
||||||
* @brief Private Inlined Routines for POSIX Once
|
|
||||||
*
|
|
||||||
* This include file contains the static inline implementation of the private
|
|
||||||
* inlined routines for POSIX once.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* COPYRIGHT (c) 1989-1999.
|
|
||||||
* On-Line Applications Research Corporation (OAR).
|
|
||||||
*
|
|
||||||
* COPYRIGHT (c) 2013.
|
|
||||||
* Chris Johns <chrisj@rtems.org>
|
|
||||||
*
|
|
||||||
* The license and distribution terms for this file may be
|
|
||||||
* found in the file LICENSE in this distribution or at
|
|
||||||
* http://www.rtems.com/license/LICENSE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <rtems/score/objectimpl.h>
|
|
||||||
#include <rtems/score/percpu.h>
|
|
||||||
|
|
||||||
#ifndef _RTEMS_POSIX_ONCEIMPL_H
|
|
||||||
#define _RTEMS_POSIX_ONCEIMPL_H
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @addtogroup POSIX_ONCE
|
|
||||||
*
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Lock to allow once mutex's to be initialized.
|
|
||||||
*/
|
|
||||||
POSIX_EXTERN pthread_mutex_t _POSIX_Once_Lock;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief POSIX once manager initialization.
|
|
||||||
*
|
|
||||||
* This routine performs the initialization necessary for this manager.
|
|
||||||
*/
|
|
||||||
void _POSIX_Once_Manager_initialization(void);
|
|
||||||
|
|
||||||
/** @} */
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
/* end of include file */
|
|
||||||
@@ -88,10 +88,6 @@ $(PROJECT_INCLUDE)/rtems/posix/muteximpl.h: include/rtems/posix/muteximpl.h $(PR
|
|||||||
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/muteximpl.h
|
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/muteximpl.h
|
||||||
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/muteximpl.h
|
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/muteximpl.h
|
||||||
|
|
||||||
$(PROJECT_INCLUDE)/rtems/posix/onceimpl.h: include/rtems/posix/onceimpl.h $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp)
|
|
||||||
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/onceimpl.h
|
|
||||||
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/onceimpl.h
|
|
||||||
|
|
||||||
$(PROJECT_INCLUDE)/rtems/posix/priorityimpl.h: include/rtems/posix/priorityimpl.h $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp)
|
$(PROJECT_INCLUDE)/rtems/posix/priorityimpl.h: include/rtems/posix/priorityimpl.h $(PROJECT_INCLUDE)/rtems/posix/$(dirstamp)
|
||||||
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/priorityimpl.h
|
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/posix/priorityimpl.h
|
||||||
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/priorityimpl.h
|
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/posix/priorityimpl.h
|
||||||
|
|||||||
@@ -1,46 +0,0 @@
|
|||||||
/**
|
|
||||||
* @file
|
|
||||||
*
|
|
||||||
* @brief POSIX Once Manager Initialization
|
|
||||||
* @ingroup POSIX_ONCE POSIX Once Support
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* COPYRIGHT (c) 2013
|
|
||||||
* Chris Johns <chrisj@rtems.org>
|
|
||||||
*
|
|
||||||
* The license and distribution terms for this file may be
|
|
||||||
* found in the file LICENSE in this distribution or at
|
|
||||||
* http://www.rtems.com/license/LICENSE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if HAVE_CONFIG_H
|
|
||||||
#include "config.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <pthread.h>
|
|
||||||
#include <errno.h>
|
|
||||||
|
|
||||||
#include <rtems.h>
|
|
||||||
#include <rtems/posix/posixapi.h>
|
|
||||||
#include <rtems/posix/onceimpl.h>
|
|
||||||
|
|
||||||
void _POSIX_Once_Manager_initialization(void)
|
|
||||||
{
|
|
||||||
pthread_mutexattr_t mattr;
|
|
||||||
int eno;
|
|
||||||
|
|
||||||
_POSIX_Once_Lock = PTHREAD_MUTEX_INITIALIZER;
|
|
||||||
|
|
||||||
eno = pthread_mutexattr_init( &mattr );
|
|
||||||
_Assert( eno == 0 );
|
|
||||||
eno = pthread_mutexattr_settype( &mattr, PTHREAD_MUTEX_RECURSIVE );
|
|
||||||
_Assert( eno == 0 );
|
|
||||||
|
|
||||||
eno = pthread_mutex_init( &_POSIX_Once_Lock, &mattr );
|
|
||||||
if ( eno != 0 )
|
|
||||||
_POSIX_Fatal_error( POSIX_FD_PTHREAD_ONCE, eno );
|
|
||||||
|
|
||||||
eno = pthread_mutexattr_destroy( &mattr );
|
|
||||||
_Assert( eno == 0 );
|
|
||||||
}
|
|
||||||
@@ -23,9 +23,7 @@
|
|||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#include <rtems.h>
|
#include <rtems/score/apimutex.h>
|
||||||
#include <rtems/system.h>
|
|
||||||
#include <rtems/posix/onceimpl.h>
|
|
||||||
|
|
||||||
#define PTHREAD_ONCE_INIT_NOT_RUN 0
|
#define PTHREAD_ONCE_INIT_NOT_RUN 0
|
||||||
#define PTHREAD_ONCE_INIT_RUNNING 1
|
#define PTHREAD_ONCE_INIT_RUNNING 1
|
||||||
@@ -45,9 +43,7 @@ int pthread_once(
|
|||||||
return EINVAL;
|
return EINVAL;
|
||||||
|
|
||||||
if ( once_control->init_executed != PTHREAD_ONCE_INIT_COMPLETE ) {
|
if ( once_control->init_executed != PTHREAD_ONCE_INIT_COMPLETE ) {
|
||||||
r = pthread_mutex_lock( &_POSIX_Once_Lock );
|
_Once_Lock();
|
||||||
if ( r == 0 ) {
|
|
||||||
int rr;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Getting to here means the once_control is locked so we have:
|
* Getting to here means the once_control is locked so we have:
|
||||||
@@ -69,10 +65,8 @@ int pthread_once(
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
rr = pthread_mutex_unlock( &_POSIX_Once_Lock );
|
|
||||||
if ( r == 0 )
|
_Once_Unlock();
|
||||||
r = rr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
|
|||||||
@@ -1765,11 +1765,6 @@ const rtems_libio_helper rtems_fs_init_helper =
|
|||||||
#include <rtems/posix/threadsup.h>
|
#include <rtems/posix/threadsup.h>
|
||||||
#include <rtems/posix/timer.h>
|
#include <rtems/posix/timer.h>
|
||||||
|
|
||||||
/**
|
|
||||||
* POSIX Once support uses a single mutex.
|
|
||||||
*/
|
|
||||||
#define CONFIGURE_MAXIMUM_POSIX_INTERNAL_MUTEXES 1
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Account for the object control structures plus the name
|
* Account for the object control structures plus the name
|
||||||
* of the object to be duplicated.
|
* of the object to be duplicated.
|
||||||
@@ -1899,7 +1894,6 @@ const rtems_libio_helper rtems_fs_init_helper =
|
|||||||
|
|
||||||
#define CONFIGURE_MEMORY_FOR_POSIX \
|
#define CONFIGURE_MEMORY_FOR_POSIX \
|
||||||
( CONFIGURE_MEMORY_FOR_POSIX_MUTEXES( CONFIGURE_MAXIMUM_POSIX_MUTEXES + \
|
( CONFIGURE_MEMORY_FOR_POSIX_MUTEXES( CONFIGURE_MAXIMUM_POSIX_MUTEXES + \
|
||||||
CONFIGURE_MAXIMUM_POSIX_INTERNAL_MUTEXES + \
|
|
||||||
CONFIGURE_MAXIMUM_GO_CHANNELS + CONFIGURE_GO_INIT_MUTEXES) + \
|
CONFIGURE_MAXIMUM_GO_CHANNELS + CONFIGURE_GO_INIT_MUTEXES) + \
|
||||||
CONFIGURE_MEMORY_FOR_POSIX_CONDITION_VARIABLES( \
|
CONFIGURE_MEMORY_FOR_POSIX_CONDITION_VARIABLES( \
|
||||||
CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES + \
|
CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES + \
|
||||||
@@ -2130,11 +2124,11 @@ const rtems_libio_helper rtems_fs_init_helper =
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RTEMS uses one instance of an internal mutex class. This accounts
|
* RTEMS uses two instance of an internal mutex class. This accounts
|
||||||
* for that mutex
|
* for these mutexes.
|
||||||
*/
|
*/
|
||||||
#define CONFIGURE_API_MUTEX_MEMORY \
|
#define CONFIGURE_API_MUTEX_MEMORY \
|
||||||
_Configure_Object_RAM(1, sizeof(API_Mutex_Control))
|
_Configure_Object_RAM(2, sizeof(API_Mutex_Control))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This calculates the amount of memory reserved for the IDLE tasks.
|
* This calculates the amount of memory reserved for the IDLE tasks.
|
||||||
@@ -2349,7 +2343,6 @@ const rtems_libio_helper rtems_fs_init_helper =
|
|||||||
CONFIGURE_MAXIMUM_POSIX_THREADS + CONFIGURE_MAXIMUM_ADA_TASKS +
|
CONFIGURE_MAXIMUM_POSIX_THREADS + CONFIGURE_MAXIMUM_ADA_TASKS +
|
||||||
CONFIGURE_MAXIMUM_GOROUTINES,
|
CONFIGURE_MAXIMUM_GOROUTINES,
|
||||||
CONFIGURE_MAXIMUM_POSIX_MUTEXES + CONFIGURE_GNAT_MUTEXES +
|
CONFIGURE_MAXIMUM_POSIX_MUTEXES + CONFIGURE_GNAT_MUTEXES +
|
||||||
CONFIGURE_MAXIMUM_POSIX_INTERNAL_MUTEXES +
|
|
||||||
CONFIGURE_MAXIMUM_ADA_TASKS + CONFIGURE_MAXIMUM_FAKE_ADA_TASKS +
|
CONFIGURE_MAXIMUM_ADA_TASKS + CONFIGURE_MAXIMUM_FAKE_ADA_TASKS +
|
||||||
CONFIGURE_GO_INIT_MUTEXES + CONFIGURE_MAXIMUM_GO_CHANNELS,
|
CONFIGURE_GO_INIT_MUTEXES + CONFIGURE_MAXIMUM_GO_CHANNELS,
|
||||||
CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES +
|
CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES +
|
||||||
@@ -2599,7 +2592,6 @@ const rtems_libio_helper rtems_fs_init_helper =
|
|||||||
#ifdef RTEMS_POSIX_API
|
#ifdef RTEMS_POSIX_API
|
||||||
/* POSIX API Pieces */
|
/* POSIX API Pieces */
|
||||||
CONFIGURE_MEMORY_FOR_POSIX_MUTEXES( CONFIGURE_MAXIMUM_POSIX_MUTEXES +
|
CONFIGURE_MEMORY_FOR_POSIX_MUTEXES( CONFIGURE_MAXIMUM_POSIX_MUTEXES +
|
||||||
CONFIGURE_MAXIMUM_POSIX_INTERNAL_MUTEXES +
|
|
||||||
CONFIGURE_MAXIMUM_GO_CHANNELS + CONFIGURE_GO_INIT_MUTEXES),
|
CONFIGURE_MAXIMUM_GO_CHANNELS + CONFIGURE_GO_INIT_MUTEXES),
|
||||||
CONFIGURE_MEMORY_FOR_POSIX_CONDITION_VARIABLES(
|
CONFIGURE_MEMORY_FOR_POSIX_CONDITION_VARIABLES(
|
||||||
CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES +
|
CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES +
|
||||||
|
|||||||
@@ -116,8 +116,9 @@ void rtems_initialize_data_structures(void)
|
|||||||
*/
|
*/
|
||||||
_Objects_Information_table[OBJECTS_INTERNAL_API] = _Internal_Objects;
|
_Objects_Information_table[OBJECTS_INTERNAL_API] = _Internal_Objects;
|
||||||
|
|
||||||
_API_Mutex_Initialization( 1 );
|
_API_Mutex_Initialization( 2 );
|
||||||
_API_Mutex_Allocate( &_RTEMS_Allocator_Mutex );
|
_API_Mutex_Allocate( &_RTEMS_Allocator_Mutex );
|
||||||
|
_API_Mutex_Allocate( &_Once_Mutex );
|
||||||
|
|
||||||
_Watchdog_Handler_initialization();
|
_Watchdog_Handler_initialization();
|
||||||
_TOD_Handler_initialization();
|
_TOD_Handler_initialization();
|
||||||
|
|||||||
@@ -36,7 +36,6 @@
|
|||||||
#include <rtems/posix/condimpl.h>
|
#include <rtems/posix/condimpl.h>
|
||||||
#include <rtems/posix/mqueueimpl.h>
|
#include <rtems/posix/mqueueimpl.h>
|
||||||
#include <rtems/posix/muteximpl.h>
|
#include <rtems/posix/muteximpl.h>
|
||||||
#include <rtems/posix/onceimpl.h>
|
|
||||||
#include <rtems/posix/priorityimpl.h>
|
#include <rtems/posix/priorityimpl.h>
|
||||||
#include <rtems/posix/psignalimpl.h>
|
#include <rtems/posix/psignalimpl.h>
|
||||||
#include <rtems/posix/pthreadimpl.h>
|
#include <rtems/posix/pthreadimpl.h>
|
||||||
@@ -79,7 +78,6 @@ void _POSIX_API_Initialize(void)
|
|||||||
_POSIX_Condition_variables_Manager_initialization();
|
_POSIX_Condition_variables_Manager_initialization();
|
||||||
_POSIX_Mutex_Manager_initialization();
|
_POSIX_Mutex_Manager_initialization();
|
||||||
_POSIX_Message_queue_Manager_initialization();
|
_POSIX_Message_queue_Manager_initialization();
|
||||||
_POSIX_Once_Manager_initialization();
|
|
||||||
_POSIX_Semaphore_Manager_initialization();
|
_POSIX_Semaphore_Manager_initialization();
|
||||||
_POSIX_Timer_Manager_initialization();
|
_POSIX_Timer_Manager_initialization();
|
||||||
_POSIX_Barrier_Manager_initialization();
|
_POSIX_Barrier_Manager_initialization();
|
||||||
|
|||||||
@@ -120,6 +120,18 @@ SCORE_EXTERN API_Mutex_Control *_RTEMS_Allocator_Mutex;
|
|||||||
#define _RTEMS_Unlock_allocator() \
|
#define _RTEMS_Unlock_allocator() \
|
||||||
_API_Mutex_Unlock( _RTEMS_Allocator_Mutex )
|
_API_Mutex_Unlock( _RTEMS_Allocator_Mutex )
|
||||||
|
|
||||||
|
SCORE_EXTERN API_Mutex_Control *_Once_Mutex;
|
||||||
|
|
||||||
|
static inline void _Once_Lock( void )
|
||||||
|
{
|
||||||
|
_API_Mutex_Lock( _Once_Mutex );
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void _Once_Unlock( void )
|
||||||
|
{
|
||||||
|
_API_Mutex_Unlock( _Once_Mutex );
|
||||||
|
}
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|||||||
@@ -482,8 +482,7 @@ static rtems_task Init(rtems_task_argument argument)
|
|||||||
}
|
}
|
||||||
rtems_resource_snapshot_take(&snapshot);
|
rtems_resource_snapshot_take(&snapshot);
|
||||||
rtems_test_assert(
|
rtems_test_assert(
|
||||||
snapshot.posix_api.active_mutexes ==
|
snapshot.posix_api.active_mutexes == CONFIGURE_MAXIMUM_POSIX_MUTEXES
|
||||||
(CONFIGURE_MAXIMUM_POSIX_MUTEXES + CONFIGURE_MAXIMUM_POSIX_INTERNAL_MUTEXES)
|
|
||||||
);
|
);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user