Jabberd14-1.6.0/jabberd/heartbeat.c/heartbeat

Last-modified: 2007-03-18 (日) 18:00:47

このページを編集する際は,編集に関する方針に従ってください.

概要

 * this thread continuously checks if a function, that is registered to be called regularly using register_beat() has to be called again
 *

引数

* @param arg unused/ignored

実装

void *heartbeat(void *arg) {

   beat b, b2;
   result r;
   while(1) {
  • 現在のスレッドを1秒間止める。1秒ごとにsignalのチェック。
       pth_sleep(1);
       if(heartbeat__ring==NULL) break;
	/* run through the ring */
	for(b = heartbeat__ring->next; b != heartbeat__ring; b = b->next)
	{
  • freq秒ごとに登録した関数を実行する。
	    /* beats can fire on a frequency, just keep a counter */
	    if(b->last++ == b->freq)
	    {
	        b->last = 0;
	        r = (b->f)(b->arg);
  • 関数を実行した結果がr_UNREGの場合、関数の登録を解除。
	        if(r == r_UNREG)
	        { /* this beat doesn't want to be fired anymore, unlink and free */
	            b2 = b->prev;
		    b->prev->next = b->next;
		    b->next->prev = b->prev;
		    pool_free(b->p);
		    b = b2; /* reset b to accomodate the for loop */
	        }
	    }
	}
   }
   return NULL;

}

呼出元

#related: relatedプラグインは廃止されました。