Why ngx_trylock do extra judgement?

Meng Zhang jammy.linux at gmail.com
Sun Jul 20 12:38:25 UTC 2014


I believe it tries to avoid unnecessary memory barrier or bus locking operations, e.g. on X86, usually, the CAS is implemented by "lock cmpxchg X,Y".

Regards,
Jammy


On 20 Jul, 2014, at 11:06 am, 贾凯 <jiakai1000 at gmail.com> wrote:

> 
> Hi there,
> 
> function ngx_shmtx_lock:		if (*mtx->lock == 0 && ngx_atomic_cmp_set(mtx->lock, 0, ngx_pid))
> and ngx_trylock (ngx_atomic.h):		(*(lock) == 0 && ngx_atomic_cmp_set(lock, 0, 1))
> 
> I think ngx_atomic_cmp_set is enough, why Nginx do extra judgement ahead of it ?
> 
> 
> 
> _______________________________________________
> nginx-devel mailing list
> nginx-devel at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx-devel









-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20140720/bfc59f4c/attachment.html>


More information about the nginx-devel mailing list