Oracle Latch:一段描绘Latch运作的伪代码

作者: Maclean Liu , post on May 21st, 2011 , English Version
【本站文章除注明转载外,均为本站原创编译】
转载请注明:文章转载自: Oracle Clinic – Maclean Liu的个人技术博客 [http://www.oracledatabase12g.com/]
本文标题: Oracle Latch:一段描绘Latch运作的伪代码
本文永久地址: http://www.oracledatabase12g.com/archives/oracle-latch%e4%b8%80%e6%ae%b5%e6%8f%8f%e7%bb%98latch%e8%bf%90%e4%bd%9c%e7%9a%84%e4%bc%aa%e4%bb%a3%e7%a0%81.html

以下这段伪代码来自于OraPubCraig A. Shallahamer,这段代码并不长但基本对获取latch、spin、sleep的行为都描述清楚了,如果你对latch仍不甚了了,那么这段代码会对你很有帮助:

 

 

 

Function Get_Latch(latch_name,mode)
{
  If Mode eq ‘immediate’ {
    If Fast_Get(latch_name) {
      return TRUE
    Else {
      return FALSE
    }
  }
  Else {
    If Fast_Get(latch_name)
    Then {
      v$latch.gets++
      return TRUE
    }
    Else {
      v$latch.misses++
      for try = 0 .. large_number
      {
        if Spin_Get(latch_name)
        Then {
          return TRUE
        }
        Else {
          T0 = time
          Sleep(try)
          T1=time
          Register_Event("latch free",T1-T0)
        }
      } -- spin/sleep loop
    }
  }
}

Function Fast_Get(latch_name)
{
  If try_to_get_latch(latch_name)
  Then {
    return TRUE
  }
  Else {
    return FALSE
  }
}

Function Spin_Get(latch_name)
{
  v$latch.spin_get++
  for i = 1 to _spin_count
  {
    If Fast_Get(latch_name)
    Then {
      return TRUE
    }
  }
}

Function Sleep(try)
{
  v$latch.sleeps++
  v$latch.sleep[try]++
  sleeptime =
    decode(try,0,0,1,10,2,20,3,~40,4,~80,...~2000)
  sleep(sleeptime)
}

© 2011 – 2012, www.oracledatabase12g.com. 版权所有.文章允许转载,但必须以链接方式注明源地址,否则追究法律责任.

相关文章 | Related posts:

  1. Latches and Tuning:Latches
  2. Know more about Buffer Cache and Latch
  3. Know more about Oracle Latches
  4. latch free:cache buffer handles造成的SQL性能问题
  5. Basics of C code within the Oracle kernel
  6. How to check and disable Adaptive Cursor Sharing in 11g

2 comments to Oracle Latch:一段描绘Latch运作的伪代码

Leave a Reply

  

  

  

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>