From: seantywork Date: Mon, 17 Mar 2025 06:41:16 +0000 (+0900) Subject: fix lock X-Git-Url: https://git.feebdaed.xyz/?a=commitdiff_plain;h=d3c445b6eb6b0ddcae641d8ad85680aa11f75650;p=socialize.git fix lock --- diff --git a/include/socialize/ctl.h b/include/socialize/ctl.h index 9023557..219cc82 100644 --- a/include/socialize/ctl.h +++ b/include/socialize/ctl.h @@ -65,9 +65,9 @@ void ctx_read_packet(struct HUB_PACKET* hp); void spinlock_init(struct spinlock* spinlock); -void pthread_mutext_lock(struct spinlock* spinlock); +void spinlock_lock(struct spinlock* spinlock); -void pthread_mutext_unlock(struct spinlock* spinlock); +void spinlock_unlock(struct spinlock* spinlock); #endif \ No newline at end of file diff --git a/src/ctl.c b/src/ctl.c index 822442c..712cc16 100644 --- a/src/ctl.c +++ b/src/ctl.c @@ -254,13 +254,13 @@ struct SOCK_CONTEXT* get_sockctx_by_fd(int fd){ struct SOCK_CONTEXT_LOCK* ctxlock; - pthread_mutext_lock(&SOCK_CTL.slock); + pthread_mutex_lock(&SOCK_CTL.slock); if(SOCK_CTL.in_use == 0){ printf("sockctl not in use\n"); - pthread_mutext_unlock(&SOCK_CTL.slock); + pthread_mutex_unlock(&SOCK_CTL.slock); return NULL; } @@ -271,7 +271,7 @@ struct SOCK_CONTEXT* get_sockctx_by_fd(int fd){ ctxlock = SOCK_CTL.SOCK_CTX_LOCK[i]; - pthread_mutext_unlock(&SOCK_CTL.slock); + pthread_mutex_unlock(&SOCK_CTL.slock); pthread_mutex_lock(&ctxlock->lock); @@ -513,13 +513,13 @@ int calloc_sockctx(int fd){ struct SOCK_CONTEXT_LOCK* ctxlock = NULL; - pthread_mutext_lock(&SOCK_CTL.slock); + pthread_mutex_lock(&SOCK_CTL.slock); if(SOCK_CTL.in_use == 0){ printf("sockctl not in use\n"); - pthread_mutext_unlock(&SOCK_CTL.slock); + pthread_mutex_unlock(&SOCK_CTL.slock); return -1; } @@ -530,7 +530,7 @@ int calloc_sockctx(int fd){ ctxlock = SOCK_CTL.SOCK_CTX_LOCK[i]; - pthread_mutext_unlock(&SOCK_CTL.slock); + pthread_mutex_unlock(&SOCK_CTL.slock); pthread_mutex_lock(&ctxlock->lock); @@ -568,13 +568,13 @@ int free_sockctx(int fd, int memfree){ struct SOCK_CONTEXT_LOCK* ctxlock = NULL; - pthread_mutext_lock(&SOCK_CTL.slock); + pthread_mutex_lock(&SOCK_CTL.slock); if(SOCK_CTL.in_use == 0){ printf("sockctl not in use\n"); - pthread_mutext_unlock(&SOCK_CTL.slock); + pthread_mutex_unlock(&SOCK_CTL.slock); return -1; } @@ -586,7 +586,7 @@ int free_sockctx(int fd, int memfree){ ctxlock = SOCK_CTL.SOCK_CTX_LOCK[i]; - pthread_mutext_unlock(&SOCK_CTL.slock); + pthread_mutex_unlock(&SOCK_CTL.slock); pthread_mutex_lock(&ctxlock->lock); @@ -941,11 +941,11 @@ void spinlock_init(struct spinlock* spinlock) { atomic_store(&spinlock->locked, 0); } -void pthread_mutext_lock(struct spinlock* spinlock) { +void spinlock_lock(struct spinlock* spinlock) { while (!atomic_compare_exchange(&spinlock->locked, 0, 1)) { } } -void pthread_mutext_unlock(struct spinlock* spinlock) { +void spinlock_unlock(struct spinlock* spinlock) { atomic_store(&spinlock->locked, 0); } diff --git a/src/sock/sock.c b/src/sock/sock.c index b463cb1..945dd8b 100644 --- a/src/sock/sock.c +++ b/src/sock/sock.c @@ -34,7 +34,7 @@ int init_all(){ SOCK_CTL.in_use = 1; - spinlock_init(&SOCK_CTL.slock); + pthread_mutex_init(&SOCK_CTL.slock, NULL); SOCK_CTL.size = MAX_CONN; @@ -59,7 +59,7 @@ int init_all(){ int free_all(){ - pthread_mutext_lock(&SOCK_CTL.slock); + pthread_mutex_lock(&SOCK_CTL.slock); SOCK_CTL.in_use = 0; @@ -75,7 +75,7 @@ int free_all(){ free(SOCK_CTL.SOCK_CTX_LOCK); - pthread_mutext_unlock(&SOCK_CTL.slock); + pthread_mutex_unlock(&SOCK_CTL.slock); } void sock_listen_and_serve(void* varg){