Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 6 Apr 2017 11:31:23 +0200
From:      Ed Schouten <ed@nuxi.nl>
To:        Yubin Ruan <ablacktshirt@gmail.com>
Cc:        FreeBSD Hackers <freebsd-hackers@freebsd.org>
Subject:   Re: Understanding the FreeBSD locking mechanism
Message-ID:  <CABh_MKkbVVi%2BgTkaBVDvVfRggS6pbHKJE_VbYBZpAaTCZ81b7Q@mail.gmail.com>
In-Reply-To: <e99b6366-7d30-a889-b7db-4a3b3133ff5e@gmail.com>
References:  <e99b6366-7d30-a889-b7db-4a3b3133ff5e@gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
Hi Yubin,

2017-04-06 11:16 GMT+02:00 Yubin Ruan <ablacktshirt@gmail.com>:
> Does this function provides the ordinary "spinlock" functionality? There
> is no special "test-and-set" instruction, and neither any extra locking
> to protect internal data structure manipulation. Isn't this subjected to
> race condition?

Locking a spinlock is done through macro mtx_lock_spin(), which
expands to __mtx_lock_spin() in sys/sys/mutex.h. That macro first
calls into the function you looked at, spinlock_enter(), to disable
interrupts. It then calls into the _mtx_obtain_lock_fetch() to do the
test-and-set operation you were looking for.

Best regards,
-- 
Ed Schouten <ed@nuxi.nl>
Nuxi, 's-Hertogenbosch, the Netherlands
KvK-nr.: 62051717



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CABh_MKkbVVi%2BgTkaBVDvVfRggS6pbHKJE_VbYBZpAaTCZ81b7Q>