Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Sat, 6 Sep 2014 21:54:51 -0400
From: Rich Felker <dalias@...c.org>
To: musl@...ts.openwall.com
Subject: Re: [PATCH 5/9] add the functions for mtx_t

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 <threads.h>
> +
> +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

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.