Hi all,
I was going through spin_lock macro. This method uses the following code.
I was not able to understand what exaclty is happened in this macro.
Spin_lock diables the preempting of the current thread. For that I think it uses thread_info structure which has preempt_count.
But I was not able to understand how exactly it works:
The Macro Flow looks like as follows for me:
# define add_preempt_count(val) do { preempt_count() += (val); } while (0)
# define sub_preempt_count(val) do { preempt_count() -= (val); } while (0)
# define sub_preempt_count(val) do { preempt_count() -= (val); } while (0)
#define inc_preempt_count() add_preempt_count(1)
#define preempt_disable() \
do { \
inc_preempt_count(); \
barrier(); \
} while (0)
do { \
inc_preempt_count(); \
barrier(); \
} while (0)
#define __LOCK(lock) \
do { preempt_disable(); __acquire(lock); (void)(lock); } while (0)
do { preempt_disable(); __acquire(lock); (void)(lock); } while (0)
#define _spin_lock(lock) __LOCK(lock)
#define spin_lock(lock) _spin_lock(lock)
But I was not able to understand how exactly preempting works. when schedular wants to schedule the other process, it checks the thread_info->preempt_count value? If it is yes plese provide me some links or code reference for it.
Thanks
Manjunath