Changeset 16fc3f9a in rtems


Ignore:
Timestamp:
Dec 12, 2017, 5:27:14 AM (2 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
b17bcb3
Parents:
36304f3
git-author:
Sebastian Huber <sebastian.huber@…> (12/12/17 05:27:14)
git-committer:
Sebastian Huber <sebastian.huber@…> (02/02/18 14:01:22)
Message:

network: Use self-contained recursive mutex

Update #2843.

Location:
cpukit
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cpukit/include/rtems/confdefs.h

    r36304f3 r16fc3f9a  
    20582058
    20592059  /*
    2060    * This specifies the number of Classic API semaphores required
    2061    */
    2062   #ifdef RTEMS_NETWORKING
    2063     #define _CONFIGURE_NETWORKING_SEMAPHORES 1
    2064   #else
    2065     #define _CONFIGURE_NETWORKING_SEMAPHORES 0
    2066   #endif
    2067 
    2068   /*
    20692060   * This macro is calculated to specify the number of Classic API
    20702061   * semaphores required by the application and configured RTEMS
     
    20732064  #define _CONFIGURE_SEMAPHORES \
    20742065    (CONFIGURE_MAXIMUM_SEMAPHORES + \
    2075       _CONFIGURE_SEMAPHORES_FOR_FILE_SYSTEMS + \
    2076       _CONFIGURE_NETWORKING_SEMAPHORES)
     2066      _CONFIGURE_SEMAPHORES_FOR_FILE_SYSTEMS)
    20772067
    20782068  /*
  • cpukit/libnetworking/rtems/rtems_glue.c

    r36304f3 r16fc3f9a  
    1313#include <rtems/libio.h>
    1414#include <rtems/error.h>
     15#include <rtems/thread.h>
    1516#include <rtems/rtems_bsdnet.h>
    16 #include <rtems/rtems/semimpl.h>
    17 #include <rtems/score/coremuteximpl.h>
    1817#include <sys/types.h>
    1918#include <sys/param.h>
     
    4645 * Network task synchronization
    4746 */
    48 static rtems_id networkSemaphore;
    49 #ifdef RTEMS_FAST_MUTEX
    50 Semaphore_Control   *the_networkSemaphore;
    51 #endif
     47static rtems_recursive_mutex networkMutex =
     48    RTEMS_RECURSIVE_MUTEX_INITIALIZER("_Network");
    5249static rtems_id networkDaemonTid;
    5350static uint32_t   networkDaemonPriority;
     
    112109rtems_bsdnet_semaphore_release_recursive(void)
    113110{
    114 #ifdef RTEMS_FAST_MUTEX
    115111        uint32_t nest_count;
    116         uint32_t i;
    117 
    118         nest_count =
    119                 the_networkSemaphore ?
    120                 the_networkSemaphore->Core_control.Mutex.Recursive.nest_level + 1 : 0;
    121         for (i = 0; i < nest_count; ++i) {
    122                 rtems_bsdnet_semaphore_release();
    123         }
    124 
     112
     113        nest_count = networkMutex._nest_level;
     114        networkMutex._nest_level = 0;
     115        rtems_recursive_mutex_unlock(&networkMutex);
    125116        return nest_count;
    126 #else
    127         #error "not implemented"
    128 #endif
    129117}
    130118
     
    132120rtems_bsdnet_semaphore_obtain_recursive(uint32_t nest_count)
    133121{
    134         uint32_t i;
    135 
    136         for (i = 0; i < nest_count; ++i) {
    137                 rtems_bsdnet_semaphore_obtain();
    138         }
     122        rtems_recursive_mutex_lock(&networkMutex);
     123        networkMutex._nest_level = nest_count;
    139124}
    140125
     
    266251rtems_bsdnet_initialize (void)
    267252{
    268         rtems_status_code sc;
     253        rtems_bsdnet_semaphore_obtain ();
    269254
    270255        /*
     
    314299
    315300        /*
    316          * Create the task-synchronization semaphore
    317          */
    318         sc = rtems_semaphore_create (rtems_build_name('B', 'S', 'D', 'n'),
    319                                         0,
    320                                         RTEMS_PRIORITY |
    321                                                 RTEMS_BINARY_SEMAPHORE |
    322                                                 RTEMS_INHERIT_PRIORITY |
    323                                                 RTEMS_NO_PRIORITY_CEILING |
    324                                                 RTEMS_LOCAL,
    325                                         0,
    326                                         &networkSemaphore);
    327         if (sc != RTEMS_SUCCESSFUL) {
    328                 printf ("Can't create network seamphore: `%s'\n", rtems_status_text (sc));
    329                 return -1;
    330         }
    331 #ifdef RTEMS_FAST_MUTEX
    332         the_networkSemaphore = (Semaphore_Control *)
    333                 _Objects_Get_no_protection(networkSemaphore, &_Semaphore_Information);
    334 #endif
    335 
    336         /*
    337301         * Compute clock tick conversion factors
    338302         */
     
    346310         * Set up BSD-style sockets
    347311         */
    348         if (bsd_init () < 0)
     312        if (bsd_init () < 0) {
     313                rtems_bsdnet_semaphore_release ();
    349314                return -1;
     315        }
    350316
    351317        /*
     
    370336rtems_bsdnet_semaphore_obtain (void)
    371337{
    372 #ifdef RTEMS_FAST_MUTEX
    373         Thread_queue_Context queue_context;
    374         Status_Control status;
    375         if (!the_networkSemaphore)
    376                 rtems_panic ("rtems-net: network sema obtain: network not initialised\n");
    377         _Thread_queue_Context_initialize(&queue_context);
    378         _ISR_lock_ISR_disable(&queue_context.Lock_context.Lock_context);
    379         _Thread_queue_Context_set_enqueue_do_nothing_extra( &queue_context );
    380         status = _CORE_recursive_mutex_Seize (
    381                 &the_networkSemaphore->Core_control.Mutex.Recursive,
    382                 CORE_MUTEX_TQ_PRIORITY_INHERIT_OPERATIONS,
    383                 _Thread_Executing,
    384                 true,                   /* wait */
    385                 _CORE_recursive_mutex_Seize_nested,
    386                 &queue_context
    387         );
    388         if (status != STATUS_SUCCESSFUL)
    389                 rtems_panic ("rtems-net: can't obtain network sema: %d\n", status);
    390 #else
    391         rtems_status_code sc;
    392 
    393         sc = rtems_semaphore_obtain (networkSemaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
    394         if (sc != RTEMS_SUCCESSFUL)
    395                 rtems_panic ("rtems-net: can't obtain network semaphore: `%s'\n",
    396                  rtems_status_text (sc));
    397 #endif
     338        rtems_recursive_mutex_lock(&networkMutex);
    398339}
    399340
     
    404345rtems_bsdnet_semaphore_release (void)
    405346{
    406 #ifdef RTEMS_FAST_MUTEX
    407         Thread_queue_Context queue_context;
    408         Status_Control status;
    409 
    410         if (!the_networkSemaphore)
    411                 rtems_panic ("rtems-net: network sema obtain: network not initialised\n");
    412         _Thread_queue_Context_initialize(&queue_context);
    413         _ISR_lock_ISR_disable(&queue_context.Lock_context.Lock_context);
    414         status = _CORE_recursive_mutex_Surrender(
    415                 &the_networkSemaphore->Core_control.Mutex.Recursive,
    416                 CORE_MUTEX_TQ_PRIORITY_INHERIT_OPERATIONS,
    417                 _Thread_Executing,
    418                 &queue_context
    419         );
    420         if (status != STATUS_SUCCESSFUL)
    421                 rtems_panic ("rtems-net: can't release network sema: %i\n");
    422 #else
    423         rtems_status_code sc;
    424 
    425         sc = rtems_semaphore_release (networkSemaphore);
    426         if (sc != RTEMS_SUCCESSFUL)
    427                 rtems_panic ("rtems-net: can't release network semaphore: `%s'\n",
    428                  rtems_status_text (sc));
    429 #endif
     347        rtems_recursive_mutex_unlock(&networkMutex);
    430348}
    431349
Note: See TracChangeset for help on using the changeset viewer.