S.l.e!ep.¢%

像打了激速一样,以四倍的速度运转,开心的工作
简单、开放、平等的公司文化;尊重个性、自由与个人价值;
posts - 1098, comments - 335, trackbacks - 0, articles - 1
  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理
0012eff8 7c827d0b 7c83d236 000002bc 00000000 ntdll!KiFastSystemCallRet
0012effc 7c83d236 000002bc 00000000 00000000 ntdll!NtWaitForSingleObject+0xc
0012f038 7c83d281 000002bc 00000004 00408ab3 ntdll!RtlpWaitOnCriticalSection+0x1a3
0012f058 00403db4 0045b3e4 0045b3e0 0012f074 ntdll!RtlEnterCriticalSection+0xa8

Feedback

# re: 今天发现 EnterCriticalSection 里头还是调用了 WaitForSingleObject[未登录]  回复  更多评论   

2009-07-22 11:19 by nscboy
ntdll!NtWaitForSingleObject+0xc
要确认这个说法需要确认后面那个+0xc的具体含义吧。

# re: 今天发现 EnterCriticalSection 里头还是调用了 WaitForSingleObject  回复  更多评论   

2009-07-22 11:52 by 万连文
这个是具体的代码,有些可以确定的东西没有必要去猜测:

page , 132
subttl "RtlEnterCriticalSection"

;++
;
; NTSTATUS
; RtlEnterCriticalSection(
; IN PRTL_CRITICAL_SECTION CriticalSection
; )
;
; Routine Description:
;
; This function enters a critical section.
;
; Arguments:
;
; CriticalSection - supplies a pointer to a critical section.
;
; Return Value:
;
; STATUS_SUCCESS or raises an exception if an error occured.
;
;--

align 16
cPublicProc _RtlEnterCriticalSection,1
cPublicFpo 1,0

mov ecx,fs:PcTeb ; get current TEB address
mov edx,CriticalSection ; get address of critical section
cmp CsSpinCount[edx],0 ; check if spin count is zero
jne short Ent40 ; if ne, spin count specified

;
; Attempt to acquire critical section.
;

Lock1: ;
lock inc dword ptr CsLockCount[edx] ; increment lock count
jnz short Ent20 ; if nz, already owned

;
; Set critical section owner and initialize recursion count.
;

Ent10:
if DBG
cmp CsOwningThread[edx],0
je @F
stdCall _RtlpCriticalSectionIsOwned, <edx>
mov ecx,fs:PcTeb ; get current TEB address
mov edx,CriticalSection ; get address of critical section
@@:
endif ; DBG
mov eax,TbClientId + 4[ecx] ; get current client ID
mov CsOwningThread[edx],eax ; set critical section owner
mov dword ptr CsRecursionCount[edx],1 ; set recursion count

if DBG

inc dword ptr TbCountOfOwnedCriticalSections[ecx] ; increment owned count
mov eax,CsDebugInfo[edx] ; get debug information address
inc dword ptr CsEntryCount[eax] ; increment entry count

endif ; DBG

xor eax,eax ; set success status

stdRET _RtlEnterCriticalSection

;
; The critical section is already owned, but may be owned by the current thread.
;

align 16
Ent20: mov eax,TbClientId + 4[ecx] ; get current client ID
cmp CsOwningThread[edx],eax ; check if current thread is owner
jne short Ent30 ; if ne, current thread not owner
inc dword ptr CsRecursionCount[edx] ; increment recursion count

if DBG

mov eax,CsDebugInfo[edx] ; get debug information address
inc dword ptr CsEntryCount[eax] ; increment entry count

endif ; DBG

xor eax,eax ; set success status

stdRET _RtlEnterCriticalSection

;
; The critcal section is owned by another thread and the current thread must
; wait for ownership.
;

Ent30: stdCall _RtlpWaitForCriticalSection, <edx> ; wait for ownership
mov ecx,fs:PcTeb ; get current TEB address
mov edx,CriticalSection ; get address of critical section
jmp Ent10 ; set owner and recursion count

;
; A nonzero spin count is specified.
;

align 16
Ent40: mov eax,TbClientId + 4[ecx] ; get current client ID
cmp CsOwningThread[edx],eax ; check if current thread is owner
jne short Ent50 ; if ne, current thread not owner

;
; The critical section is owned by the current thread. Increment the lock
; count and the recursion count.
;

Lock6: ;
lock inc dword ptr CsLockCount[edx] ; increment lock count
inc dword ptr CsRecursionCount[edx] ; increment recursion count

if DBG

mov eax,CsDebugInfo[edx] ; get debug information address
inc dword ptr CsEntryCount[eax] ; increment entry count

endif ; DBG

xor eax,eax ; set success status

stdRET _RtlEnterCriticalSection

;
; A nonzero spin count is specified and the current thread is not the owner.
;

align 16
Ent50: push CsSpinCount[edx] ; get spin count value
Ent60: mov eax,-1 ; set comparand value
mov ecx,0 ; set exchange value

Lock7:
lock cmpxchg dword ptr CsLockCount[edx],ecx ; attempt to acquire critical section
jnz short Ent70 ; if nz, critical section not acquired

;
; The critical section has been acquired. Set the owning thread and the initial
; recursion count.
;

add esp,4 ; remove spin count from stack
mov ecx,fs:PcTeb ; get current TEB address
mov eax,TbClientId + 4[ecx] ; get current client ID
mov CsOwningThread[edx],eax ; set critical section owner
mov dword ptr CsRecursionCount[edx],1 ; set recursion count

if DBG

inc dword ptr TbCountOfOwnedCriticalSections[ecx] ; increment owned count
mov eax,CsDebugInfo[edx] ; get debug information address
inc dword ptr CsEntryCount[eax] ; increment entry count

endif ; DBG

xor eax,eax ; set success status

stdRET _RtlEnterCriticalSection

;
; The critical section is currently owned. Spin until it is either unowned
; or the spin count has reached zero.
;
; If waiters are present, don't spin on the lock since we will never see it go free
;

Ent70: cmp CsLockCount[edx],1 ; check if waiters are present,
jge short Ent76 ; if ge 1, then do not spin

Ent75: YIELD
cmp CsLockCount[edx],-1 ; check if lock is owned
je short Ent60 ; if e, lock is not owned
dec dword ptr [esp] ; decrement spin count
jnz short Ent75 ; if nz, continue spinning
Ent76: add esp,4 ; remove spin count from stack
mov ecx,fs:PcTeb ; get current TEB address
jmp Lock1 ;

stdENDP _RtlEnterCriticalSection

# re: 今天发现 EnterCriticalSection 里头还是调用了 WaitForSingleObject  回复  更多评论   

2009-07-22 18:54 by wocow3
新的SDk EnterCriticalSection在多核的机器上会首先有个自选量,之后才等待挂起。反正MS也没公布EnterCriticalSection的实现细节,现在调用了,没准以后又不用WaitForSingleObject实现了

# re: 今天发现 EnterCriticalSection 里头还是调用了 WaitForSingleObject  回复  更多评论   

2009-07-23 06:00 by 沈国华
x^n+y^n=z^n,(x,y,z,n为有理数,n>2的正整数)要有解则条件...均为有理数为充要条件。这样求解范围可在整个复数中进行。 关于如何可在复数去推行 可由n个公式共同来推导。 最简单的推导是最难证明的 以前理解了1+0=1 现在明白了0+0=0 要证明更困难了 手机:13567398633

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理