Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
edc0dcb5
Commit
edc0dcb5
authored
Apr 29, 2017
by
Paul Sokolovsky
Browse files
extmod/moduselect: Refactor towards introduction of poll.ipoll().
This follows previous refactor made to unix/moduselect.
parent
b0828694
Changes
1
Hide whitespace changes
Inline
Side-by-side
extmod/moduselect.c
View file @
edc0dcb5
...
@@ -182,6 +182,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_select_select_obj, 3, 4, select_select);
...
@@ -182,6 +182,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_select_select_obj, 3, 4, select_select);
typedef
struct
_mp_obj_poll_t
{
typedef
struct
_mp_obj_poll_t
{
mp_obj_base_t
base
;
mp_obj_base_t
base
;
mp_map_t
poll_map
;
mp_map_t
poll_map
;
int
flags
;
}
mp_obj_poll_t
;
}
mp_obj_poll_t
;
/// \method register(obj[, eventmask])
/// \method register(obj[, eventmask])
...
@@ -219,9 +220,7 @@ STATIC mp_obj_t poll_modify(mp_obj_t self_in, mp_obj_t obj_in, mp_obj_t eventmas
...
@@ -219,9 +220,7 @@ STATIC mp_obj_t poll_modify(mp_obj_t self_in, mp_obj_t obj_in, mp_obj_t eventmas
}
}
MP_DEFINE_CONST_FUN_OBJ_3
(
poll_modify_obj
,
poll_modify
);
MP_DEFINE_CONST_FUN_OBJ_3
(
poll_modify_obj
,
poll_modify
);
/// \method poll([timeout])
STATIC
mp_uint_t
poll_poll_internal
(
uint
n_args
,
const
mp_obj_t
*
args
)
{
/// Timeout is in milliseconds.
STATIC
mp_obj_t
poll_poll
(
uint
n_args
,
const
mp_obj_t
*
args
)
{
mp_obj_poll_t
*
self
=
args
[
0
];
mp_obj_poll_t
*
self
=
args
[
0
];
// work out timeout (its given already in ms)
// work out timeout (its given already in ms)
...
@@ -239,33 +238,44 @@ STATIC mp_obj_t poll_poll(uint n_args, const mp_obj_t *args) {
...
@@ -239,33 +238,44 @@ STATIC mp_obj_t poll_poll(uint n_args, const mp_obj_t *args) {
}
}
}
}
self
->
flags
=
flags
;
mp_uint_t
start_tick
=
mp_hal_ticks_ms
();
mp_uint_t
start_tick
=
mp_hal_ticks_ms
();
mp_uint_t
n_ready
;
for
(;;)
{
for
(;;)
{
// poll the objects
// poll the objects
mp_uint_t
n_ready
=
poll_map_poll
(
&
self
->
poll_map
,
NULL
);
n_ready
=
poll_map_poll
(
&
self
->
poll_map
,
NULL
);
if
(
n_ready
>
0
||
(
timeout
!=
-
1
&&
mp_hal_ticks_ms
()
-
start_tick
>=
timeout
))
{
if
(
n_ready
>
0
||
(
timeout
!=
-
1
&&
mp_hal_ticks_ms
()
-
start_tick
>=
timeout
))
{
// one or more objects are ready, or we had a timeout
break
;
mp_obj_list_t
*
ret_list
=
mp_obj_new_list
(
n_ready
,
NULL
);
n_ready
=
0
;
for
(
mp_uint_t
i
=
0
;
i
<
self
->
poll_map
.
alloc
;
++
i
)
{
if
(
!
MP_MAP_SLOT_IS_FILLED
(
&
self
->
poll_map
,
i
))
{
continue
;
}
poll_obj_t
*
poll_obj
=
(
poll_obj_t
*
)
self
->
poll_map
.
table
[
i
].
value
;
if
(
poll_obj
->
flags_ret
!=
0
)
{
mp_obj_t
tuple
[
2
]
=
{
poll_obj
->
obj
,
MP_OBJ_NEW_SMALL_INT
(
poll_obj
->
flags_ret
)};
ret_list
->
items
[
n_ready
++
]
=
mp_obj_new_tuple
(
2
,
tuple
);
if
(
flags
&
FLAG_ONESHOT
)
{
// Don't poll next time, until new event flags will be set explicitly
poll_obj
->
flags
=
0
;
}
}
}
return
ret_list
;
}
}
MICROPY_EVENT_POLL_HOOK
MICROPY_EVENT_POLL_HOOK
}
}
return
n_ready
;
}
STATIC
mp_obj_t
poll_poll
(
uint
n_args
,
const
mp_obj_t
*
args
)
{
mp_obj_poll_t
*
self
=
args
[
0
];
mp_uint_t
n_ready
=
poll_poll_internal
(
n_args
,
args
);
// one or more objects are ready, or we had a timeout
mp_obj_list_t
*
ret_list
=
mp_obj_new_list
(
n_ready
,
NULL
);
n_ready
=
0
;
for
(
mp_uint_t
i
=
0
;
i
<
self
->
poll_map
.
alloc
;
++
i
)
{
if
(
!
MP_MAP_SLOT_IS_FILLED
(
&
self
->
poll_map
,
i
))
{
continue
;
}
poll_obj_t
*
poll_obj
=
(
poll_obj_t
*
)
self
->
poll_map
.
table
[
i
].
value
;
if
(
poll_obj
->
flags_ret
!=
0
)
{
mp_obj_t
tuple
[
2
]
=
{
poll_obj
->
obj
,
MP_OBJ_NEW_SMALL_INT
(
poll_obj
->
flags_ret
)};
ret_list
->
items
[
n_ready
++
]
=
mp_obj_new_tuple
(
2
,
tuple
);
if
(
self
->
flags
&
FLAG_ONESHOT
)
{
// Don't poll next time, until new event flags will be set explicitly
poll_obj
->
flags
=
0
;
}
}
}
return
ret_list
;
}
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN
(
poll_poll_obj
,
1
,
3
,
poll_poll
);
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN
(
poll_poll_obj
,
1
,
3
,
poll_poll
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment