1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
5 * Bertrand Guiheneuf <bertrand@helixcode.com>
7 * Copyright 1999, 2000 Helix Code, Inc. (http://www.helixcode.com)
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of the
12 * License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
30 #include "camel-op-queue.h"
32 static GStaticMutex op_queue_mutex = G_STATIC_MUTEX_INIT;
37 * camel_op_queue_new: create a new operation queue
39 * Create a new operation queue.
41 * Return value: the newly allcated object
46 CamelOpQueue *op_queue;
48 op_queue = g_new (CamelOpQueue, 1);
49 op_queue->ops_tail = NULL;
50 op_queue->ops_head = NULL;
51 op_queue->service_available = TRUE;
58 camel_op_queue_free (CamelOpQueue *op_queue)
60 g_list_free (op_queue->ops_head);
65 * camel_op_queue_push_op: Add an operation to the queue
66 * @queue: queue object
67 * @op: operation to add
69 * Add an operation to an operation queue.
70 * The queue is a FIFO queue.
73 camel_op_queue_push_op (CamelOpQueue *queue, CamelOp *op)
76 g_static_mutex_lock (&op_queue_mutex);
77 if (!queue->ops_tail) {
78 queue->ops_head = g_list_prepend (NULL, op);
79 queue->ops_tail = queue->ops_head;
81 queue->ops_head = g_list_prepend (queue->ops_head, op);
82 g_static_mutex_unlock (&op_queue_mutex);
87 * camel_op_queue_pop_op: Pop the next operation pending in the queue
88 * @queue: queue object
90 * Pop the next operation pending in the queue.
95 camel_op_queue_pop_op (CamelOpQueue *queue)
102 g_static_mutex_lock (&op_queue_mutex);
103 op_list = queue->ops_tail;
104 if (!op_list) return NULL;
106 queue->ops_tail = queue->ops_tail->prev;
107 op = (CamelOp *)op_list->data;
108 g_static_mutex_unlock (&op_queue_mutex);
115 * camel_op_queue_run_next_op: run the next pending operation
116 * @queue: queue object
118 * Run the next pending operation in the queue.
120 * Return value: TRUE if an operation was launched FALSE if there was no operation pending in the queue.
123 camel_op_queue_run_next_op (CamelOpQueue *queue)
127 op = camel_op_queue_pop_op (queue);
128 if (!op) return FALSE;
134 * camel_op_queue_set_service_availability: set the service availability for an operation queue
135 * @queue: queue object
136 * @available: availability flag
138 * set the service availability
141 camel_op_queue_set_service_availability (CamelOpQueue *queue, gboolean available)
143 g_static_mutex_lock (&op_queue_mutex);
144 queue->service_available = available;
145 g_static_mutex_unlock (&op_queue_mutex);
149 * camel_op_queue_get_service_availability: determine if an operation queue service is available
150 * @queue: queue object
152 * Determine if the service associated to an operation queue is available.
154 * Return value: service availability.
157 camel_op_queue_get_service_availability (CamelOpQueue *queue)
161 g_static_mutex_lock (&op_queue_mutex);
162 available = queue->service_available;
163 g_static_mutex_unlock (&op_queue_mutex);