[ECOS] how to get mutex owner?
Boris V. Guzhov
borg@int.spb.ru
Fri Aug 4 00:18:00 GMT 2000
> > I think that following code is true.
> >
> > cyg_mutex_t mutex;
> > ...
> > if ( mutex.owner == (cyg_thread *)cyg_thread_self() )
> > {
> > // This thread is the mutex owner
> > }
>
> I'm in plain C. So I don't think this type conversion is very good. It
> should work in C++ maybe.
>
> But instead I finally used:
> if ( mutex.owner->unique_id == cyg_thread_self() )
>
> Thanks
There is the simple C (not C++) example:
#include <stdio.h>
#include <cyg/kernel/kapi.h>
cyg_thread thread;
char stack[4096];
cyg_handle_t h;
cyg_thread_entry_t proc;
cyg_mutex_t mx;
void cyg_user_start(void)
{
cyg_mutex_init(&mx);
cyg_thread_create(4, proc, (cyg_addrword_t) 0,
"proc", (void *) stack, 4096,
&h, &thread);
cyg_thread_resume(h);
}
void proc(cyg_addrword_t data)
{
cyg_mutex_lock(&mx);
printf("Mutex owner: %p\n", mx.owner);
printf("Thread self(): %p\n", (void *)cyg_thread_self());
printf("Thread self(): %p\n", (cyg_thread *)cyg_thread_self());
printf("Mutex owner->unique_id: %p\n", (void *)mx.owner->unique_id);
cyg_mutex_unlock(&mx);
for(;;);
}
It prints:
Mutex owner: 0x10dae0
Thread self(): 0x10dae0
Thread self(): 0x10dae0
Mutex owner->unique_id: 0x3
I think that the unique_id value using is not true.
In my opinion it's true to use:
mutex.owner == (cyg_thread *)cyg_thread_self()
or
mutex.owner == (void *)cyg_thread_self()
Thanks
--
Boris Guzhov
St.Petersburg, Russia
More information about the Ecos-discuss
mailing list