After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 415891 - Use EFlag to simplify logic in evolution-data-server
Use EFlag to simplify logic in evolution-data-server
Status: RESOLVED FIXED
Product: evolution-data-server
Classification: Platform
Component: general
1.10.x (obsolete)
Other Linux
: Normal enhancement
: ---
Assigned To: Evolution Shell Maintainers Team
Evolution QA team
Depends on:
Blocks: 376991 426816
 
 
Reported: 2007-03-08 00:27 UTC by Matthew Barnes
Modified: 2013-09-14 16:49 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Proposed patch (8.63 KB, patch)
2007-03-08 00:28 UTC, Matthew Barnes
committed Details | Review
EFlag usage examples (47.99 KB, patch)
2007-03-09 05:34 UTC, Matthew Barnes
none Details | Review
EFlag usage examples (47.98 KB, patch)
2007-08-02 17:34 UTC, Matthew Barnes
committed Details | Review

Description Matthew Barnes 2007-03-08 00:27:32 UTC
I'd like to propose a small addition to libedataserver called EFlag.

EFlag is a very simple thread synchronization mechanism.  It implements a thread-safe flag that can be blocked on.  Internally it just wraps a GMutex, a GCond, and a gboolean.  An EFlag is essentially a binary semaphore with a more intuitive interface.  It's based on Python's threading.Event class [1].

I find myself implementing this little pattern quite frequently when doing concurrent programming, so I thought it would be nice to formalize an API around it.  I'd like to utilize it in some refactoring work that I have planned for Evolution 2.11/2.12.

Here's the API.  See the patch for documentation.

    EFlag *   e_flag_new        (void);
    gboolean  e_flag_is_set     (EFlag *flag);
    void      e_flag_set        (EFlag *flag);
    void      e_flag_clear      (EFlag *flag);
    void      e_flag_wait       (EFlag *flag);
    gboolean  e_flag_timed_wait (EFlag *flag, GTimeVal *abs_time);
    void      e_flag_free       (EFlag *flag);

One example where this is useful is synchronizing messages between threads:

    Sender
    ------
    msg = create_new_message ();
    ... populate message ...
    send_message (msg);
    e_flag_wait (msg->done);  /* wait for message to be processed */
    ... retrieve results ...
    free_message (msg);

    Receiver
    --------
    msg = get_incoming_message ();
    ... process message ...
    e_flag_set (msg->done);  /* notify sender */


[1] http://docs.python.org/lib/event-objects.html
Comment 1 Matthew Barnes 2007-03-08 00:28:23 UTC
Created attachment 84201 [details] [review]
Proposed patch
Comment 2 Matthew Barnes 2007-03-09 05:34:32 UTC
Created attachment 84293 [details] [review]
EFlag usage examples

Here's a few examples in existing evolution-data-server code where an EFlag can be used to simplify thread synchronization.
Comment 3 Matthew Barnes 2007-03-09 12:46:11 UTC
Recent refactoring of e-passwords.c also uses EFlag (see bug #376991).
Comment 4 Matthew Barnes 2007-03-30 20:08:55 UTC
Also using it in the mailer to replace EMsgPort (see bug #362638).
Comment 5 Matthew Barnes 2007-04-13 17:31:35 UTC
And in the printing clean up (see bug #426816).
Comment 6 Matthew Barnes 2007-04-16 15:04:34 UTC
Varadhan, Srini says I need to have you review this.  Would you please?
Comment 7 Matthew Barnes 2007-04-19 19:33:27 UTC
Committed the EFlag implementation to Subversion trunk (revision 7706).

Varadhan wanted to give the other patch (containing EFlag usage examples) some more scrutiny, so I'm leaving this bug open until that patch gets a thumbs up or thumbs down.
Comment 8 Philip Van Hoof 2007-05-13 11:48:10 UTC
FYI: I'm not yet patching Tinymail's camel-lite with this because I don't think I would be using it. I'd be okay if I would have to patch this in (or starting using it), though.
Comment 9 Matthew Barnes 2007-05-13 21:53:48 UTC
Camel shouldn't be using EFlag at all.  My plan is to have Evolution and E-D-S use EFlag wherever it currently uses EMsgPort, so that EMsgPort can be moved to Camel (if that makes sense).  Then that would be one less thing that Camel needs libedataserver for.
Comment 10 Philip Van Hoof 2007-05-14 20:16:31 UTC
That would make sense, indeed
Comment 11 Matthew Barnes 2007-05-24 19:26:20 UTC
Changing summary to describe the remaining patch for this bug.
Comment 12 Ross Burton 2007-08-02 14:58:16 UTC
I'm happy for the addressbook patches to be committed.
Comment 13 Matthew Barnes 2007-08-02 17:34:49 UTC
Created attachment 92934 [details] [review]
EFlag usage examples

Here's an updated patch for the current Subversion trunk.
Comment 14 Matthew Barnes 2007-08-10 15:26:39 UTC
Committing based on Ross' approval in comment #12.  Revision 7935.