* [Xenomai-help] rt_heap_delete in asynchronous context
@ 2006-05-29 0:01 Nathaniel J Villaume
2006-05-29 12:45 ` Gilles Chanteperdrix
0 siblings, 1 reply; 3+ messages in thread
From: Nathaniel J Villaume @ 2006-05-29 0:01 UTC (permalink / raw)
To: xenomai
Hi,
I have a simple user-space program (see below) that tries to
create a heap. If the heap already exists, then the program tries
to delete it. I have no other threads binding to the heap.
I can create, but not delete the heap. The error returned is
-EPERM. According to the API manual, this means the call occurred
in an asynchronous context. What does this mean, exactly? How
should I delete this heap?
Any advice?
BTW, superb job on the documentation, it's made my learning curve
easy/straight-forward.
Thanks,
Nate
/*************************************************/
/*! @file
@brief
File shows how to allocate heap memory from user-space
*/
#include "native/heap.h"
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
RT_HEAP heap;
const char hp_name[]="heap1";
size_t hp_size = 500000;
RT_HEAP_INFO hp_info;
/*Map error codes to human-readable strings*/
void xeno_error_lookup(const char* msg, int err);
int
main( void )
{
int err = 0;
err = rt_heap_create( &heap, hp_name, hp_size, H_SHARED);
if (err)
{
printf("Couldn't create the heap\n");
if (-EEXIST == err)
{
printf("Deleting heap....\n");
err = rt_heap_delete( &heap);
if (err)
{
xeno_error_lookup("Couldn't delete heap.", err);
}
}
exit(err);
}
return err;
}
void xeno_error_lookup(const char* msg, int err)
{
char* pc=0;
switch (err)
{
case -EINVAL:
pc = "EINVAL";
break;
case -EIDRM:
pc = "EIDRM";
break;
case -EPERM:
pc = "EPERM";
break;
}
printf("%s: %d => %s\n", msg, err, pc);
}
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Xenomai-help] rt_heap_delete in asynchronous context
2006-05-29 0:01 [Xenomai-help] rt_heap_delete in asynchronous context Nathaniel J Villaume
@ 2006-05-29 12:45 ` Gilles Chanteperdrix
2006-05-29 18:19 ` Nathaniel J Villaume
0 siblings, 1 reply; 3+ messages in thread
From: Gilles Chanteperdrix @ 2006-05-29 12:45 UTC (permalink / raw)
To: Nathaniel.J.Villaume; +Cc: xenomai
Nathaniel J Villaume wrote:
> Hi,
>
> I have a simple user-space program (see below) that tries to
> create a heap. If the heap already exists, then the program tries
> to delete it. I have no other threads binding to the heap.
>
> I can create, but not delete the heap. The error returned is
> -EPERM. According to the API manual, this means the call occurred
> in an asynchronous context. What does this mean, exactly? How
> should I delete this heap?
>
> Any advice?
You should not try and delete a heap if you did not succeed in creating
or binding it. The contents of the RT_HEAP object are uninitialized
when rt_heap_create fails, rt_heap_delete call munmap passing the
contents of this uninitialized object, and munmap returns -1 with errno
set to EINVAL. rt_heap_delete should be fixed to return -errno in this
case, but you should bind the heap before deleting it.
--
Gilles Chanteperdrix.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Xenomai-help] rt_heap_delete in asynchronous context
2006-05-29 12:45 ` Gilles Chanteperdrix
@ 2006-05-29 18:19 ` Nathaniel J Villaume
0 siblings, 0 replies; 3+ messages in thread
From: Nathaniel J Villaume @ 2006-05-29 18:19 UTC (permalink / raw)
To: Gilles Chanteperdrix; +Cc: xenomai, Nathaniel.J.Villaume
Gilles,
Thanks for the reply. Sure enough, binding to the heap allows me
to delete it. I wanted to update the documentation, but I'm not
sure I understand it well enough. Here's my attempt
--I hope it clarifies rather than obscures! :
--- ksrc/skins/native/heap.c 2006-04-09 14:03:50.000000000 -0700
+++ ksrc/skins/native/heap.c.new 2006-05-27 22:54:44.000000000 -0700
@@ -351,7 +351,8 @@
* - -EIDRM is returned if @a heap is a deleted heap descriptor.
*
* - -EPERM is returned if this service was called from an
- * asynchronous context.
+ * asynchronous context. The heap may first need to be
associated with the
+ * calling process using rt_heap_bind().
*
* Environments:
*
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2006-05-29 18:19 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-05-29 0:01 [Xenomai-help] rt_heap_delete in asynchronous context Nathaniel J Villaume
2006-05-29 12:45 ` Gilles Chanteperdrix
2006-05-29 18:19 ` Nathaniel J Villaume
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.