remove gen from sys thread
This commit is contained in:
parent
c6e1450d88
commit
ceb1ac2059
@ -395,7 +395,7 @@ struct thread_local_store *sys_thread_get_thread_local_store(void);
|
||||
typedef SYS_THREAD_ENTRY_POINT_FUNC_DEF(sys_thread_entry_point_func, data);
|
||||
|
||||
struct sys_thread {
|
||||
u64 handle[2];
|
||||
u64 handle;
|
||||
};
|
||||
|
||||
/* Creates a new thread running in the supplied `entry_point` */
|
||||
|
||||
@ -34,7 +34,6 @@
|
||||
#define WINDOW_CLASS_NAME L"power_play_window_class"
|
||||
|
||||
struct win32_thread {
|
||||
u64 gen;
|
||||
sys_thread_entry_point_func *entry_point;
|
||||
void *thread_data;
|
||||
char thread_name_cstr[256];
|
||||
@ -1594,13 +1593,10 @@ INTERNAL struct win32_thread *win32_thread_alloc_locked(struct sys_lock *lock)
|
||||
if (G.threads_first_free) {
|
||||
t = G.threads_first_free;
|
||||
G.threads_first_free = t->next;
|
||||
*t = (struct win32_thread) {
|
||||
.gen = t->gen + 1
|
||||
};
|
||||
} else {
|
||||
t = arena_push_zero(&G.threads_arena, struct win32_thread);
|
||||
t->gen = 1;
|
||||
t = arena_push(&G.threads_arena, struct win32_thread);
|
||||
}
|
||||
MEMZERO_STRUCT(t);
|
||||
if (!G.threads_first) {
|
||||
G.threads_first = t;
|
||||
} else {
|
||||
@ -1628,35 +1624,8 @@ INTERNAL void win32_thread_release_locked(struct sys_lock *lock, struct win32_th
|
||||
if (G.threads_last == t) {
|
||||
G.threads_last = t->prev;
|
||||
}
|
||||
u64 new_gen = t->gen + 1;
|
||||
*t = (struct win32_thread) {
|
||||
.next = G.threads_first_free,
|
||||
.gen = new_gen
|
||||
};
|
||||
}
|
||||
|
||||
INTERNAL struct win32_thread *win32_thread_from_sys_thread_locked(struct sys_lock *lock, struct sys_thread st)
|
||||
{
|
||||
sys_assert_locked_s(lock, &G.threads_mutex);
|
||||
(UNUSED)lock;
|
||||
|
||||
u64 gen = st.handle[0];
|
||||
struct win32_thread *t = (struct win32_thread *)st.handle[1];
|
||||
if (t->gen == gen) {
|
||||
return t;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
INTERNAL struct sys_thread sys_thread_from_win32_thread_locked(struct sys_lock *lock, struct win32_thread *t)
|
||||
{
|
||||
sys_assert_locked_s(lock, &G.threads_mutex);
|
||||
(UNUSED)lock;
|
||||
|
||||
return (struct sys_thread) {
|
||||
.handle[0] = t->gen,
|
||||
.handle[1] = (u64)t
|
||||
.next = G.threads_first_free
|
||||
};
|
||||
}
|
||||
|
||||
@ -1730,7 +1699,7 @@ struct sys_thread sys_thread_alloc(sys_thread_entry_point_func *entry_point, voi
|
||||
sys_panic(STR("Failed to create thread"));
|
||||
}
|
||||
|
||||
res = sys_thread_from_win32_thread_locked(&lock, t);
|
||||
res.handle = (u64)t;
|
||||
}
|
||||
sys_mutex_unlock(&lock);
|
||||
|
||||
@ -1744,7 +1713,7 @@ void sys_thread_wait_release(struct sys_thread *thread)
|
||||
/* Lookup */
|
||||
struct sys_lock lock = sys_mutex_lock_s(&G.threads_mutex);
|
||||
{
|
||||
struct win32_thread *t = win32_thread_from_sys_thread_locked(&lock, *thread);
|
||||
struct win32_thread *t = (struct win32_thread *)thread->handle;
|
||||
if (t) {
|
||||
handle = t->handle;
|
||||
}
|
||||
@ -2144,7 +2113,7 @@ int CALLBACK wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev_instance,
|
||||
HANDLE app_thread_handle = 0;
|
||||
struct sys_lock lock = sys_mutex_lock_s(&G.threads_mutex);
|
||||
{
|
||||
struct win32_thread *wt = win32_thread_from_sys_thread_locked(&lock, app_thread);
|
||||
struct win32_thread *wt = (struct win32_thread *)app_thread.handle;
|
||||
app_thread_handle = wt->handle;
|
||||
}
|
||||
sys_mutex_unlock(&lock);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user