Skip to content

Commit

Permalink
all: change thread to t
Browse files Browse the repository at this point in the history
  • Loading branch information
Delta456 committed Aug 21, 2023
1 parent b3521cf commit e27d16d
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 129 deletions.
48 changes: 24 additions & 24 deletions kernel/modules/event/event.v
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ fn check_for_pending(mut events []&eventstruct.Event) ?u64 {
return none
}

fn attach_listeners(mut events []&eventstruct.Event, mut thread proc.Thread) {
thread.attached_events_i = 0
fn attach_listeners(mut events []&eventstruct.Event, mut t proc.Thread) {
t.attached_events_i = 0

for i := u64(0); i < events.len; i++ {
mut e := events[i]
Expand All @@ -38,28 +38,28 @@ fn attach_listeners(mut events []&eventstruct.Event, mut thread proc.Thread) {

mut listener := &e.listeners[e.listeners_i]

listener.thread = voidptr(thread)
listener.t = voidptr(t)
listener.which = i

e.listeners_i++

if thread.attached_events_i == proc.max_events {
if t.attached_events_i == proc.max_events {
panic('listening on too many events')
}

thread.attached_events[thread.attached_events_i] = e
thread.attached_events_i++
t.attached_events[t.attached_events_i] = e
t.attached_events_i++
}
}

fn detach_listeners(mut thread proc.Thread) {
for i := u64(0); i < thread.attached_events_i; i++ {
mut e := thread.attached_events[i]
fn detach_listeners(mut t proc.Thread) {
for i := u64(0); i < t.attached_events_i; i++ {
mut e := t.attached_events[i]

for j := u64(0); j < e.listeners_i; j++ {
mut listener := &e.listeners[j]

if listener.thread != voidptr(thread) {
if listener.t != voidptr(t) {
continue
}

Expand All @@ -70,7 +70,7 @@ fn detach_listeners(mut thread proc.Thread) {
}
}

thread.attached_events_i = 0
t.attached_events_i = 0
}

fn lock_events(mut events []&eventstruct.Event) {
Expand All @@ -86,7 +86,7 @@ fn unlock_events(mut events []&eventstruct.Event) {
}

pub fn await(mut events []&eventstruct.Event, block bool) ?u64 {
mut thread := proc.current_thread()
mut t := proc.current_thread()

asm volatile amd64 {
cli
Expand All @@ -111,32 +111,32 @@ pub fn await(mut events []&eventstruct.Event, block bool) ?u64 {

katomic.inc(waiting_event_count)

attach_listeners(mut events, mut thread)
attach_listeners(mut events, mut t)
defer {
asm volatile amd64 {
cli
}
lock_events(mut events)
detach_listeners(mut thread)
detach_listeners(mut t)
unlock_events(mut events)
asm volatile amd64 {
sti
}
}

sched.dequeue_thread(thread)
sched.dequeue_thread(t)

unlock_events(mut events)

sched.yield(true)

katomic.dec(waiting_event_count)

if thread.enqueued_by_signal {
if t.enqueued_by_signal {
return none
}

return thread.which_event
return t.which_event
}

pub fn trigger(mut e eventstruct.Event, drop bool) u64 {
Expand Down Expand Up @@ -166,11 +166,11 @@ pub fn trigger(mut e eventstruct.Event, drop bool) u64 {
}

for i := u64(0); i < e.listeners_i; i++ {
mut thread := unsafe { &proc.Thread(e.listeners[i].thread) }
mut t := unsafe { &proc.Thread(e.listeners[i].t) }

thread.which_event = e.listeners[i].which
t.which_event = e.listeners[i].which

sched.enqueue_thread(thread, false)
sched.enqueue_thread(t, false)
}

ret := e.listeners_i
Expand Down Expand Up @@ -200,10 +200,10 @@ pub fn pthread_exit(ret voidptr) {
sched.yield(false)
}

pub fn pthread_wait(thread &proc.Thread) voidptr {
mut events := [&thread.exited]
pub fn pthread_wait(t &proc.Thread) voidptr {
mut events := [&t.exited]
await(mut events, true) or {}
exit_value := thread.exit_value
unsafe { free(thread) }
exit_value := t.exit_value
unsafe { free(t) }
return exit_value
}
8 changes: 4 additions & 4 deletions kernel/modules/file/epoll.v
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,14 @@ pub fn syscall_epoll_pwait(_ voidptr, epfdnum int, ret_events &EPollEvent, maxev
return errno.err, errno.einval
}

mut thread := proc.current_thread()
mut t := proc.current_thread()

oldmask := thread.masked_signals
oldmask := t.masked_signals
if voidptr(sigmask) != unsafe { nil } {
thread.masked_signals = unsafe { *sigmask }
t.masked_signals = unsafe { *sigmask }
}
defer {
thread.masked_signals = oldmask
t.masked_signals = oldmask
}

mut fdlist := []&FD{}
Expand Down
18 changes: 9 additions & 9 deletions kernel/modules/file/file.v
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ pub const (
)

pub fn syscall_ppoll(_ voidptr, fds &PollFD, nfds u64, tmo_p &time.TimeSpec, sigmask &u64) (u64, u64) {
mut thread := proc.current_thread()
mut process := thread.process
mut t := proc.current_thread()
mut process := t.process

C.printf(c'\n\e[32m%s\e[m: ppoll(0x%llx, %llu, 0x%llx, 0x%llx)\n', process.name.str,
voidptr(fds), nfds, voidptr(tmo_p), voidptr(sigmask))
Expand All @@ -76,12 +76,12 @@ pub fn syscall_ppoll(_ voidptr, fds &PollFD, nfds u64, tmo_p &time.TimeSpec, sig
return 0, 0
}

oldmask := thread.masked_signals
oldmask := t.masked_signals
if voidptr(sigmask) != unsafe { nil } {
thread.masked_signals = unsafe { sigmask[0] }
t.masked_signals = unsafe { sigmask[0] }
}
defer {
thread.masked_signals = oldmask
t.masked_signals = oldmask
}

mut fdlist := []&FD{}
Expand Down Expand Up @@ -371,8 +371,8 @@ pub fn fdnum_dup(_old_process &proc.Process, oldfdnum int, _new_process &proc.Pr
}

pub fn syscall_dup3(_ voidptr, oldfdnum int, newfdnum int, flags int) (u64, u64) {
mut thread := proc.current_thread()
mut process := thread.process
mut t := proc.current_thread()
mut process := t.process

C.printf(c'\n\e[32m%s\e[m: dup3(%d, %d, %d)\n', process.name.str, oldfdnum, newfdnum,
flags)
Expand All @@ -387,8 +387,8 @@ pub fn syscall_dup3(_ voidptr, oldfdnum int, newfdnum int, flags int) (u64, u64)
}

pub fn syscall_fcntl(_ voidptr, fdnum int, cmd int, arg u64) (u64, u64) {
mut thread := proc.current_thread()
mut process := thread.process
mut t := proc.current_thread()
mut process := t.process

C.printf(c'\n\e[32m%s\e[m: fcntl(%d, %d, %lld)\n', process.name.str, fdnum, cmd, arg)
defer {
Expand Down
10 changes: 5 additions & 5 deletions kernel/modules/lib/stubs/pthread.v
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,27 @@ struct C.__thread_data {}
struct C.__threadattr {}

[export: 'pthread_create']
pub fn pthread_create(thread &&C.__thread_data, attr &C.__threadattr, start_routine fn (voidptr) voidptr, arg voidptr) int {
pub fn pthread_create(t &&C.__thread_data, attr &C.__threadattr, start_routine fn (voidptr) voidptr, arg voidptr) int {
if voidptr(attr) != voidptr(0) {
lib.kpanic(voidptr(0), c'pthread_create() called with non-NULL attr')
}

unsafe {
mut ptr := &voidptr(thread)
mut ptr := &voidptr(t)
*ptr = sched.new_kernel_thread(voidptr(start_routine), arg, true)
}
return 0
}

[export: 'pthread_detach']
pub fn pthread_detach(thread &C.__thread_data) int {
pub fn pthread_detach(t &C.__thread_data) int {
return 0
}

[export: 'pthread_join']
pub fn pthread_join(thread &C.__thread_data, mut retval voidptr) int {
pub fn pthread_join(t &C.__thread_data, mut retval voidptr) int {
unsafe {
*retval = event.pthread_wait(&proc.Thread(thread))
*retval = event.pthread_wait(&proc.Thread(t))
}
return 0
}
Expand Down
Loading

0 comments on commit e27d16d

Please sign in to comment.