Changeset 606ed52 in rtems


Ignore:
Timestamp:
May 23, 2014, 3:09:22 PM (5 years ago)
Author:
Ralf Kirchner <ralf.kirchner@…>
Branches:
4.11, master
Children:
7c90670
Parents:
25f5730f
git-author:
Ralf Kirchner <ralf.kirchner@…> (05/23/14 15:09:22)
git-committer:
Sebastian Huber <sebastian.huber@…> (06/02/14 11:48:41)
Message:

libblock: Use pthread_once() for initialization

Enabling and disabling preemption as done for single core will not work
for SMP. In the bdbuf initialization preemption handling can be avoided
in general by using pthread_once().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libblock/src/bdbuf.c

    r25f5730f r606ed52  
    3636#include <string.h>
    3737#include <inttypes.h>
     38#include <pthread.h>
    3839
    3940#include <rtems.h>
     
    138139  rtems_chain_control read_ahead_chain;  /**< Read-ahead request chain */
    139140  bool                read_ahead_enabled; /**< Read-ahead enabled */
    140 
    141   bool                initialised;       /**< Initialised state. */
     141  rtems_status_code   init_status;       /**< The initialization status */
    142142} rtems_bdbuf_cache;
    143143
     
    169169  RTEMS_BDBUF_FATAL_TREE_RM,
    170170  RTEMS_BDBUF_FATAL_WAIT_EVNT,
    171   RTEMS_BDBUF_FATAL_WAIT_TRANS_EVNT
     171  RTEMS_BDBUF_FATAL_WAIT_TRANS_EVNT,
     172  RTEMS_BDBUF_FATAL_ONCE
    172173} rtems_bdbuf_fatal_code;
    173174
     
    218219 */
    219220static rtems_bdbuf_cache bdbuf_cache;
     221
     222static pthread_once_t rtems_bdbuf_once_state = PTHREAD_ONCE_INIT;
    220223
    221224#if RTEMS_BDBUF_TRACE
     
    13861389}
    13871390
    1388 /**
    1389  * Initialise the cache.
    1390  *
    1391  * @return rtems_status_code The initialisation status.
    1392  */
    1393 rtems_status_code
    1394 rtems_bdbuf_init (void)
     1391static rtems_status_code
     1392rtems_bdbuf_do_init (void)
    13951393{
    13961394  rtems_bdbuf_group*  group;
     
    14001398  size_t              cache_aligment;
    14011399  rtems_status_code   sc;
    1402   rtems_mode          prev_mode;
    14031400
    14041401  if (rtems_bdbuf_tracer)
     
    14181415      > RTEMS_MINIMUM_STACK_SIZE / 8U)
    14191416    return RTEMS_INVALID_NUMBER;
    1420 
    1421   /*
    1422    * We use a special variable to manage the initialisation incase we have
    1423    * completing threads doing this. You may get errors if the another thread
    1424    * makes a call and we have not finished initialisation.
    1425    */
    1426   prev_mode = rtems_bdbuf_disable_preemption ();
    1427   if (bdbuf_cache.initialised)
    1428   {
    1429     rtems_bdbuf_restore_preemption (prev_mode);
    1430     return RTEMS_RESOURCE_IN_USE;
    1431   }
    1432 
    1433   memset(&bdbuf_cache, 0, sizeof(bdbuf_cache));
    1434   bdbuf_cache.initialised = true;
    1435   rtems_bdbuf_restore_preemption (prev_mode);
    14361417
    14371418  /*
     
    16511632  }
    16521633
    1653   bdbuf_cache.initialised = false;
    1654 
    16551634  return RTEMS_UNSATISFIED;
     1635}
     1636
     1637static void
     1638rtems_bdbuf_init_once (void)
     1639{
     1640  bdbuf_cache.init_status = rtems_bdbuf_do_init();
     1641}
     1642
     1643rtems_status_code
     1644rtems_bdbuf_init (void)
     1645{
     1646  int eno = pthread_once (&rtems_bdbuf_once_state, rtems_bdbuf_init_once);
     1647
     1648  if (eno != 0)
     1649    rtems_bdbuf_fatal (RTEMS_BDBUF_FATAL_ONCE);
     1650
     1651  return bdbuf_cache.init_status;
    16561652}
    16571653
Note: See TracChangeset for help on using the changeset viewer.