Skip to content

core: add an argument to thread_create() #847

@Kijewski

Description

@Kijewski

Our thread_create() looks like that:

int thread_create(char *stack,
                  int stacksize,
                  char priority,
                  int flags,
                  void (*function)(void),
                  const char *name);

The argument function takes a pointer to a function that does not take arguments and returns void. The absence of an argument to function forces one to employ a trampoline, which is complicated because it generally requires extra memory.

I'd be in favor of adding a parameter void *arg to thread_create() and change function to void (*function)(void*).

Because that would break about everything, a new function name should be used, and thread_create() should be kept with the same signature and an implementation like that

static void thread_create_stub(void *function_)
{
    void (*function)(void) = function_;
    function();
}

int thread_create(...)
{
    return thread_create_ex(stack, stacksize, priority, flags,
                            thread_create_stub, function, name);
}

That change would mean that we need to change thread_stack_init() in

  • ./cpu/arm_common/arm_cpu.c,
  • ./cpu/msp430-common/cpu.c,
  • ./cpu/native/native_cpu.c and
  • ./cpu/lpc1768/atom.c,
    but I think it would be worth it.

Opinions?

Metadata

Metadata

Assignees

Labels

Discussion: RFCThe issue/PR is used as a discussion starting point about the item of the issue/PRType: new featureThe issue requests / The PR implemements a new feature for RIOT

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions