#include <uk/config.h>
#include <uk/syscall.h>
+#define TIDMAP_SIZE (CONFIG_LIBPOSIX_PROCESS_MAX_PID + 1)
+
#if CONFIG_LIBPOSIX_PROCESS_PIDS
#include <uk/bitmap.h>
#include <uk/list.h>
/**
* System global lists
*/
-static struct posix_thread *tid_thread[CONFIG_LIBPOSIX_PROCESS_MAX_PID];
-static unsigned long tid_map[UK_BITS_TO_LONGS(CONFIG_LIBPOSIX_PROCESS_MAX_PID)];
+static struct posix_thread *tid_thread[TIDMAP_SIZE];
+static unsigned long tid_map[UK_BITS_TO_LONGS(TIDMAP_SIZE)];
/**
* Thread-local posix_thread reference
unsigned long found;
/* search starting from last position */
- found = uk_find_next_zero_bit(tid_map,
- CONFIG_LIBPOSIX_PROCESS_MAX_PID, prev);
- if (found == CONFIG_LIBPOSIX_PROCESS_MAX_PID) {
+ found = uk_find_next_zero_bit(tid_map, TIDMAP_SIZE, prev);
+ if (found == TIDMAP_SIZE) {
/* search again starting from the beginning */
- found = uk_find_first_zero_bit(tid_map,
- CONFIG_LIBPOSIX_PROCESS_MAX_PID);
+ found = uk_find_first_zero_bit(tid_map, TIDMAP_SIZE);
}
- if (found == CONFIG_LIBPOSIX_PROCESS_MAX_PID) {
+ if (found == TIDMAP_SIZE) {
/* no free PID */
return -1;
}
/* TODO: Mutex */
tid = find_free_tid();
- if (tid >= 0)
+ if (tid > 0)
uk_set_bit(tid, tid_map);
return tid;
}
static void release_tid(pid_t tid)
{
- UK_ASSERT(tid >= 0 && tid <= CONFIG_LIBPOSIX_PROCESS_MAX_PID);
+ UK_ASSERT(tid > 0 && tid <= CONFIG_LIBPOSIX_PROCESS_MAX_PID);
/* TODO: Mutex */
uk_clear_bit(tid, tid_map);
uk_pr_debug("Process PID %d created (parent PID: %d)\n",
(int) pprocess->pid,
- (int) ((pprocess->parent) ? pprocess->parent->pid : -1));
+ (int) ((pprocess->parent) ? pprocess->parent->pid : 0));
return 0;
err_free_pprocess:
UK_ASSERT(pthread_self->process);
if (!pthread_self->process->parent) {
- /* no parent, return own PID */
- return pthread_self->process->pid;
+ /* no parent, return 0 */
+ return 0;
}
return pthread_self->process->parent->pid;
{
pid_t child_tid = ukthread2tid(child);
- UK_ASSERT(child_tid >= 0);
+ UK_ASSERT(child_tid > 0);
if (!cl_args->parent_tid)
return -EINVAL;
{
pid_t child_tid = ukthread2tid(child);
- UK_ASSERT(child_tid >= 0);
+ UK_ASSERT(child_tid > 0);
if (!cl_args->child_tid)
return -EINVAL;