Browse Source

将mutex改成spinlock

linzhenxing 3 years ago
parent
commit
9e1470ad83

+ 1 - 1
components/drivers/tty/console.c

@@ -302,7 +302,7 @@ rt_err_t console_register(const char *name, struct rt_device *iodev)
     }
     tty_initstack(console->head);
 
-    rt_mutex_init(&console->mutex, "console", RT_IPC_FLAG_PRIO);
+    rt_spin_lock_init(&console->spinlock);
     console->pgrp = -1;
     console->session = -1;
     console->foreground = RT_NULL;

+ 5 - 2
components/drivers/tty/include/tty.h

@@ -148,8 +148,11 @@ struct tty_struct
 
     struct winsize winsize;
     struct termios init_termios;
-    struct rt_mutex mutex;
-
+#ifdef RT_USING_SMP
+    struct rt_spinlock spinlock;
+#else
+    rt_spinlock_t spinlock;
+#endif
     pid_t pgrp;
     pid_t session;
     struct rt_lwp *foreground;

+ 1 - 1
components/drivers/tty/pty.c

@@ -348,7 +348,7 @@ static int ptmx_register(void)
     }
     tty_initstack(ptm_drv->head);
 
-    rt_mutex_init(&ptm_drv->mutex, "pty", RT_IPC_FLAG_PRIO);
+    rt_spin_lock_init(&ptm_drv->spinlock);
     ptm_drv->pgrp = -1;
     ptm_drv->session = -1;
     ptm_drv->foreground = RT_NULL;

+ 4 - 4
components/lwp/lwp.c

@@ -1216,9 +1216,9 @@ pid_t lwp_execve(char *filename, int debug, int argc, char **argv, char **envp)
                     struct rt_lwp *old_lwp;
                     tty = (struct tty_struct *)console_tty_get();
                     old_lwp = tty->foreground;
-                    rt_mutex_take(&tty->mutex, RT_WAITING_FOREVER);
+                    rt_spin_lock(&tty->spinlock);
                     ret = tty_push(&tty->head, old_lwp);
-                    rt_mutex_release(&tty->mutex);
+                    rt_spin_unlock(&tty->spinlock);
                     if (ret < 0)
                     {
                         lwp_tid_put(tid);
@@ -1240,9 +1240,9 @@ pid_t lwp_execve(char *filename, int debug, int argc, char **argv, char **envp)
                 {
                     if (self_lwp != RT_NULL)
                     {
-                        rt_mutex_take(&self_lwp->tty->mutex, RT_WAITING_FOREVER);
+                        rt_spin_lock(&self_lwp->tty->spinlock);
                         ret = tty_push(&self_lwp->tty->head, self_lwp);
-                        rt_mutex_release(&self_lwp->tty->mutex);
+                        rt_spin_unlock(&self_lwp->tty->spinlock);
                         if (ret < 0)
                         {
                             lwp_tid_put(tid);

+ 2 - 2
components/lwp/lwp_pid.c

@@ -447,9 +447,9 @@ void lwp_free(struct rt_lwp* lwp)
         level = rt_hw_interrupt_disable();
         if (lwp->tty != RT_NULL)
         {
-            rt_mutex_take(&lwp->tty->mutex, RT_WAITING_FOREVER);
+            rt_spin_lock(&lwp->tty->spinlock);
             old_lwp = tty_pop(&lwp->tty->head, RT_NULL);
-            rt_mutex_release(&lwp->tty->mutex);
+            rt_spin_unlock(&lwp->tty->spinlock);
             if (lwp->tty->foreground == lwp)
             {
                 lwp->tty->foreground = old_lwp;

+ 2 - 2
components/lwp/lwp_syscall.c

@@ -1729,9 +1729,9 @@ int _sys_fork(void)
         struct rt_lwp *old_lwp;
 
         old_lwp = lwp->tty->foreground;
-        rt_mutex_take(&lwp->tty->mutex, RT_WAITING_FOREVER);
+        rt_spin_lock(&lwp->tty->spinlock);
         ret = tty_push(&lwp->tty->head, old_lwp);
-        rt_mutex_release(&lwp->tty->mutex);
+        rt_spin_unlock(&lwp->tty->spinlock);
         if (ret < 0)
         {
             LOG_E("malloc fail!\n");