Pārlūkot izejas kodu

[cmdline] Rewrite "sync" command to use monojob_wait()

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 11 gadus atpakaļ
vecāks
revīzija
92c56e129b
5 mainītis faili ar 103 papildinājumiem un 25 dzēšanām
  1. 1
    19
      src/core/pending.c
  2. 2
    2
      src/hci/commands/sync_cmd.c
  3. 12
    4
      src/include/ipxe/pending.h
  4. 14
    0
      src/include/usr/sync.h
  5. 74
    0
      src/usr/sync.c

+ 1
- 19
src/core/pending.c Parādīt failu

@@ -31,7 +31,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
31 31
  */
32 32
 
33 33
 /** Total count of pending operations */
34
-static int pending_total;
34
+int pending_total;
35 35
 
36 36
 /**
37 37
  * Mark an operation as pending
@@ -60,21 +60,3 @@ void pending_put ( struct pending_operation *pending ) {
60 60
 		       pending, pending->count, pending_total );
61 61
 	}
62 62
 }
63
-
64
-/**
65
- * Wait for pending operations to complete
66
- *
67
- * @v timeout		Timeout period, in ticks (0=indefinite)
68
- * @ret rc		Return status code
69
- */
70
-int pending_wait ( unsigned long timeout ) {
71
-	unsigned long start = currticks();
72
-
73
-	do {
74
-		if ( pending_total == 0 )
75
-			return 0;
76
-		step();
77
-	} while ( ( timeout == 0 ) || ( ( currticks() - start ) < timeout ) );
78
-
79
-	return -ETIMEDOUT;
80
-}

+ 2
- 2
src/hci/commands/sync_cmd.c Parādīt failu

@@ -24,7 +24,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
24 24
 #include <getopt.h>
25 25
 #include <ipxe/command.h>
26 26
 #include <ipxe/parseopt.h>
27
-#include <ipxe/pending.h>
27
+#include <usr/sync.h>
28 28
 
29 29
 /** @file
30 30
  *
@@ -65,7 +65,7 @@ static int sync_exec ( int argc, char **argv ) {
65 65
 		return rc;
66 66
 
67 67
 	/* Wait for pending operations to complete */
68
-	if ( ( rc = pending_wait ( opts.timeout ) ) != 0 ) {
68
+	if ( ( rc = sync ( opts.timeout ) ) != 0 ) {
69 69
 		printf ( "Operations did not complete: %s\n", strerror ( rc ) );
70 70
 		return rc;
71 71
 	}

+ 12
- 4
src/include/ipxe/pending.h Parādīt failu

@@ -9,8 +9,6 @@
9 9
 
10 10
 FILE_LICENCE ( GPL2_OR_LATER );
11 11
 
12
-#include <ipxe/list.h>
13
-
14 12
 /** A pending operation */
15 13
 struct pending_operation {
16 14
 	/** Pending count */
@@ -21,14 +19,24 @@ struct pending_operation {
21 19
  * Check if an operation is pending
22 20
  *
23 21
  * @v pending		Pending operation
24
- * @v is_pending	Operation is pending
22
+ * @ret is_pending	Operation is pending
25 23
  */
26 24
 static inline int is_pending ( struct pending_operation *pending ) {
27 25
 	return ( pending->count != 0 );
28 26
 }
29 27
 
28
+extern int pending_total;
29
+
30
+/**
31
+ * Check if any operations are pending
32
+ *
33
+ * @ret have_pending	Some operations are pending
34
+ */
35
+static inline int have_pending ( void ) {
36
+	return ( pending_total != 0 );
37
+}
38
+
30 39
 extern void pending_get ( struct pending_operation *pending );
31 40
 extern void pending_put ( struct pending_operation *pending );
32
-extern int pending_wait ( unsigned long timeout );
33 41
 
34 42
 #endif /* _IPXE_PENDING_H */

+ 14
- 0
src/include/usr/sync.h Parādīt failu

@@ -0,0 +1,14 @@
1
+#ifndef _USR_SYNC_H
2
+#define _USR_SYNC_H
3
+
4
+/** @file
5
+ *
6
+ * Wait for pending operations to complete
7
+ *
8
+ */
9
+
10
+FILE_LICENCE ( GPL2_OR_LATER );
11
+
12
+extern int sync ( unsigned long timeout );
13
+
14
+#endif /* _USR_SYNC_H */

+ 74
- 0
src/usr/sync.c Parādīt failu

@@ -0,0 +1,74 @@
1
+/*
2
+ * Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>.
3
+ *
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.
8
+ *
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.
13
+ *
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
17
+ * 02110-1301, USA.
18
+ */
19
+
20
+FILE_LICENCE ( GPL2_OR_LATER );
21
+
22
+#include <stddef.h>
23
+#include <ipxe/job.h>
24
+#include <ipxe/monojob.h>
25
+#include <ipxe/pending.h>
26
+#include <usr/sync.h>
27
+
28
+/** @file
29
+ *
30
+ * Wait for pending operations to complete
31
+ *
32
+ */
33
+
34
+/**
35
+ * Report progress
36
+ *
37
+ * @v intf		Interface
38
+ * @v progress		Progress report to fill in
39
+ * @ret ongoing_rc	Ongoing job status code (if known)
40
+ */
41
+static int sync_progress ( struct interface *intf,
42
+			   struct job_progress *progress __unused ) {
43
+
44
+	/* Terminate successfully if no pending operations remain */
45
+	if ( ! have_pending() )
46
+		intf_close ( intf, 0 );
47
+
48
+	return 0;
49
+}
50
+
51
+/** Synchroniser interface operations */
52
+static struct interface_operation sync_intf_op[] = {
53
+	INTF_OP ( job_progress, struct interface *, sync_progress ),
54
+};
55
+
56
+/** Synchroniser interface descriptor */
57
+static struct interface_descriptor sync_intf_desc =
58
+	INTF_DESC_PURE ( sync_intf_op );
59
+
60
+/** Synchroniser */
61
+static struct interface sync_intf = INTF_INIT ( sync_intf_desc );
62
+
63
+/**
64
+ * Wait for pending operations to complete
65
+ *
66
+ * @v timeout		Timeout period, in ticks (0=indefinite)
67
+ * @ret rc		Return status code
68
+ */
69
+int sync ( unsigned long timeout ) {
70
+
71
+	/* Attach synchroniser and wait for completion */
72
+	intf_plug_plug ( &monojob, &sync_intf );
73
+	return monojob_wait ( NULL, timeout );
74
+}

Notiek ielāde…
Atcelt
Saglabāt