Linux?μ?????????
???????????? ???????[ 2016/6/30 14:09:43 ] ?????????????? Linux
	???????
	?????????д??????μ???????????????漰?????????????????-??????????????????????????????????????????????????????????????Щ??????????????????????????????????Linux?μ??????-??Щ“??”????????????????????????????????????????????????
	???????
	??????????????Linux????У???????????????????????????????????spin_lock????????????mutex????????????semaphore????????????
	??????????
	???????????????????????????????????ò?????????????????????κ????????????????????????У???????????С?????С????е?λ????????????????????????????????????API???????????嶼????????????include/asm/atomic.h????У?????????????????
	???????????????????????????????????ü???????????????????
	?????????????壺
	????typedef struct{
	????volatile int counter;
	????}atomic_t;
	????volatile????????ε???ο?????gcc???????????????????????????????????????????????????????????????
	????????????API??
	????1??atomic_read(atomic_t *v);
	?????????????????????????????????????????????????????v?????
	????2??atomic_set(atomic_t *v??int i);
	????????????????????????v????i??
	????3??atomic_add(int i??atomic_t *v);
	??????????????????????v?????i??
	????4??atomic_sub(int i??atomic_t *v);
	??????????????????????v?м??i??
	????5??atomic_sub_and_test(int i?? atomic_t *v);
	??????????????????????v?м??i?????ж???????0??????0???????棬????????
	????6??atomic_inc(atomic_t *v);
	?????????????????????v????????1??
	????7??atomic_dec(atomic_t *v);
	??????????????????????v?????1??
	????8??atomic_dec_and_test(atomic_t *v);
	??????????????????????v?????1?????ж???????0??????0???????棬????????
	????9??int atomic_inc_and_test(atomic_t *v);
	??????????????????????v????????1?????ж???????0??????0???????棬????????
	????10??atomic_add_negative(int i?? atomic_t*v);
	??????????????????????v????????i?????ж????????????????????????棬????????
	????11??atomic_add_return(int i?? atomic_t *v);
	??????????????????????v????????i????????????v?????
	????12??int atomic_sub_return(int i?? atomic_t *v);
	??????????????????????v?м??i????????????v?????
	????13??int atomic_inc_return(atomic_t * v);
	??????????????????????v????????1??????????v?????
	????14??int atomic_dec_return(atomic_t * v);
	??????????????????????v?????1??????????v?????
	????????????????????????????ü???????TCP/IPЭ?????IP????????У?????????ü???????????н?structipq?????????IP????????refcnt?????ü????????????????atomic_t????????IP???????????ip_frag_create?У??????atomic_set?????????????1?????????IP????????ú???atomic_inc?????ü?????1??????????????IP????????ú???ipq_put??????IP?????ipq_put??ú???atomic_dec_and_test?????ü?????1???ж????ü???????0??????????Ip?????????ipq_kill??IP?????ipq?????????????????????IP????????ü?????1???????ú???atomic_dec??????
	?????????
	??????????????????????????????????????????????繲????棩?????????????Э??????????????????????????????????淽???????????
	???????????????????????????????????????2??裺
	????1??????????????????????
	????2?????????????????????????????????????????????
	????3??????0?????????????????????sleep???????????????0?????????????????1???????У?
	????4???????????????????????????????????????1???????????н?????sleep??????????????????????y????
	????????????????????/usr/src/linux/include/linux/sem.h ?У????????????????????????????????????????е????????
	????Linux2.6.26??????????????壺
	????struct semaphore {
	????spinlock_t                lock;
	????unsigned int             count;
	????struct list_head        wait_list;
	????};
	?????????????????????У??????????????????????spinlock??????????????spinlock????????????count??????????????(count--)?????(count > 0)??
	???????????pv????
	???????????P????
	??????1??void down(struct semaphore *sem);
	??????2??int down_interruptible(struct semaphore *sem);
	??????3??int down_trylock(struct semaphore *sem);
	????(1)?е????????2.6.26?е???????????????????out??(Use of this function is deprecated)?????????y??????????????ɡ?
	????(2)?????????????
	/**
	* down_interruptible - acquire the semaphore unless interrupted
	* @sem: the semaphore to be acquired
	*
	* Attempts to acquire the semaphore.  If no more tasks are allowed to
	* acquire the semaphore?? calling this function will put the task to sleep.
	* If the sleep is interrupted by a signal?? this function will return -EINTR.
	* If the semaphore is successfully acquired?? this function returns 0.
	*/
	int down_interruptible(struct semaphore *sem)
	{
	unsigned long flags;
	int result = 0;
	spin_lock_irqsave(&sem->lock?? flags);
	if (likely(sem->count > 0))
	sem->count--;
	else
	result = __down_interruptible(sem);
	spin_unlock_irqrestore(&sem->lock?? flags);
	return result;
	}
	?????????????????????????????£??????count??????0??????????????????????????????????????count--?????????????????????????????????????????????????????????????л????????????????????struct semaphore ??wait_list?????????У????????
	???????????????????????__down_interruptible()?????У????????struct semaphore_waiter????????struct semaphore_waiter???????£?
	????struct semaphore_waiter
	????{
	????struct list_head list;
	????struct task_struct *task;
	????int up;
	????};
	????????????????task??????????list???????????????????sem?е?wait_list??????????б??У??????ж????????sem?????down_interruptible????sem??wait_list???γ????????????
	
	????(???????????????????????????????????????????У??????????????????????TASK_INTERRUPTIBLE??????????????schedule()?????????????????cpu?????ж????????)
	
??????
					
					???·???
App??С????H5?????????????????Щ??
2024/9/11 15:34:34?????????????????????????
2024/9/10 11:13:49P-One ???????????????????????????????????????
2024/9/10 10:14:12???????????????????????????
2024/9/9 18:04:26??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44
					
			
								
								
								
								
								
								
								
								
								
								
				
sales@spasvo.com