Reading Gauche/Reading Gauche 0.9/gc/pthread_support.c/GC_lock


Top / Reading Gauche / Reading Gauche 0.9 / gc / pthread_support.c / GC_lock

GC_lock

概要

編集中

void GC_lock(void)
{
#   define low_spin_max 30  /* spin cycles if we suspect uniprocessor */
#   define high_spin_max SPIN_MAX /* spin cycles for multiprocessor */
   static unsigned spin_max = low_spin_max;
   unsigned my_spin_max;
   static unsigned last_spins = 0;
   unsigned my_last_spins;
   int i;

   if (AO_test_and_set_acquire(&GC_allocate_lock) == AO_TS_CLEAR) {
       return;
   }
   my_spin_max = spin_max;
   my_last_spins = last_spins;
   for (i = 0; i < my_spin_max; i++) {
       if (GC_collecting || GC_nprocs == 1) goto yield;
       if (i < my_last_spins/2) {
           GC_pause();
           continue;
       }
       if (AO_test_and_set_acquire(&GC_allocate_lock) == AO_TS_CLEAR) {
	    /*
            * got it!
            * Spinning worked.  Thus we're probably not being scheduled
            * against the other process with which we were contending.
            * Thus it makes sense to spin longer the next time.
	     */
           last_spins = i;
           spin_max = high_spin_max;
           return;
       }
   }
   /* We are probably being scheduled against the other process.  Sleep. */
   spin_max = low_spin_max;
yield:
   for (i = 0;; ++i) {
       if (AO_test_and_set_acquire(&GC_allocate_lock) == AO_TS_CLEAR) {
           return;
       }
#       define SLEEP_THRESHOLD 12
		/* Under Linux very short sleeps tend to wait until	*/
		/* the current time quantum expires.  On old Linux	*/
		/* kernels nanosleep(<= 2ms) just spins under Linux.    */
		/* (Under 2.4, this happens only for real-time		*/
		/* processes.)  We want to minimize both behaviors	*/
		/* here.						*/
       if (i < SLEEP_THRESHOLD) {
           sched_yield();
	} else {
	    struct timespec ts;
	
	    if (i > 24) i = 24;
			/* Don't wait for more than about 15msecs, even	*/
			/* under extreme contention.			*/
	    ts.tv_sec = 0;
	    ts.tv_nsec = 1 << i;
	    nanosleep(&ts, 0);
	}
   }
}

調べるもの

参照元

コメント

コメントはありません。 コメント/Reading Gauche/Reading Gauche 0.9/gc/pthread_support.c/GC_lock?

お名前:

MENU

now: 4

リンク


最新の20件
2018-05-03 2017-09-29 2017-04-25 2017-01-10 2016-12-11 2016-10-04 2016-08-14 2016-06-05 2016-05-29 2016-04-15 2015-12-28 2013-02-25 2013-02-21 2013-02-20 2013-02-12 2013-02-11 2013-02-10
最新の20件
2010-02-01 2010-01-31 2010-01-30 2010-01-29 2010-01-16

Counter: 1584, today: 1, yesterday: 0

リロード   新規 編集 凍結 差分 添付 複製 改名   トップ 一覧 検索 最終更新 バックアップ   ヘルプ   最終更新のRSS

Last-modified: 2010-01-16 (土) 20:59:09 (3081d);  Modified by mona
PukiWiki 1.4.6 Copyright © 2001-2005 PukiWiki Developers Team. License is GPL.
Based on "PukiWiki" 1.3 by yu-ji
Powered by PHP 5.2.17
HTML convert time to 0.068 sec.