Changeset becbeda in rtems


Ignore:
Timestamp:
Jun 9, 2015, 8:48:22 PM (4 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.11, master
Children:
0562060
Parents:
aa2a62c
git-author:
Joel Sherrill <joel.sherrill@…> (06/09/15 20:48:22)
git-committer:
Joel Sherrill <joel.sherrill@…> (06/11/15 15:06:33)
Message:

pc386/console/fb*.c: Use atomics to avoid dependency on pthreads

closes #2364.

Location:
c/src/lib/libbsp/i386/pc386/console
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • c/src/lib/libbsp/i386/pc386/console/fb_cirrus.c

    raa2a62c rbecbeda  
    2828#include <rtems/fb.h>
    2929#include <rtems/framebuffer.h>
    30 
    31 /* mutex to limit driver to protect against multiple opens */
    32 static pthread_mutex_t cirrus_mutex = PTHREAD_MUTEX_INITIALIZER;
     30#include <rtems/score/atomic.h>
     31
     32/* flag to limit driver to protect against multiple opens */
     33static Atomic_Flag driver_mutex;
    3334
    3435/* screen information for the VGA driver
     
    332333          rtems_fatal_error_occurred( status );
    333334      }
     335
     336      _Atomic_Flag_clear(&driver_mutex, ATOMIC_ORDER_RELEASE);
    334337
    335338      return RTEMS_SUCCESSFUL;
     
    592595  uint32_t smem_start, regs_start;
    593596
    594   if (pthread_mutex_trylock(&cirrus_mutex)!= 0){
    595       printk( "FB_CIRRUS could not lock cirrus_mutex\n" );
     597  if (_Atomic_Flag_test_and_set(&driver_mutex, ATOMIC_ORDER_ACQUIRE) != 0 ) {
     598      printk( "FB_CIRRUS could not lock driver_mutex\n" );
    596599
    597600      return RTEMS_UNSATISFIED;
     
    663666)
    664667{
    665   if (pthread_mutex_unlock(&cirrus_mutex) == 0){
    666       /* restore previous state.  for VGA this means return to text mode.
    667        * leave out if graphics hardware has been initialized in
    668        * frame_buffer_initialize() */
    669 
    670       /* VGA text mode */
    671       fb_cirrus_write_gdc_reg(&cirrus_board_info, 0x06, 0x00);
    672 
    673       printk( "FB_CIRRUS: close called.\n" );
    674       return RTEMS_SUCCESSFUL;
    675   }
    676 
    677   return RTEMS_UNSATISFIED;
     668  _Atomic_Flag_clear(&driver_mutex, ATOMIC_ORDER_RELEASE);
     669
     670  /* restore previous state.  for VGA this means return to text mode.
     671   * leave out if graphics hardware has been initialized in
     672   * frame_buffer_initialize() */
     673
     674  /* VGA text mode */
     675  fb_cirrus_write_gdc_reg(&cirrus_board_info, 0x06, 0x00);
     676
     677  printk( "FB_CIRRUS: close called.\n" );
     678  return RTEMS_SUCCESSFUL;
    678679}
    679680
  • c/src/lib/libbsp/i386/pc386/console/fb_vesa_rm.c

    raa2a62c rbecbeda  
    5656#include <rtems/framebuffer.h>
    5757
     58#include <rtems/score/atomic.h>
     59
    5860#include <stdlib.h>
    5961
     
    8587void vesa_realmode_bootup_init(void);
    8688
    87 /* mutex for protection against multiple opens, when called frame_buffer_open */
    88 static pthread_mutex_t vesa_mutex = PTHREAD_MUTEX_INITIALIZER;
     89/* flag to limit driver to protect against multiple opens */
     90static Atomic_Flag driver_mutex;
    8991
    9092/* screen information for the VGA driver
     
    841843    printk(FB_VESA_NAME " frame buffer -- driver initializing..\n" );
    842844
    843 /*
    844  * Register the device.
    845  */
     845   /*
     846    * Register the device.
     847    */
    846848    status = rtems_io_register_name(FRAMEBUFFER_DEVICE_0_NAME, major, 0);
    847849    if (status != RTEMS_SUCCESSFUL)
     
    851853        rtems_fatal_error_occurred( status );
    852854    }
     855
     856    _Atomic_Flag_clear(&driver_mutex, ATOMIC_ORDER_RELEASE);
    853857
    854858    return RTEMS_SUCCESSFUL;
     
    867871    printk( FB_VESA_NAME " open device\n" );
    868872
    869     if (pthread_mutex_trylock(&vesa_mutex) != 0)
     873    if (_Atomic_Flag_test_and_set(&driver_mutex, ATOMIC_ORDER_ACQUIRE) != 0 )
    870874    {
    871875        printk( FB_VESA_NAME " could not lock vesa_mutex\n" );
     
    889893{
    890894  printk( FB_VESA_NAME " close device\n" );
    891   if (pthread_mutex_unlock(&vesa_mutex) == 0)
    892   {
    893       /* restore previous state.  for VGA this means return to text mode.
    894        * leave out if graphics hardware has been initialized in
    895        * frame_buffer_initialize() */
    896 
    897       printk(FB_VESA_NAME ": close called.\n" );
    898       return RTEMS_SUCCESSFUL;
    899   }
    900 
    901   return RTEMS_UNSATISFIED;
     895  _Atomic_Flag_clear(&driver_mutex, ATOMIC_ORDER_RELEASE);
     896  /* restore previous state.  for VGA this means return to text mode.
     897   * leave out if graphics hardware has been initialized in
     898   * frame_buffer_initialize() */
     899
     900  printk(FB_VESA_NAME ": close called.\n" );
     901  return RTEMS_SUCCESSFUL;
    902902}
    903903
  • c/src/lib/libbsp/i386/pc386/console/fb_vga.c

    raa2a62c rbecbeda  
    2121#include <rtems/framebuffer.h>
    2222
     23#include <rtems/score/atomic.h>
     24
    2325/* these routines are defined in vgainit.c.*/
    2426extern void ega_hwinit( void );
    2527extern void ega_hwterm( void );
    2628
    27 /* mutex attribure */
    28 pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
     29/* flag to limit driver to protect against multiple opens */
     30static Atomic_Flag driver_mutex;
    2931
    3032/* screen information for the VGA driver */
     
    8890  }
    8991
     92  _Atomic_Flag_clear(&driver_mutex, ATOMIC_ORDER_RELEASE);
     93
    9094  return RTEMS_SUCCESSFUL;
    9195}
     
    100104)
    101105{
    102   if (pthread_mutex_trylock(&mutex)== 0){
     106  if (_Atomic_Flag_test_and_set(&driver_mutex, ATOMIC_ORDER_ACQUIRE) != 0 ) {
    103107      /* restore previous state.  for VGA this means return to text mode.
    104108       * leave out if graphics hardware has been initialized in
     
    122126)
    123127{
    124   if (pthread_mutex_unlock(&mutex) == 0){
    125     /* restore previous state.  for VGA this means return to text mode.
    126      * leave out if graphics hardware has been initialized in
    127      * frame_buffer_initialize() */
    128     ega_hwterm();
    129     printk( "FBVGA close called.\n" );
    130     return RTEMS_SUCCESSFUL;
    131   }
    132 
    133   return RTEMS_UNSATISFIED;
    134 }
     128  _Atomic_Flag_clear(&driver_mutex, ATOMIC_ORDER_RELEASE);
     129  /* restore previous state.  for VGA this means return to text mode.
     130   * leave out if graphics hardware has been initialized in
     131   * frame_buffer_initialize() */
     132  ega_hwterm();
     133  printk( "FBVGA close called.\n" );
     134  return RTEMS_SUCCESSFUL;
    135135
    136136/*
Note: See TracChangeset for help on using the changeset viewer.