]> git.feebdaed.xyz Git - socialize.git/commitdiff
modify: spin to mutex
authorseantywork <seantywork@gmail.com>
Sat, 15 Mar 2025 08:33:03 +0000 (08:33 +0000)
committerseantywork <seantywork@gmail.com>
Sat, 15 Mar 2025 08:33:03 +0000 (08:33 +0000)
include/socialize/core.h
include/socialize/ctl.h
src/ctl.c
src/sock/sock.c

index 41cb6794ab8d15c22405a71969d921506dfb9ee9..ddf2e1a45bb6e585b3a89e0f8d56ada90c6b695e 100644 (file)
@@ -223,7 +223,7 @@ struct SOCK_CONTEXT_LOCK {
 
 struct SOCK_CTL {
     int in_use;
-    struct spinlock slock;
+    pthread_mutex_t slock;
     int size;
     struct SOCK_CONTEXT** SOCK_CTX;
     struct SOCK_CONTEXT_LOCK** SOCK_CTX_LOCK;
index 219cc826b58cfbd8b7965e8f98c4015625272a5c..90235578ba10bfe4d7270d2edac267bc387852c2 100644 (file)
@@ -65,9 +65,9 @@ void ctx_read_packet(struct HUB_PACKET* hp);
 
 void spinlock_init(struct spinlock* spinlock);
 
-void spinlock_lock(struct spinlock* spinlock);
+void pthread_mutext_lock(struct spinlock* spinlock);
 
-void spinlock_unlock(struct spinlock* spinlock);
+void pthread_mutext_unlock(struct spinlock* spinlock);
 
 
 #endif
\ No newline at end of file
index 800a04367e48ab3ccbb8138dd8ddd02bb97f1c6d..822442c934b6cdc8b12e84c5506e18d59604af16 100644 (file)
--- 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;
 
-    spinlock_lock(&SOCK_CTL.slock);
+    pthread_mutext_lock(&SOCK_CTL.slock);
 
     if(SOCK_CTL.in_use == 0){
 
         printf("sockctl not in use\n");
 
-        spinlock_unlock(&SOCK_CTL.slock);
+        pthread_mutext_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];
 
-    spinlock_unlock(&SOCK_CTL.slock);
+    pthread_mutext_unlock(&SOCK_CTL.slock);
 
     pthread_mutex_lock(&ctxlock->lock);
 
@@ -513,13 +513,13 @@ int calloc_sockctx(int fd){
 
     struct SOCK_CONTEXT_LOCK* ctxlock = NULL;
 
-    spinlock_lock(&SOCK_CTL.slock);
+    pthread_mutext_lock(&SOCK_CTL.slock);
 
     if(SOCK_CTL.in_use == 0){
 
         printf("sockctl not in use\n");
 
-        spinlock_unlock(&SOCK_CTL.slock);
+        pthread_mutext_unlock(&SOCK_CTL.slock);
 
         return -1;
     }
@@ -530,7 +530,7 @@ int calloc_sockctx(int fd){
 
     ctxlock = SOCK_CTL.SOCK_CTX_LOCK[i];
 
-    spinlock_unlock(&SOCK_CTL.slock);
+    pthread_mutext_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;
 
-    spinlock_lock(&SOCK_CTL.slock);
+    pthread_mutext_lock(&SOCK_CTL.slock);
 
     if(SOCK_CTL.in_use == 0){
 
         printf("sockctl not in use\n");
 
-        spinlock_unlock(&SOCK_CTL.slock);
+        pthread_mutext_unlock(&SOCK_CTL.slock);
 
         return -1;
     }
@@ -586,7 +586,7 @@ int free_sockctx(int fd, int memfree){
 
     ctxlock = SOCK_CTL.SOCK_CTX_LOCK[i];
 
-    spinlock_unlock(&SOCK_CTL.slock);
+    pthread_mutext_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 spinlock_lock(struct spinlock* spinlock) {
+void pthread_mutext_lock(struct spinlock* spinlock) {
     while (!atomic_compare_exchange(&spinlock->locked, 0, 1)) {
     }
 }
 
-void spinlock_unlock(struct spinlock* spinlock) {
+void pthread_mutext_unlock(struct spinlock* spinlock) {
     atomic_store(&spinlock->locked, 0);
 }
index af087cf6536c3993481139e24e5023e90c399884..b463cb1646a47935a2628f36c4c336cfb1adf7ca 100644 (file)
@@ -59,7 +59,7 @@ int init_all(){
 
 int free_all(){
 
-    spinlock_lock(&SOCK_CTL.slock);
+    pthread_mutext_lock(&SOCK_CTL.slock);
 
     SOCK_CTL.in_use = 0;
 
@@ -75,7 +75,7 @@ int free_all(){
 
     free(SOCK_CTL.SOCK_CTX_LOCK);
 
-    spinlock_unlock(&SOCK_CTL.slock);
+    pthread_mutext_unlock(&SOCK_CTL.slock);
 }
 
 void sock_listen_and_serve(void* varg){