1 diff --git a/backends/opkg/pk-backend-opkg.c b/backends/opkg/pk-backend-opkg.c
2 index a7b5244..9e71b90 100644
3 --- a/backends/opkg/pk-backend-opkg.c
4 +++ b/backends/opkg/pk-backend-opkg.c
6 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
13 @@ -47,6 +48,22 @@ typedef struct {
17 +static int __opkg_lock__ = 0;
18 +static inline void opkg_thread_lock()
20 + while ( __opkg_lock__ )
25 +static inline void opkg_thread_unlock()
27 + if (! __opkg_lock__ ) {
28 + pk_debug("Warning: opkg_thread_unlock without lock before!!\n");
34 opkg_unknown_error (PkBackend *backend, gint error_code, gchar *failed_cmd)
36 @@ -236,6 +253,7 @@ backend_refresh_cache_thread (PkBackend *backend)
37 opkg_unknown_error (backend, ret, "Refreshing cache");
39 pk_backend_finished (backend);
40 + opkg_thread_unlock();
44 @@ -246,6 +264,7 @@ backend_refresh_cache_thread (PkBackend *backend)
46 backend_refresh_cache (PkBackend *backend, gboolean force)
49 pk_backend_set_status (backend, PK_STATUS_ENUM_REFRESH_CACHE);
50 pk_backend_set_percentage (backend, PK_BACKEND_PERCENTAGE_INVALID);
52 @@ -260,15 +279,26 @@ backend_refresh_cache (PkBackend *backend, gboolean force)
54 pk_opkg_package_list_cb (opkg_t *opkg, opkg_package_t *pkg, void *data)
56 - SearchParams *params = (SearchParams*) data;
57 + SearchParams *params;
61 - PkFilterEnum filters = params->filters;
62 + PkFilterEnum filters;
65 + pk_debug("opkg is NULL!!\n");
69 + pk_debug("data is NULL!!\n");
75 + params = (SearchParams*) data;
76 + filters = params->filters;
78 switch (params->search_type)
81 @@ -336,6 +366,7 @@ backend_search_thread (PkBackend *backend)
82 opkg_list_packages (opkg, pk_opkg_package_list_cb, params);
84 pk_backend_finished (params->backend);
85 + opkg_thread_unlock();
87 g_free (params->needle);
89 @@ -348,6 +379,7 @@ backend_search_name (PkBackend *backend, PkFilterEnum filters, const gchar *sear
95 pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
96 pk_backend_set_percentage (backend, PK_BACKEND_PERCENTAGE_INVALID);
97 @@ -370,6 +402,7 @@ backend_search_description (PkBackend *backend, PkFilterEnum filters, const gcha
101 + opkg_thread_lock();
103 pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
104 pk_backend_set_percentage (backend, PK_BACKEND_PERCENTAGE_INVALID);
105 @@ -389,6 +422,7 @@ backend_search_group (PkBackend *backend, PkFilterEnum filters, const gchar *sea
107 SearchParams *params;
109 + opkg_thread_lock();
111 pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
112 pk_backend_set_percentage (backend, PK_BACKEND_PERCENTAGE_INVALID);
113 @@ -431,12 +465,15 @@ backend_install_packages_thread (PkBackend *backend)
116 pk_backend_finished (backend);
117 + opkg_thread_unlock();
122 backend_install_packages (PkBackend *backend, gchar **package_ids)
124 + opkg_thread_lock();
126 pk_backend_set_percentage (backend, PK_BACKEND_PERCENTAGE_INVALID);
127 pk_backend_set_status (backend, PK_STATUS_ENUM_INSTALL);
129 @@ -493,6 +530,7 @@ backend_remove_packages_thread (PkBackend *backend)
132 pk_backend_finished (backend);
133 + opkg_thread_unlock();
137 @@ -500,6 +538,8 @@ static void
138 backend_remove_packages (PkBackend *backend, gchar **package_ids, gboolean allow_deps, gboolean autoremove)
142 + opkg_thread_lock();
144 pk_backend_set_status (backend, PK_STATUS_ENUM_REMOVE);
145 pk_backend_set_percentage (backend, PK_BACKEND_PERCENTAGE_INVALID);
146 @@ -540,12 +580,15 @@ backend_update_system_thread (PkBackend *backend)
147 opkg_unknown_error (backend, err, "Upgrading system");
149 pk_backend_finished (backend);
150 + opkg_thread_unlock();
155 backend_update_system (PkBackend *backend)
157 + opkg_thread_lock();
159 pk_backend_set_status (backend, PK_STATUS_ENUM_UPDATE);
160 pk_backend_set_percentage (backend, PK_BACKEND_PERCENTAGE_INVALID);
162 @@ -571,6 +614,7 @@ backend_update_package_thread (PkBackend *backend)
163 "Package not found");
164 pk_package_id_free (pi);
165 pk_backend_finished (backend);
166 + opkg_thread_unlock();
170 @@ -581,6 +625,7 @@ backend_update_package_thread (PkBackend *backend)
172 pk_package_id_free (pi);
173 pk_backend_finished (backend);
174 + opkg_thread_unlock();
178 @@ -589,10 +634,12 @@ backend_update_packages (PkBackend *backend, gchar **package_ids)
182 - pk_backend_set_status (backend, PK_STATUS_ENUM_UPDATE);
183 - pk_backend_set_percentage (backend, PK_BACKEND_PERCENTAGE_INVALID);
185 for (i = 0; package_ids[i]; i++) {
187 + opkg_thread_lock();
189 + pk_backend_set_status (backend, PK_STATUS_ENUM_UPDATE);
190 + pk_backend_set_percentage (backend, PK_BACKEND_PERCENTAGE_INVALID);
191 pk_backend_set_string (backend, "pkgid", package_ids[i]);
192 pk_backend_thread_create (backend, backend_update_package_thread);
194 @@ -626,12 +673,14 @@ backend_get_updates_thread (PkBackend *backend)
196 opkg_list_upgradable_packages (opkg, pk_opkg_list_upgradable_cb, backend);
197 pk_backend_finished (backend);
198 + opkg_thread_unlock();
203 backend_get_updates (PkBackend *backend, PkFilterEnum filters)
205 + opkg_thread_lock();
206 pk_backend_set_status (backend, PK_STATUS_ENUM_UPDATE);
207 pk_backend_set_percentage (backend, PK_BACKEND_PERCENTAGE_INVALID);
209 @@ -672,6 +721,7 @@ backend_get_details_thread (PkBackend *backend)
211 pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_ID_INVALID, "invalid package id");
212 pk_backend_finished (backend);
213 + opkg_thread_unlock();
217 @@ -683,6 +733,7 @@ backend_get_details_thread (PkBackend *backend)
219 pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_NOT_FOUND, NULL);
220 pk_backend_finished (backend);
221 + opkg_thread_unlock();
225 @@ -698,15 +749,18 @@ backend_get_details_thread (PkBackend *backend)
228 pk_backend_details (backend, newid, NULL, group, pkg->description, pkg->url, pkg->size);
229 + pk_backend_finished (backend);
230 + opkg_thread_unlock();
233 opkg_package_free(pkg);
234 - pk_backend_finished (backend);
239 backend_get_details (PkBackend *backend, const gchar *package_id)
241 + opkg_thread_lock();
242 pk_backend_set_percentage (backend, PK_BACKEND_PERCENTAGE_INVALID);
243 pk_backend_thread_create (backend, backend_get_details_thread);