genode/repos/libports/src/lib/libc/pthread_create.cc
Norman Feske 648bcd1505 libc: unify use of namespaces
This patch unifies the patterns of using the 'Genode' and 'Libc'
namespaces.

Types defined in the 'internal/' headers reside in the 'Libc'
namespace. The code in the headers does not need to use the
'Libc::' prefix.

Compilation units import the 'Libc' namespace after the definition of
local types. Local types reside in the 'Libc' namespace (and should
eventually move to an 'internal/' header).

Since the 'Libc' namespace imports the 'Genode' namespace, there is
no need to use the 'Genode::' prefix. Consequently, code in the
compilation units rarely need to qualify the 'Genode' or 'Libc'
namespaces.

There are a few cases where the 'Libc', the 'Genode', and the global
(libc) namespaces are ambigious. In these cases, an explicit
clarification is needed:

- 'Genode::Allocator' differs from 'Libc::Allocator'.
- 'Genode::Env' differs from 'Libc::Env'.
- Genode's string functions (strcmp, memcpy, strcpy) conflict
  with the names of the (global) libc functions.
- There exist both 'Genode::uint64_t' and the libc'c 'uint64_t'.

Issue #3497
2019-11-19 14:10:55 +01:00

73 lines
1.8 KiB
C++

/*
* \brief pthread_create implementation
* \author Christian Prochaska
* \date 2012-03-12
*
* Purpose of a single file for pthread_create is that other application may
* easily replace this implementation with another one.
*/
/*
* Copyright (C) 2012-2017 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU Affero General Public License version 3.
*/
/* libc includes */
#include <libc/allocator.h>
#include <errno.h>
/* libc-internal includes */
#include <internal/thread_create.h>
#include <internal/pthread.h>
int Libc::pthread_create(pthread_t *thread,
void *(*start_routine) (void *), void *arg,
size_t stack_size, char const * name,
Cpu_session * cpu, Affinity::Location location)
{
Libc::Allocator alloc { };
pthread_t thread_obj = new (alloc)
pthread(start_routine, arg,
stack_size, name, cpu, location);
if (!thread_obj)
return EAGAIN;
*thread = thread_obj;
thread_obj->start();
return 0;
}
int Libc::pthread_create(pthread_t *thread, Thread &t)
{
Libc::Allocator alloc { };
pthread_t thread_obj = new (alloc) pthread(t);
if (!thread_obj)
return EAGAIN;
*thread = thread_obj;
return 0;
}
extern "C"
{
int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
void *(*start_routine) (void *), void *arg)
{
size_t const stack_size = (attr && *attr && (*attr)->stack_size)
? (*attr)->stack_size
: Libc::Component::stack_size();
return Libc::pthread_create(thread, start_routine, arg, stack_size,
"pthread", nullptr,
Genode::Affinity::Location());
}
}