]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
A naming-only change: rename VG_(set_running) to VG_(acquire_BigLock)
authorJulian Seward <jseward@acm.org>
Sun, 17 Dec 2006 18:58:55 +0000 (18:58 +0000)
committerJulian Seward <jseward@acm.org>
Sun, 17 Dec 2006 18:58:55 +0000 (18:58 +0000)
and VG_(set_sleeping) to VG_(release_BigLock).  And some other minor
renamings to the thread locking stuff, to make it easier to follow.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@6408

coregrind/m_scheduler/priv_sema.h
coregrind/m_scheduler/scheduler.c
coregrind/m_scheduler/sema.c
coregrind/m_signals.c
coregrind/m_syswrap/syswrap-linux.c
coregrind/m_syswrap/syswrap-main.c
coregrind/m_syswrap/syswrap-ppc32-aix5.c
coregrind/m_syswrap/syswrap-ppc64-aix5.c
coregrind/pub_core_scheduler.h

index 658025f8af48bb42229132178ad89ec3fb002840..5f1732e3432dc159f391b9546edf0133643e4638 100644 (file)
 #ifndef __PRIV_SEMA_H
 #define __PRIV_SEMA_H
 
-/* Not really a semaphore, but use a pipe for a token-passing scheme */
 /* Not really a semaphore, but use a pipe for a token-passing scheme */
 typedef struct {
    Int pipe[2];
-   Int owner_thread;           /* who currently has it */
+   Int owner_lwpid;            /* who currently has it */
 } vg_sema_t;
 
 // Nb: this may be OS-specific, but let's not factor it out until we
index 98a7e15b41f0eee80ea27c7ab54781bf48668ce8..e439e4994b10d875870dbdcf69a59f64c18e44f4 100644 (file)
    There are no extra threads.
 
    The main difference is that Valgrind only allows one client thread
-   to run at once.  This is controlled with the VCPU semaphore,
-   "run_sema".  Any time a thread wants to run client code or
+   to run at once.  This is controlled with the CPU Big Lock,
+   "the_BigLock".  Any time a thread wants to run client code or
    manipulate any shared state (which is anything other than its own
-   ThreadState entry), it must hold the run_sema.
+   ThreadState entry), it must hold the_BigLock.
 
    When a thread is about to block in a blocking syscall, it releases
-   run_sema, and re-takes it when it becomes runnable again (either
+   the_BigLock, and re-takes it when it becomes runnable again (either
    because the syscall finished, or we took a signal).
 
    VG_(scheduler) therefore runs in each thread.  It returns only when
@@ -135,7 +135,7 @@ void VG_(print_scheduler_stats)(void)
 }
 
 /* CPU semaphore, so that threads can run exclusively */
-static vg_sema_t run_sema;
+static vg_sema_t the_BigLock;
 
 
 /* ---------------------------------------------------------------------
@@ -189,14 +189,14 @@ ThreadId VG_(alloc_ThreadState) ( void )
 }
 
 /* 
-   Mark a thread as Runnable.  This will block until the run_sema is
+   Mark a thread as Runnable.  This will block until the_BigLock is
    available, so that we get exclusive access to all the shared
-   structures and the CPU.  Up until we get the sema, we must not
+   structures and the CPU.  Up until we get the_BigLock, we must not
    touch any shared state.
 
    When this returns, we'll actually be running.
  */
-void VG_(set_running)(ThreadId tid, HChar* who)
+void VG_(acquire_BigLock)(ThreadId tid, HChar* who)
 {
    ThreadState *tst;
 
@@ -209,10 +209,10 @@ void VG_(set_running)(ThreadId tid, HChar* who)
    }
 #endif
 
-   /* First, acquire the lock.  We can't do anything else safely prior
-      to this point.  Even doing debug printing prior to this point
-      is, technically, wrong. */
-   ML_(sema_down)(&run_sema);
+   /* First, acquire the_BigLock.  We can't do anything else safely
+      prior to this point.  Even doing debug printing prior to this
+      point is, technically, wrong. */
+   ML_(sema_down)(&the_BigLock);
 
    tst = VG_(get_ThreadState)(tid);
 
@@ -246,7 +246,7 @@ void VG_(set_running)(ThreadId tid, HChar* who)
    but it may mean that we remain in a Runnable state and we're just
    yielding the CPU to another thread).
  */
-void VG_(set_sleeping)(ThreadId tid, ThreadStatus sleepstate, HChar* who)
+void VG_(release_BigLock)(ThreadId tid, ThreadStatus sleepstate, HChar* who)
 {
    ThreadState *tst = VG_(get_ThreadState)(tid);
 
@@ -268,9 +268,9 @@ void VG_(set_sleeping)(ThreadId tid, ThreadStatus sleepstate, HChar* who)
       print_sched_event(tid, buf);
    }
 
-   /* Release the run_sema; this will reschedule any runnable
+   /* Release the_BigLock; this will reschedule any runnable
       thread. */
-   ML_(sema_up)(&run_sema);
+   ML_(sema_up)(&the_BigLock);
 }
 
 /* Clear out the ThreadState and release the semaphore. Leaves the
@@ -291,7 +291,7 @@ void VG_(exit_thread)(ThreadId tid)
    if (VG_(clo_trace_sched))
       print_sched_event(tid, "release lock in VG_(exit_thread)");
 
-   ML_(sema_up)(&run_sema);
+   ML_(sema_up)(&the_BigLock);
 }
 
 /* If 'tid' is blocked in a syscall, send it SIGVGKILL so as to get it
@@ -321,14 +321,14 @@ void VG_(vg_yield)(void)
    vg_assert(tid != VG_INVALID_THREADID);
    vg_assert(VG_(threads)[tid].os_state.lwpid == VG_(gettid)());
 
-   VG_(set_sleeping)(tid, VgTs_Yielding, "VG_(vg_yield)");
+   VG_(release_BigLock)(tid, VgTs_Yielding, "VG_(vg_yield)");
 
    /* 
       Tell the kernel we're yielding.
     */
    VG_(do_syscall0)(__NR_sched_yield);
 
-   VG_(set_running)(tid, "VG_(vg_yield)");
+   VG_(acquire_BigLock)(tid, "VG_(vg_yield)");
 }
 
 
@@ -413,9 +413,9 @@ void mostly_clear_thread_record ( ThreadId tid )
    would be too hard to try to re-number the thread and relocate the           
    thread state down to VG_(threads)[1].                                       
                                                                                
-   This function also needs to reinitialize the run_sema, since                
-   otherwise we may end up sharing its state with the parent, which            
-   would be deeply confusing.                                                  
+   This function also needs to reinitialize the_BigLock, since
+   otherwise we may end up sharing its state with the parent, which
+   would be deeply confusing.
 */                                          
 static void sched_fork_cleanup(ThreadId me)
 {
@@ -435,9 +435,9 @@ static void sched_fork_cleanup(ThreadId me)
    }
 
    /* re-init and take the sema */
-   ML_(sema_deinit)(&run_sema);
-   ML_(sema_init)(&run_sema);
-   ML_(sema_down)(&run_sema);
+   ML_(sema_deinit)(&the_BigLock);
+   ML_(sema_init)(&the_BigLock);
+   ML_(sema_down)(&the_BigLock);
 }
 
 
@@ -457,7 +457,7 @@ void VG_(scheduler_init) ( Addr clstack_end, SizeT clstack_size )
    vg_assert(VG_IS_PAGE_ALIGNED(clstack_end+1));
    vg_assert(VG_IS_PAGE_ALIGNED(clstack_size));
 
-   ML_(sema_init)(&run_sema);
+   ML_(sema_init)(&the_BigLock);
 
    for (i = 0 /* NB; not 1 */; i < VG_N_THREADS; i++) {
       /* Paranoia .. completely zero it out. */
@@ -813,7 +813,7 @@ static UInt/*trc*/ handle_noredir_jump ( ThreadId tid )
 /* 
    Run a thread until it wants to exit.
    
-   We assume that the caller has already called VG_(set_running) for
+   We assume that the caller has already called VG_(acquire_BigLock) for
    us, so we own the VCPU.  Also, all signals are blocked.
  */
 VgSchedReturnCode VG_(scheduler) ( ThreadId tid )
@@ -860,8 +860,8 @@ VgSchedReturnCode VG_(scheduler) ( ThreadId tid )
         /* 3 Aug 06: doing sys__nsleep works but crashes some apps.
             sys_yield also helps the problem, whilst not crashing apps. */
 
-        VG_(set_sleeping)(tid, VgTs_Yielding, 
-                                "VG_(scheduler):timeslice");
+        VG_(release_BigLock)(tid, VgTs_Yielding, 
+                                   "VG_(scheduler):timeslice");
         /* ------------ now we don't have The Lock ------------ */
 
 #        if defined(VGP_ppc32_aix5) || defined(VGP_ppc64_aix5)
@@ -878,7 +878,7 @@ VgSchedReturnCode VG_(scheduler) ( ThreadId tid )
          }
 #        endif
 
-        VG_(set_running)(tid, "VG_(scheduler):timeslice");
+        VG_(acquire_BigLock)(tid, "VG_(scheduler):timeslice");
         /* ------------ now we do have The Lock ------------ */
 
         /* OK, do some relatively expensive housekeeping stuff */
@@ -1387,7 +1387,7 @@ void scheduler_sanity ( ThreadId tid )
    if (!VG_(is_running_thread)(tid)) {
       VG_(message)(Vg_DebugMsg,
                   "Thread %d is supposed to be running, "
-                   "but doesn't own run_sema (owned by %d)\n", 
+                   "but doesn't own the_BigLock (owned by %d)\n", 
                   tid, VG_(running_tid));
       bad = True;
    }
@@ -1399,9 +1399,9 @@ void scheduler_sanity ( ThreadId tid )
       bad = True;
    }
 
-   if (lwpid != run_sema.owner_thread) {
+   if (lwpid != the_BigLock.owner_lwpid) {
       VG_(message)(Vg_DebugMsg,
-                   "Thread %d doesn't own the run_sema\n",
+                   "Thread (LWPID) %d doesn't own the_BigLock\n",
                    tid);
       bad = True;
    }
index b175fa320699f616d32a1c4dbbbcd4f647d22248..459d2f07546e9a966231c5c9432d2ff0ed919976 100644 (file)
@@ -65,7 +65,7 @@ void ML_(sema_init)(vg_sema_t *sema)
                                                  sema->pipe[1]);
    vg_assert(sema->pipe[0] != sema->pipe[1]);
 
-   sema->owner_thread = -1;
+   sema->owner_lwpid = -1;
 
    /* create initial token */
    sema_char = 'A';
@@ -78,12 +78,12 @@ void ML_(sema_init)(vg_sema_t *sema)
 
 void ML_(sema_deinit)(vg_sema_t *sema)
 {
-   vg_assert(sema->owner_thread != -1); /* must be initialised */
+   vg_assert(sema->owner_lwpid != -1); /* must be initialised */
    vg_assert(sema->pipe[0] != sema->pipe[1]);
    VG_(close)(sema->pipe[0]);
    VG_(close)(sema->pipe[1]);
    sema->pipe[0] = sema->pipe[1] = -1;
-   sema->owner_thread = -1;
+   sema->owner_lwpid = -1;
 }
 
 /* get a token */
@@ -93,7 +93,7 @@ void ML_(sema_down)(vg_sema_t *sema)
    Int ret;
    Int lwpid = VG_(gettid)();
 
-   vg_assert(sema->owner_thread != lwpid); /* can't have it already */
+   vg_assert(sema->owner_lwpid != lwpid); /* can't have it already */
    vg_assert(sema->pipe[0] != sema->pipe[1]);
 
   again:
@@ -113,7 +113,7 @@ void ML_(sema_down)(vg_sema_t *sema)
 
    if (sema_char == 'Z') sema_char = 'A'; else sema_char++;
 
-   sema->owner_thread = lwpid;
+   sema->owner_lwpid = lwpid;
 }
 
 /* put token back */
@@ -123,11 +123,11 @@ void ML_(sema_up)(vg_sema_t *sema)
    Char buf[2];
    buf[0] = sema_char; 
    buf[1] = 0;
-   vg_assert(sema->owner_thread != -1); /* must be initialised */
+   vg_assert(sema->owner_lwpid != -1); /* must be initialised */
    vg_assert(sema->pipe[0] != sema->pipe[1]);
-   vg_assert(sema->owner_thread == VG_(gettid)()); /* must have it */
+   vg_assert(sema->owner_lwpid == VG_(gettid)()); /* must have it */
 
-   sema->owner_thread = 0;
+   sema->owner_lwpid = 0;
 
    ret = VG_(write)(sema->pipe[1], buf, 1);
 
index d46744ecf67ab5ec77d14093fe75e6dcf0ae56b2..63a85ffa7095f11416412096faa0cf844a753f65 100644 (file)
@@ -1589,7 +1589,7 @@ void async_signalhandler ( Int sigNo, vki_siginfo_t *info, struct vki_ucontext *
    vg_assert(tst->status == VgTs_WaitSys);
 
    /* The thread isn't currently running, make it so before going on */
-   VG_(set_running)(tid, "async_signalhandler");
+   VG_(acquire_BigLock)(tid, "async_signalhandler");
 
    /* Update thread state properly */
    VG_(fixup_guest_state_after_syscall_interrupted)(
@@ -1915,7 +1915,7 @@ static void sigvgkill_handler(int signo, vki_siginfo_t *si, struct vki_ucontext
       VG_(message)(Vg_DebugMsg, 
                    "sigvgkill for lwp %d tid %d", VG_(gettid)(), tid);
 
-   VG_(set_running)(tid, "sigvgkill_handler");
+   VG_(acquire_BigLock)(tid, "sigvgkill_handler");
 
    vg_assert(signo == VG_SIGVGKILL);
    vg_assert(si->si_signo == signo);
index f4d8504b594a35c8f041f68d5b3e0fddd8f5648e..a9c6c200e3242da915ef8d4fe4396bec2cd3f2bd 100644 (file)
@@ -71,7 +71,7 @@ static VgSchedReturnCode thread_wrapper(Word /*ThreadId*/ tidW)
    vg_assert(tst->status == VgTs_Init);
 
    /* make sure we get the CPU lock before doing anything significant */
-   VG_(set_running)(tid, "thread_wrapper(starting new thread)");
+   VG_(acquire_BigLock)(tid, "thread_wrapper(starting new thread)");
 
    if (0)
       VG_(printf)("thread tid %d started: stack = %p\n",
index e259f2644b1c65e97c5432f54687f6ad2c599a87..1a4f7b7a4fa456afe9dca9b78e33c04d9307cc6c 100644 (file)
@@ -38,7 +38,7 @@
 #include "pub_core_libcprint.h"
 #include "pub_core_libcproc.h"      // For VG_(getpid)()
 #include "pub_core_libcsignal.h"
-#include "pub_core_scheduler.h"     // For VG_(set_sleeping), VG_(set_running),
+#include "pub_core_scheduler.h"     // For VG_({acquire,release}_BigLock),
                                     //   and VG_(vg_yield)
 #include "pub_core_stacktrace.h"    // For VG_(get_and_pp_StackTrace)()
 #include "pub_core_tooliface.h"
@@ -915,7 +915,7 @@ void VG_(client_syscall) ( ThreadId tid )
          putSyscallArgsIntoGuestState( &sci->args, &tst->arch.vex );
 
          /* Drop the lock */
-         VG_(set_sleeping)(tid, VgTs_WaitSys, "VG_(client_syscall)[async]");
+         VG_(release_BigLock)(tid, VgTs_WaitSys, "VG_(client_syscall)[async]");
 
          /* Do the call, which operates directly on the guest state,
             not on our abstracted copies of the args/result. */
@@ -930,7 +930,7 @@ void VG_(client_syscall) ( ThreadId tid )
             to the scheduler.  */
 
          /* Reacquire the lock */
-         VG_(set_running)(tid, "VG_(client_syscall)[async]");
+         VG_(acquire_BigLock)(tid, "VG_(client_syscall)[async]");
 
          /* Even more impedance matching.  Extract the syscall status
             from the guest state. */
index c3f9b8947640c4390344a72727ff7ab341dfdd48..6e2c202efe8ab6a6bb0a709f58142a8e4762448f 100644 (file)
@@ -94,7 +94,7 @@ static VgSchedReturnCode thread_wrapper(Word /*ThreadId*/ tidW)
    vg_assert(tst->status == VgTs_Init);
 
    /* make sure we get the CPU lock before doing anything significant */
-   VG_(set_running)(tid, "thread_wrapper(starting new thread)");
+   VG_(acquire_BigLock)(tid, "thread_wrapper(starting new thread)");
 
    if (0)
       VG_(printf)("thread tid %d started: stack = %p\n",
index 9c95d46a678eb84fc8ba0f9321eaa6524c2c5bd6..74bb11c9c04c69f7cf108921557548b139e9ebe7 100644 (file)
@@ -94,7 +94,7 @@ static VgSchedReturnCode thread_wrapper(Word /*ThreadId*/ tidW)
    vg_assert(tst->status == VgTs_Init);
 
    /* make sure we get the CPU lock before doing anything significant */
-   VG_(set_running)(tid, "thread_wrapper(starting new thread)");
+   VG_(acquire_BigLock)(tid, "thread_wrapper(starting new thread)");
 
    if (0)
       VG_(printf)("thread tid %d started: stack = %p\n",
index 7e71513b90c4243a98c49e3ad1785c268c2e4c82..8e8df63133f299a2f3cddfc26ef72dcf62521af7 100644 (file)
@@ -57,7 +57,7 @@ extern void VG_(nuke_all_threads_except) ( ThreadId me,
    thread state to VgTs_Runnable, and the thread will attempt to take
    the CPU lock.  By the time it returns, tid will be the running
    thread. */
-extern void VG_(set_running) ( ThreadId tid, HChar* who );
+extern void VG_(acquire_BigLock) ( ThreadId tid, HChar* who );
 
 /* Set a thread into a sleeping state.  Before the call, the thread
    must be runnable, and holding the CPU lock.  When this call
@@ -67,7 +67,7 @@ extern void VG_(set_running) ( ThreadId tid, HChar* who );
    caller must be careful not to touch any shared state.  It is also
    the caller's responsibility to actually block until the thread is
    ready to run again. */
-extern void VG_(set_sleeping) ( ThreadId tid, ThreadStatus state, HChar* who );
+extern void VG_(release_BigLock) ( ThreadId tid, ThreadStatus state, HChar* who );
 
 /* Yield the CPU for a while */
 extern void VG_(vg_yield)(void);