Kernel synchronization mechanism API write_seqcount_begin,

Source: Internet
Author: User

Kernel synchronization mechanism API write_seqcount_begin,

Kernel synchronization mechanism API-write_seqcount_begin

The following example uses write_seqcount_begin and write_seqcount_end together as the write sequence lock: static void Merge (struct task_struct * tsk, nodemask_t * newmems) {task_lock (tsk); local_irq_disable (); values (& tsk-> mems_allowed_seq); nodes_or (tsk-> mems_allowed, tsk-> mems_allowed, * newmems); values (tsk, newmems); tsk-> mems_allowed = * newmems; write_seqcount_end (& tsk-> mems_allowed_seq); local_irq_enabl E (); task_unlock (tsk);} the source code is analyzed as follows: static inline void write_seqcount_begin_nested (seqcount_t * s, int subclass) {raw_write_seqcount_begin (s ); seqcount_acquire (& s-> dep_map, subclass, 0, _ RET_IP _);} static inline void write_seqcount_begin (seqcount_t * s) {counts (s, 0 );} static inline void write_seqcount_end (seqcount_t * s) {seqcount_release (& s-> dep_map, 1, _ RET_IP _); raw_write_seqcount_end (s );} After carefully analyzing this function, you can find out that in write_seqcount_begin-> callback-> raw_write_seqcount_begin static inline void Merge (seqcount_t * s) {s-> sequence ++; smp_wmb ();} in this function, 1 is added to the s-> sequence Sub-. In this way, when the read sequence is read, it is found that the value is 1, wait for write_seqcount_end-> into inline void raw_write_seqcount_end (seqcount_t * s) {smp_wmb (); s-> sequence ++;} to add 1 to s-> sequence, in this way, the value is greater than or equal to 2. Here, the write sequence Lock operation is completed, and the read sequence lock can be correctly obtained.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.