~ubuntu-branches/ubuntu/precise/evolution-data-server/precise

« back to all changes in this revision

Viewing changes to libedataserver/e-operation-pool.c

  • Committer: Bazaar Package Importer
  • Author(s): Mathieu Trudel-Lapierre, Ken VanDine, Mathieu Trudel-Lapierre
  • Date: 2011-06-23 17:40:41 UTC
  • mfrom: (1.1.88 upstream)
  • Revision ID: james.westby@ubuntu.com-20110623174041-4wd9jvs07wfinyet
Tags: 3.1.2-0ubuntu1
* New upstream version
  - bgo 589495 - Search folder by Size (KB) counts bytes, not KB (LP: #385859)
  - bgo 649757 - Filtering on a source account always succeeded (LP: #781391)
  - bgo 418954 - Add a separate entry combo for port numbers (LP: #160304)

[ Ken VanDine ]
* debian/libebook1.2-dev.install
  - Include EBook-1.2.gir
* debian/control
  - Added gir1.2-ebook-1.2 binary

[ Mathieu Trudel-Lapierre ]
* debian/control: drop libegroupwise1.2-13, libegroupwise-dev, they are now
  an independent module.
* debian/libegroupwise1.2-13.install,
  debian/libegroupwise1.2-dev.install,
  debian/lintian/libegroupwise1.2-13: dropped, see above.
* debian/control, debian/libe*.install, debian/lintian/libe*: rename and
  update files where needed to follow upstream soname changes.
* debian/control: bump evolution-data-server's Depends to libcamel-1.2-26.
* debian/rules: update to use makeshlibs with the new libcamel soname.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * e-operation-pool.c
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU Lesser General Public
 
6
 * License as published by the Free Software Foundation; either
 
7
 * version 2 of the License, or (at your option) version 3.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
 * Lesser General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU Lesser General Public
 
15
 * License along with the program; if not, see <http://www.gnu.org/licenses/>
 
16
 *
 
17
 *
 
18
 * Copyright (C) 2011 Novell, Inc. (www.novell.com)
 
19
 *
 
20
 */
 
21
 
 
22
#include "e-operation-pool.h"
 
23
 
 
24
struct _EOperationPool {
 
25
        GThreadPool *pool;
 
26
 
 
27
        GMutex *ops_lock;
 
28
        GHashTable *ops;
 
29
        guint32 last_opid;
 
30
};
 
31
 
 
32
EOperationPool *
 
33
e_operation_pool_new (guint max_threads, GFunc thread_func, gpointer user_data)
 
34
{
 
35
        EOperationPool *pool;
 
36
        GThreadPool *thread_pool;
 
37
        GError *error = NULL;
 
38
 
 
39
        g_return_val_if_fail (thread_func != NULL, NULL);
 
40
 
 
41
        thread_pool = g_thread_pool_new (thread_func, user_data, max_threads, FALSE, &error);
 
42
        if (error) {
 
43
                g_warning ("%s: Failed to create thread pool: %s", G_STRFUNC, error->message);
 
44
                g_error_free (error);
 
45
                return NULL;
 
46
        }
 
47
 
 
48
        pool = g_new0 (EOperationPool, 1);
 
49
        pool->pool = thread_pool;
 
50
        pool->ops_lock = g_mutex_new ();
 
51
        pool->ops = g_hash_table_new (g_direct_hash, g_direct_equal);
 
52
        pool->last_opid = 0;
 
53
 
 
54
        /* Kill threads which don't do anything for 10 seconds */
 
55
        g_thread_pool_set_max_idle_time (10 * 1000);
 
56
 
 
57
        return pool;
 
58
}
 
59
 
 
60
void
 
61
e_operation_pool_free (EOperationPool *pool)
 
62
{
 
63
        g_return_if_fail (pool != NULL);
 
64
 
 
65
        g_thread_pool_free (pool->pool, FALSE, FALSE);
 
66
        g_mutex_free (pool->ops_lock);
 
67
        g_hash_table_destroy (pool->ops);
 
68
        g_free (pool);
 
69
}
 
70
 
 
71
/* Reserves new operation ID, which is returned. This operation ID may
 
72
   be released by e_operation_pool_release_opid () when the operation
 
73
   is finished.
 
74
*/
 
75
guint32
 
76
e_operation_pool_reserve_opid (EOperationPool *pool)
 
77
{
 
78
        guint32 opid;
 
79
 
 
80
        g_return_val_if_fail (pool != NULL, 0);
 
81
        g_return_val_if_fail (pool->ops != NULL, 0);
 
82
        g_return_val_if_fail (pool->ops_lock != NULL, 0);
 
83
 
 
84
        g_mutex_lock (pool->ops_lock);
 
85
 
 
86
        pool->last_opid++;
 
87
        if (!pool->last_opid)
 
88
                pool->last_opid = 1;
 
89
 
 
90
        while (pool->last_opid && g_hash_table_lookup (pool->ops, GUINT_TO_POINTER (pool->last_opid)))
 
91
                pool->last_opid++;
 
92
 
 
93
        opid = pool->last_opid;
 
94
        if (opid)
 
95
                g_hash_table_insert (pool->ops, GUINT_TO_POINTER (opid), GUINT_TO_POINTER (1));
 
96
 
 
97
        g_mutex_unlock (pool->ops_lock);
 
98
 
 
99
        g_return_val_if_fail (opid != 0, 0);
 
100
 
 
101
        return opid;
 
102
}
 
103
 
 
104
/* Releases operation ID previously reserved by e_operation_pool_reserve_opid(). */
 
105
void
 
106
e_operation_pool_release_opid (EOperationPool *pool, guint32 opid)
 
107
{
 
108
        g_return_if_fail (pool != NULL);
 
109
        g_return_if_fail (pool->ops != NULL);
 
110
        g_return_if_fail (pool->ops_lock != NULL);
 
111
 
 
112
        g_mutex_lock (pool->ops_lock);
 
113
        g_hash_table_remove (pool->ops, GUINT_TO_POINTER (opid));
 
114
        g_mutex_unlock (pool->ops_lock);
 
115
}
 
116
 
 
117
/* Pushes operation to be processed. 'opdata' is passed to the function
 
118
   provided in e_operation_pool_new ().
 
119
*/
 
120
void
 
121
e_operation_pool_push (EOperationPool *pool, gpointer opdata)
 
122
{
 
123
        GError *error = NULL;
 
124
 
 
125
        g_return_if_fail (pool != NULL);
 
126
        g_return_if_fail (pool->pool != NULL);
 
127
 
 
128
        g_thread_pool_push (pool->pool, opdata, &error);
 
129
 
 
130
        if (error) {
 
131
                g_warning ("%s: Failed to push to thread pool: %s", G_STRFUNC, error->message);
 
132
                g_error_free (error);
 
133
        }
 
134
}