public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] how to get mutex owner?
@ 2000-08-02 18:36 Fabrice Gautier
  2000-08-03  0:09 ` Boris V. Guzhov
  0 siblings, 1 reply; 4+ messages in thread
From: Fabrice Gautier @ 2000-08-02 18:36 UTC (permalink / raw)
  To: Ecos-List (E-mail)

Hi,

I'm trying to access the owner of a mutex. I'm working in C only.

The mutex struct is not documented but I saw in source code that there was a
owner field. Unfortunately the type of this field is "cyg_thread" and I
didn't find any docuementation for this thread structure. And I can't find
it in the source neither.

I'm also looking for a way to access the thread state. AFAIK there is no
such function in the C API.

Thank You

A+

-- 
Fabrice Gautier
fabrice_gautier@sdesigns.com 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [ECOS] how to get mutex owner?
  2000-08-02 18:36 [ECOS] how to get mutex owner? Fabrice Gautier
@ 2000-08-03  0:09 ` Boris V. Guzhov
  0 siblings, 0 replies; 4+ messages in thread
From: Boris V. Guzhov @ 2000-08-03  0:09 UTC (permalink / raw)
  To: Fabrice Gautier; +Cc: ecos-discuss

> Hi,
>
> I'm trying to access the owner of a mutex. I'm working in C only.
>
> The mutex struct is not documented but I saw in source code that there was
a
> owner field. Unfortunately the type of this field is "cyg_thread" and I
> didn't find any docuementation for this thread structure. And I can't find
> it in the source neither.


Hi,

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
}

Boris Guzhov,
St.Petersburg, Russia



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [ECOS] how to get mutex owner?
  2000-08-03 10:16 Fabrice Gautier
@ 2000-08-04  0:18 ` Boris V. Guzhov
  0 siblings, 0 replies; 4+ messages in thread
From: Boris V. Guzhov @ 2000-08-04  0:18 UTC (permalink / raw)
  To: ecos-discuss

> > 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





^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [ECOS] how to get mutex owner?
@ 2000-08-03 10:16 Fabrice Gautier
  2000-08-04  0:18 ` Boris V. Guzhov
  0 siblings, 1 reply; 4+ messages in thread
From: Fabrice Gautier @ 2000-08-03 10:16 UTC (permalink / raw)
  To: 'Boris V. Guzhov'; +Cc: ecos-discuss

> -----Original Message-----
> From: Boris V. Guzhov [ mailto:borg@int.spb.ru ]
> Subject: Re: [ECOS] how to get mutex owner?
> 
> 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

A+
-- 
Fabrice Gautier
fabrice_gautier@sdesigns.com 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2000-08-04  0:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-08-02 18:36 [ECOS] how to get mutex owner? Fabrice Gautier
2000-08-03  0:09 ` Boris V. Guzhov
2000-08-03 10:16 Fabrice Gautier
2000-08-04  0:18 ` Boris V. Guzhov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).