Date: Sun, 04 Dec 2005 11:34:18 +0800 From: David Xu <davidxu@freebsd.org> To: David Xu <davidxu@freebsd.org> Cc: Jason Evans <jasone@canonware.com>, current@freebsd.org Subject: Re: New libc malloc patch Message-ID: <439263BA.1090404@freebsd.org> In-Reply-To: <43925A0D.8070906@freebsd.org> References: <B6653214-2181-4342-854D-323979D23EE8@canonware.com> <Pine.LNX.4.53.0511291121360.27754@regurgitate.ugcs.caltech.edu> <0B746373-8C29-4ADF-9218-311AE08F3834@canonware.com> <4391569A.7080808@freebsd.org> <D1B3ED90-7936-41AA-93D3-AAC7E1615CDA@canonware.com> <43924917.3070506@freebsd.org> <43925A0D.8070906@freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
David Xu wrote: > Here is sample code to implement a mutex by using umtx syscalls: > ... > void > unlock_mtx(struct umtx *mtx) > { > volatile uintptr_t *m = (volatile uintptr_t *)mtx; > > for (;;) { > if (atomic_load_acq_ptr(m) == LCK_UNLOCKED) > err(1, "unlock a unlocked mutex\n"); > if (atomic_load_acq_ptr(m) == LCK_LOCKED) { > if (atomic_cmpset_acq_ptr(m, LCK_LOCKED, LCK_UNLOCKED)) > return; > } > if (atomic_load_acq_ptr(m) == LCK_CONTENDED) { > atomic_store_rel_ptr(m, LCK_UNLOCKED); > _umtx_op((struct umtx *)m, UMTX_OP_WAKE, 1, NULL, NULL); OOP, should be: _umtx_op((struct umtx *)m, UMTX_OP_WAKE, INT_MAX, NULL, NULL); This line is not very optimal if there are lots of thread waiting there. :-) There is optimal version using transaction id: http://www.dragonflybsd.org/cvsweb/src/lib/libthread_xu/thread/thr_umtx.c?rev=1.2&content-type=text/x-cvsweb-markup Though, libthr in freebsd does not use these semantices, instead they are implemented in kernel. David Xu
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?439263BA.1090404>