FreeBSD/lib/libthr/thread/thr_kern.c
/*
 * Allocate wake-address, the memory area is never freed after
 * allocated, this becauses threads may be referencing it.
 */
Allocate wake-address, the memory area is never freed after
allocated, this becauses threads may be referencing it.
Allocate wake - address the memory area is never freed after allocated this becauses threads may be referencing it .
struct wake_addr *
_thr_alloc_wake_addr(void)
{
	struct pthread *curthread;
	struct wake_addr *p;
	if (_thr_initial == NULL) {
		return &default_wake_addr;
	}
	curthread = _get_curthread();
	THR_LOCK_ACQUIRE(curthread, &addr_lock);
	if (wake_addr_head == NULL) {
		unsigned i;
		unsigned pagesize = getpagesize();
		struct wake_addr *pp = (struct wake_addr *)
			mmap(NULL, getpagesize(), PROT_READ|PROT_WRITE,
			MAP_ANON|MAP_PRIVATE, -1, 0);
		for (i = 1; i < pagesize/sizeof(struct wake_addr); ++i)
			pp[i].link = &pp[i+1];
		pp[i-1].link = NULL;	
		wake_addr_head = &pp[1];
		p = &pp[0];
	} else {
		p = wake_addr_head;
		wake_addr_head = p->link;
	}
	THR_LOCK_RELEASE(curthread, &addr_lock);
	p->value = 0;
	return (p);
}
struct wake_addr * _thr_alloc_wake_addr ( void ) { struct pthread * curthread ; struct wake_addr * p ; if ( _thr_initial == NULL ) { return & default_wake_addr ; } curthread = _get_curthread ( ) ; THR_LOCK_ACQUIRE ( curthread , & addr_lock ) ; if ( wake_addr_head == NULL ) { unsigned i ; unsigned pagesize = getpagesize ( ) ; struct wake_addr * pp = ( struct wake_addr * ) mmap ( NULL , getpagesize ( ) , PROT_READ | PROT_WRITE , MAP_ANON | MAP_PRIVATE , -1 , 0 ) ; for ( i = 1 ; i < pagesize / sizeof ( struct wake_addr ) ; ++ i ) pp [ i ] . link = & pp [ i + 1 ] ; pp [ i - 1 ] . link = NULL ; wake_addr_head = & pp [ 1 ] ; p = & pp [ 0 ] ; } else { p = wake_addr_head ; wake_addr_head = p -> link ; } THR_LOCK_RELEASE ( curthread , & addr_lock ) ; p -> value = 0 ; return ( p ) ; }
Allocate wake-address, the memory area is never freed after
 allocated, this becauses threads may be referencing it.
Allocate wake - address the memory area is never freed after allocated this becauses threads may be referencing it .