2 * Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 FILE_LICENCE ( GPL2_OR_LATER );
24 #include <ipxe/monojob.h>
25 #include <ipxe/pending.h>
30 * Wait for pending operations to complete
38 * @v progress Progress report to fill in
39 * @ret ongoing_rc Ongoing job status code (if known)
41 static int sync_progress ( struct interface *intf,
42 struct job_progress *progress __unused ) {
44 /* Terminate successfully if no pending operations remain */
45 if ( ! have_pending() )
46 intf_close ( intf, 0 );
51 /** Synchroniser interface operations */
52 static struct interface_operation sync_intf_op[] = {
53 INTF_OP ( job_progress, struct interface *, sync_progress ),
56 /** Synchroniser interface descriptor */
57 static struct interface_descriptor sync_intf_desc =
58 INTF_DESC_PURE ( sync_intf_op );
61 static struct interface sync_intf = INTF_INIT ( sync_intf_desc );
64 * Wait for pending operations to complete
66 * @v timeout Timeout period, in ticks (0=indefinite)
67 * @ret rc Return status code
69 int sync ( unsigned long timeout ) {
71 /* Attach synchroniser and wait for completion */
72 intf_plug_plug ( &monojob, &sync_intf );
73 return monojob_wait ( NULL, timeout );