void *thread_get_tls_key(int);
uintptr_t thread_id(void);
+uintptr_t thread_get_id(struct thread *t);
void thread_set_id(uintptr_t id);
__END_DECLS
char str[256];
size_t len;
- len = snprintf(str, sizeof(str), "\033[34m%.*s.\033[31m%u\033[0m: ", DISP_NAME_LEN, disp_name(),
- disp_get_core_id());
+ len = snprintf(str, sizeof(str), "\033[34m%.*s.\033[31m%u.%lu\033[0m: ", DISP_NAME_LEN, disp_name(),
+ disp_get_core_id(), thread_id());
if (len < sizeof(str)) {
va_start(argptr, fmt);
vsnprintf(str + len, sizeof(str) - len, fmt, argptr);
assert(!"thread_exit returned");
}
+/// int counter for assigning initial thread ids
+static uintptr_t threadid = 0;
+
#ifndef NDEBUG
/// Debugging assertions on thread queues
static void check_queue(struct thread *queue)
newthread->stack_top = (char *)newthread->stack_top
- (lvaddr_t)newthread->stack_top % STACK_ALIGNMENT;
+ // set thread's ID
+ newthread->id = threadid++;
+
// init registers
registers_set_initial(&newthread->regs, newthread, (lvaddr_t)thread_entry,
(lvaddr_t)newthread->stack_top,
return thread_self()->id;
}
+uintptr_t thread_get_id(struct thread *t)
+{
+ return t->id;
+}
+
void thread_set_id(uintptr_t id)
{
struct thread *me = thread_self();
struct pthread_mutex {
struct thread_mutex mutex;
int locked;
+ struct pthread_mutex_attr attrs;
};
thread_mutex_init(&(*mutex)->mutex);
(*mutex)->locked = 0;
- return 0;
+ if (attr && *attr) {
+ debug_printf("kind = %u\n", (*attr)->kind);
+ memcpy(&(*mutex)->attrs, *attr, sizeof(struct pthread_mutex_attr));
+ } else {
+ (*mutex)->attrs.kind = PTHREAD_MUTEX_NORMAL;
+ (*mutex)->attrs.robustness = 0;
+ (*mutex)->attrs.pshared = PTHREAD_PROCESS_PRIVATE;
+ }
+ return 0;
}
int pthread_mutex_destroy(pthread_mutex_t *mutex)
(*mutex)->locked++;
thread_mutex_unlock(&mutex_mutex);
- thread_mutex_lock_nested(&(*mutex)->mutex);
+ if ((*mutex)->attrs.kind == PTHREAD_MUTEX_RECURSIVE) {
+ thread_mutex_lock_nested(&(*mutex)->mutex);
+ } else {
+ thread_mutex_lock(&(*mutex)->mutex);
+ }
return 0;
}