From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/6111 Path: news.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: [PATCH 5/9] add the functions for mtx_t Date: Sat, 6 Sep 2014 21:54:51 -0400 Message-ID: <20140907015451.GA23797@brightrain.aerifal.cx> References: <0f3acdbceb88a357600611d64f7b5ed13ab3eced.1409524413.git.Jens.Gustedt@inria.fr> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1410054911 2134 80.91.229.3 (7 Sep 2014 01:55:11 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 7 Sep 2014 01:55:11 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-6124-gllmg-musl=m.gmane.org@lists.openwall.com Sun Sep 07 03:55:04 2014 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1XQRh2-0004eW-LT for gllmg-musl@plane.gmane.org; Sun, 07 Sep 2014 03:55:04 +0200 Original-Received: (qmail 5763 invoked by uid 550); 7 Sep 2014 01:55:04 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 5755 invoked from network); 7 Sep 2014 01:55:03 -0000 Content-Disposition: inline In-Reply-To: <0f3acdbceb88a357600611d64f7b5ed13ab3eced.1409524413.git.Jens.Gustedt@inria.fr> User-Agent: Mutt/1.5.21 (2010-09-15) Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:6111 Archived-At: On Mon, Sep 01, 2014 at 12:46:57AM +0200, Jens Gustedt wrote: > diff --git a/src/thread/mtx_trylock.c b/src/thread/mtx_trylock.c > new file mode 100644 > index 0000000..4f55796 > --- /dev/null > +++ b/src/thread/mtx_trylock.c > @@ -0,0 +1,21 @@ > +#include "pthread_impl.h" > +#include > + > +int __pthread_mutex_trylock(pthread_mutex_t *restrict m); > + > +int mtx_trylock(mtx_t *restrict m) { > + if (m->_m_type == PTHREAD_MUTEX_NORMAL) > + return (a_cas(&m->_m_lock, 0, EBUSY) & EBUSY) ? thrd_busy : thrd_success; > + > + int ret = __pthread_mutex_trylock(m); One more thing -- the compiler caught a type mismatch here for pthread_mutex_t vs mtx_t. Casting it away would be valid, but it's also valid to prototype __pthread_mutex_trylock with mtx_t. The latter is consistent with what's done elsewhere so I'll do that. Rich