添加debug,每个线程都维护一个jump帧

This commit is contained in:
ranchuan
2024-06-21 15:20:47 +08:00
parent 9ac75c09ac
commit 474a58e53d
10 changed files with 329 additions and 47 deletions

View File

@@ -5,17 +5,9 @@
#include "mythread.h"
#include "exception.h"
#include "stdio.h"
#include "debug.h"
typedef struct _myth_def{
struct _myth_def *next;
struct _myth_def *last;
pthread_t th;
exception_def except;
size_t id;
int (*func)(void *);
void *arg;
}myth_def;
typedef struct{
myth_def *head;
@@ -32,17 +24,18 @@ int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
static void *p_thread(void *t){
myth_def *th=(myth_def *)t;
th->id=(size_t)pthread_self();
printf("func:%08lx start id=%d.\n",(size_t)th->func,th->id);
DBG_INFO("func:%08lx start id=%d.\n",(size_t)th->func,th->id);
try_{
if(!th->func){
throw_("th->func was null.");
}
th->func(th->arg);
}catch_{
printf("func:%08lx failed.\n",(size_t)th->func);
printf("file=%s,line=%d,err=%s\n",exception()->file,exception()->line,exception()->log);
DBG_WARN("func:%08lx failed.\n",(size_t)th->func);
DBG_WARN("file=%s,line=%d,err=%s\n",exception()->file,exception()->line,exception()->log);
}
printf("func:%08lx end.\n",(size_t)th->func);
DBG_INFO("func:%08lx end.\n",(size_t)th->func);
th->end=1;
return 0;
}
@@ -85,3 +78,20 @@ int myth_join(){
return 0;
}
myth_def *myth_self(){
self_def *s=&g_self;
myth_def *myth=s->head;
size_t id=(size_t)pthread_self();
while(myth){
if(myth->id==id){
return myth;
}
myth=myth->next;
}
printf("can not find myth.\n");
return NULL;
}