1/*
2 * Copyright 2017, Data61
3 * Commonwealth Scientific and Industrial Research Organisation (CSIRO)
4 * ABN 41 687 119 230.
5 *
6 * This software may be distributed and modified according to the terms of
7 * the BSD 2-Clause license. Note that NO WARRANTY is provided.
8 * See "LICENSE_BSD2.txt" for details.
9 *
10 * @TAG(DATA61_BSD)
11 */
12
13#include <sel4debug/identity.h>
14#include "identity-internal.h"
15#include <stdlib.h>
16
17static const char *id_str;
18static const char *(*id_fn)(void);
19
20void debug_set_id(const char *s)
21{
22    id_str = s;
23    id_fn = NULL;
24}
25
26void debug_set_id_fn(const char * (*fn)(void))
27{
28    id_fn = fn;
29    id_str = NULL;
30}
31
32/* Return the identity of the current thread using whatever information the
33 * user previously told us. Note, this will return NULL if the user has not
34 * initialised either source of thread ID.
35 */
36const char *debug_get_id(void)
37{
38    if (id_fn != NULL) {
39        return id_fn();
40    } else {
41        return id_str;
42    }
43}
44