~ubuntu-branches/debian/sid/f-spot/sid

« back to all changes in this revision

Viewing changes to lib/Hyena/src/Hyena/Hyena/ThreadAssist.cs

  • Committer: Bazaar Package Importer
  • Author(s): Iain Lane
  • Date: 2010-05-24 10:35:57 UTC
  • mfrom: (2.4.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20100524103557-1j0i8f66caybci2n
* New upstream release 0.7.0
 + First release of the unstable 0.7 development series. Massive changes.
 + Reparenting and detaching support (Anton Keks) (Closes: #559745)
 + A new Mallard-based documentation (Harold Schreckengost)
 + No longer embeds flickrnet, uses distribution copy (Iain Lane)
 + Adoption of a large amount of Hyena functionality (Paul Lange, Peter
   Goetz)
 + No longer embeds gnome-keyring-sharp
 + Completely rewritten import, much faster and less memory hungry (Ruben
   Vermeersch) (Closes: #559080, #492658, #341790, #357811, #426017) (LP:
   #412091)
 + No longer use gphoto2-sharp, now uses gvfs which is less crash-pron
   (Ruben Vermeersch)
 + Fix Facebook support (Ruben Vermeersch)
 + Modernized unit tests
 + Revamped build (Mike Gemünde)
 + Much improved duplicate detection (much faster too) (Ruben Vermeersch)
 + Mouse selection in Iconview (Vincent Pomey)
 + Image panning support using middle mouse button (Wojciech Dzierżanowski)
 + Timeline slider now restricted to the size of the window (Iain Churcher)
 + Over 100 bugs closed (http://bit.ly/cyVjnD)
   - No more warnings about schema defaults (Closes: #584215) (LP: #586132)
* debian/control: Clean up build deps to match configure checks
* debian/rules: Don't run dh_makeshilbs as we don't ship any shared
  libraries. There are some private ones though, which get picked up and
  result in a useless postinst/postrm call to ldconfig. Thanks, lintian.
* debian/patches/debian_fix-distclean.patch,
  debian/patches/debian_fix_f-spot.exe.config.patch,
  debian/patches/debian_link-system-flickrnet.patch,
  debian/patches/debian_link-system-gnome-keyring.patch,
  debian/patches/debian_disable-unit-tests,
  debian/patches/git_transition_duration.patch,
  debian/patches/ubuntu_fix_folder_export_hang.patch:
  Clean up obsolete patches which are no longer necessary 
* debian/patches/*: Temporarily disable patches which originated from Ubuntu
  and no longer apply cleanly. We will get these back in a future upstream
  development release.
* debian/patches/*: Refresh to apply cleanly 
* debian/rules: Add new include dir to autoreconf call to pick up f-spot
  macros 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// ThreadAssist.cs
 
3
//
 
4
// Author:
 
5
//   Aaron Bockover <abockover@novell.com>
 
6
//   Gabriel Burt <gburt@novell.com>
 
7
//
 
8
// Copyright (C) 2005-2009 Novell, Inc.
 
9
//
 
10
// Permission is hereby granted, free of charge, to any person obtaining
 
11
// a copy of this software and associated documentation files (the
 
12
// "Software"), to deal in the Software without restriction, including
 
13
// without limitation the rights to use, copy, modify, merge, publish,
 
14
// distribute, sublicense, and/or sell copies of the Software, and to
 
15
// permit persons to whom the Software is furnished to do so, subject to
 
16
// the following conditions:
 
17
//
 
18
// The above copyright notice and this permission notice shall be
 
19
// included in all copies or substantial portions of the Software.
 
20
//
 
21
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
22
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
23
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 
24
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 
25
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 
26
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 
27
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
28
//
 
29
 
 
30
using System;
 
31
using System.Threading;
 
32
 
 
33
namespace Hyena
 
34
{
 
35
    public static class ThreadAssist
 
36
    {
 
37
        private static Thread main_thread;
 
38
 
 
39
        public static Thread MainThread {
 
40
            get { return main_thread; }
 
41
        }
 
42
 
 
43
        public static Action<InvokeHandler> ProxyToMainHandler { get; set; }
 
44
 
 
45
        public static void InitializeMainThread ()
 
46
        {
 
47
            main_thread = Thread.CurrentThread;
 
48
            main_thread.Name = "Main Thread";
 
49
        }
 
50
 
 
51
        public static bool InMainThread {
 
52
            get {
 
53
                if (main_thread == null) {
 
54
                    throw new ApplicationException ("ThreadAssist.InitializeMainThread must be called first");
 
55
                }
 
56
 
 
57
                return main_thread.Equals (Thread.CurrentThread);
 
58
            }
 
59
        }
 
60
 
 
61
        public static void AssertNotInMainThread ()
 
62
        {
 
63
            if (ApplicationContext.Debugging && InMainThread) {
 
64
                Hyena.Log.Warning ("In GUI thread, will probably block it", System.Environment.StackTrace);
 
65
            }
 
66
        }
 
67
 
 
68
        public static void AssertInMainThread ()
 
69
        {
 
70
            if (ApplicationContext.Debugging && !InMainThread) {
 
71
                Hyena.Log.Warning ("Not in main thread!", System.Environment.StackTrace);
 
72
            }
 
73
        }
 
74
 
 
75
        public static void BlockingProxyToMain (InvokeHandler handler)
 
76
        {
 
77
            if (!InMainThread) {
 
78
                var reset_event = new System.Threading.ManualResetEvent (false);
 
79
 
 
80
                ProxyToMainHandler (delegate {
 
81
                    try {
 
82
                        handler ();
 
83
                    } finally {
 
84
                        reset_event.Set ();
 
85
                    }
 
86
                });
 
87
 
 
88
                reset_event.WaitOne ();
 
89
            } else {
 
90
                handler ();
 
91
            }
 
92
        }
 
93
 
 
94
        public static void ProxyToMain (InvokeHandler handler)
 
95
        {
 
96
            if (!InMainThread) {
 
97
                ProxyToMainHandler (handler);
 
98
            } else {
 
99
                handler ();
 
100
            }
 
101
        }
 
102
 
 
103
        public static void SpawnFromMain (ThreadStart threadedMethod)
 
104
        {
 
105
            if (InMainThread) {
 
106
                Spawn (threadedMethod, true);
 
107
            } else {
 
108
                threadedMethod ();
 
109
            }
 
110
        }
 
111
 
 
112
        public static Thread Spawn (ThreadStart threadedMethod, bool autoStart)
 
113
        {
 
114
            Thread thread = new Thread (threadedMethod);
 
115
            thread.Name = String.Format ("Spawned: {0}", threadedMethod);
 
116
            thread.IsBackground = true;
 
117
            if (autoStart) {
 
118
                thread.Start ();
 
119
            }
 
120
            return thread;
 
121
        }
 
122
 
 
123
        public static Thread Spawn (ThreadStart threadedMethod)
 
124
        {
 
125
            return Spawn (threadedMethod, true);
 
126
        }
 
127
    }
 
128
}