iPXE
sync.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License as
00006  * published by the Free Software Foundation; either version 2 of the
00007  * License, or any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017  * 02110-1301, USA.
00018  *
00019  * You can also choose to distribute this program under the terms of
00020  * the Unmodified Binary Distribution Licence (as given in the file
00021  * COPYING.UBDL), provided that you have satisfied its requirements.
00022  */
00023 
00024 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00025 
00026 #include <stddef.h>
00027 #include <ipxe/job.h>
00028 #include <ipxe/monojob.h>
00029 #include <ipxe/pending.h>
00030 #include <usr/sync.h>
00031 
00032 /** @file
00033  *
00034  * Wait for pending operations to complete
00035  *
00036  */
00037 
00038 /**
00039  * Report progress
00040  *
00041  * @v intf              Interface
00042  * @v progress          Progress report to fill in
00043  * @ret ongoing_rc      Ongoing job status code (if known)
00044  */
00045 static int sync_progress ( struct interface *intf,
00046                            struct job_progress *progress __unused ) {
00047 
00048         /* Terminate successfully if no pending operations remain */
00049         if ( ! have_pending() )
00050                 intf_close ( intf, 0 );
00051 
00052         return 0;
00053 }
00054 
00055 /** Synchroniser interface operations */
00056 static struct interface_operation sync_intf_op[] = {
00057         INTF_OP ( job_progress, struct interface *, sync_progress ),
00058 };
00059 
00060 /** Synchroniser interface descriptor */
00061 static struct interface_descriptor sync_intf_desc =
00062         INTF_DESC_PURE ( sync_intf_op );
00063 
00064 /** Synchroniser */
00065 static struct interface sync_intf = INTF_INIT ( sync_intf_desc );
00066 
00067 /**
00068  * Wait for pending operations to complete
00069  *
00070  * @v timeout           Timeout period, in ticks (0=indefinite)
00071  * @ret rc              Return status code
00072  */
00073 int sync ( unsigned long timeout ) {
00074 
00075         /* Attach synchroniser and wait for completion */
00076         intf_plug_plug ( &monojob, &sync_intf );
00077         return monojob_wait ( NULL, timeout );
00078 }