Re: Custom data formatter for pthread_mutex_t?
Re: Custom data formatter for pthread_mutex_t?
- Subject: Re: Custom data formatter for pthread_mutex_t?
- From: Alastair Houghton <email@hidden>
- Date: Thu, 16 Aug 2007 20:15:56 +0100
On 15 Aug 2007, at 15:05, Cem Karan wrote:
On Tue, 14 Aug 2007 22:47:13 +0100, Peter Mulholland wrote:
What you're suggesting would be useful though... in a function would
be even more useful.. like pthread_mutex_state().
Thank you both. Peter, I agree with you that as a function, this
would be extremely useful. In a way, I'm kind of surprised that
the POSIX spec doesn't have it. Dave, you're right that I can
probably download the source and write up my own pthread_mutex_state
().
You don't need the source for that:
typedef enum { LOCKED = 1, UNLOCKED = 0, INVALID = -1 }
mutex_state_t;
mutex_state_t
pthread_mutex_state (pthread_mutex_t *mutex)
{
int ret = pthread_mutex_trylock (mutex);
if (ret == 0) {
pthread_mutex_unlock (mutex);
return UNLOCKED;
}
if (ret == EBUSY)
return LOCKED;
return INVALID;
}
Obviously it's not perfect, since it will lock and unlock the mutex
to do its test (sometimes, anyway). You might be able to come up
with a better solution by getting the code from Darwin, though from
what I remember it's all based on Mach primitives under the covers
anyway, so you'd need some way to get *their* state in order to do
much better.
Kind regards,
Alastair.
--
http://alastairs-place.net
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden