emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

baby step toward thread patch


From: Tom Tromey
Subject: baby step toward thread patch
Date: Wed, 05 Jan 2011 07:40:38 -0700
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux)

The concurrency branch hasn't been getting much action lately, largely
because of a combination of lack of time and the difficulty of keeping
it up-to-date with trunk.  I'd like to solve the latter problem by
putting some needed infrastructure directly on trunk.  Once all the
infrastructure bits are merged, development can focus on just the
threading bits.

In general these infrastructure changes don't involve any runtime cost.
However, they may make the code uglier.

I'm posting this to get an ok on this change before checking it in.  In
the absence of comments (after a decent interval) I will just go ahead
with it.

In elisp, a let binding will always be thread-local.  For this to work
properly, variables defined in C must be thread-aware somehow.  This
patch is a step toward one implementation of that.  In particular, it
moves most such globals into a structure and redefines the "plain" name
of the variable as a macro that references this structure.  Then on the
concurrency branch, we'll change the definitions of these macros to
introduce thread locality.

E.g., consider 'Vgc_cons_percentage'.  Right now it is defined in
alloc.c:

    static Lisp_Object Vgc_cons_percentage;

After this patch it will appear in a structure in globals.h:

    struct emacs_globals
    {
    [...]
      Lisp_Object Vgc_cons_percentage;
    [...]
    };

    extern struct emacs_globals globals;

    #define Vgc_cons_percentage \
        globals.Vgc_cons_percentage


In case you're curious, for threading we'll introduce an indirection:
each thread will have its own copy of this structure, and one pointer
per field.  The pointers will be redirected to either the global or
thread-local copy of the object depending on whether it is let-bound.
Then the macros will just dereference these pointers.

If you read the concurrency branch, you'll see that this approach is
different from what is implemented there.  The concurrency branch does
not work for the DEFVAR_INT and DEFVAR_BOOL cases, but this approach
will.


This patch has a couple of other minor tweaks in it: I had to rename a
few local variables that had the same name as one of the new macros, I
had to remove some (redundant) extern declarations, and in one case
("scroll_step") I had to rename a global to avoid a clash with a Gtk
header file.

These little changes I did by hand.  The major part of the patch was
written by a script, which I'm attaching.

I can commit the lesser changes separately, if anybody cares.


One last thing is that this patch doesn't handle buffer_defaults
properly yet.  That is not hard; I just think it should be an
independent change.


I did not write a ChangeLog entry for this yet.  I will update the .el
script to do this.

Tom

Attachment: txt8ge3g3O9U5.txt
Description: rewrite-globals.el

Attachment: emacs.diff.gz
Description: the patch


reply via email to

[Prev in Thread] Current Thread [Next in Thread]