www.pudn.com > efs.rar > fs_hotplug_sd_lock.c


/***********************************************************************
 * fs_hotplug_sd_lock.c
 *
 * Lock mechanism for SD devices
 * Copyright (C) 2006 QUALCOMM, Inc.
 *
 * Since the SD lock is shared between the Hotplug SD driver and CPRM
 * driver, define it here in shared code.
 *
 ***********************************************************************/

/*===========================================================================

                        EDIT HISTORY FOR MODULE

  This section contains comments describing changes made to the module.
  Notice that changes are listed in reverse chronological order.

  $Header: //depot/asic/MSMSHARED/services/efs/MSM_EFS.01.02/fs_hotplug_sd_lock.c#2 $ $DateTime: 2006/11/30 18:48:40 $ $Author: davidb $

when         who   what, where, why
----------   ---   ---------------------------------------------------------
2006-11-30   s h   Include assert.h so ThinUI build works.
2006-11-11   s h   Create

===========================================================================*/
#include "fs_hotplug.h"
#include "fs_hotplug_i.h"
#include "fs_hotplug_sd_lock.h"

#ifdef FS_HOTPLUG_SD_LOCK

#include "assert.h"

/* Critical section allocation for SDCC driver exclusive access.
 *
 * We will need one of these for EACH SD slot eventually.  Right now
 * they are mutually exclusive because they share one critical section.
 */
#ifdef FS_STANDALONE
  #define SDCC_LOCK_INIT() (void)0
  #define SDCC_LOCK()      (void)0
  #define SDCC_UNLOCK()    (void)0
#else
  #include "rex.h"
  static rex_crit_sect_type hotplug_sdcc_crit_sect;
  #define SDCC_LOCK_INIT() rex_init_crit_sect  (&hotplug_sdcc_crit_sect)
  #define SDCC_LOCK()      rex_enter_crit_sect (&hotplug_sdcc_crit_sect)
  #define SDCC_UNLOCK()    rex_leave_crit_sect (&hotplug_sdcc_crit_sect)
#endif

static int lock_is_initialized = 0;

/* Initialize the lock the first time this is called.
 * Harmless if called again. */
void
hotplug_sd_lock_init (struct hotplug_device *hdev)
{
  (void) hdev;
  if (!lock_is_initialized)
  {
    SDCC_LOCK_INIT();
    lock_is_initialized = TRUE;
  }
}

/* Grab the lock */
void
hotplug_sd_lock (struct hotplug_device *hdev)
{
  (void) hdev;
  ASSERT (lock_is_initialized);
  SDCC_LOCK();
}

/* Release the lock */
void
hotplug_sd_unlock (struct hotplug_device *hdev)
{
  (void) hdev;
  ASSERT (lock_is_initialized);
  SDCC_UNLOCK();
}

#else
extern int __dont_complain_about_empty_file;
#endif