Commit f7d98589 authored by Wesley W. Terpstra's avatar Wesley W. Terpstra

api: return # of callbacks invoked by eb_socket_check

Changing from void return to int return should not change the ABI.
parent 105a0001
......@@ -351,7 +351,7 @@ long eb_socket_run(eb_socket_t socket, long timeout_us);
* YOU MAY NOT CLOSE OR MODIFY ETHERBONE SOCKET DESCRIPTORS IN ANY WAY.
*/
EB_PUBLIC
void eb_socket_check(eb_socket_t socket, uint32_t now, eb_user_data_t user, eb_descriptor_callback_t ready);
int eb_socket_check(eb_socket_t socket, uint32_t now, eb_user_data_t user, eb_descriptor_callback_t ready);
/* Calls (*list)(user, fd) for every descriptor the socket uses. */
EB_PUBLIC
......@@ -675,7 +675,7 @@ class Socket {
/* These can be used to implement your own 'block': */
uint32_t timeout() const;
void descriptors(eb_user_data_t user, eb_descriptor_callback_t list) const;
void check(uint32_t now, eb_user_data_t user, eb_descriptor_callback_t ready);
int check(uint32_t now, eb_user_data_t user, eb_descriptor_callback_t ready);
protected:
Socket(eb_socket_t sock);
......@@ -856,7 +856,7 @@ inline void Socket::descriptors(eb_user_data_t user, eb_descriptor_callback_t li
return eb_socket_descriptors(socket, user, list);
}
inline void Socket::check(uint32_t now, eb_user_data_t user, eb_descriptor_callback_t ready) {
inline int Socket::check(uint32_t now, eb_user_data_t user, eb_descriptor_callback_t ready) {
return eb_socket_check(socket, now, user, ready);
}
......
......@@ -49,7 +49,7 @@ typedef union {
eb_address_t address;
} eb_max_align_t;
EB_PRIVATE int eb_device_slave(eb_socket_t socketp, eb_transport_t transportp, eb_device_t devicep, eb_user_data_t data, eb_descriptor_callback_t ready);
EB_PRIVATE eb_status_t eb_device_flush(eb_device_t device);
EB_PRIVATE int eb_device_slave(eb_socket_t socketp, eb_transport_t transportp, eb_device_t devicep, eb_user_data_t data, eb_descriptor_callback_t ready, int *completed);
EB_PRIVATE eb_status_t eb_device_flush(eb_device_t device, int *completed);
#endif
......@@ -54,7 +54,7 @@ static void EB_mWRITE(uint8_t* wptr, eb_data_t val, int alignment) {
* Whenever a callback or an allocation happens, dereferenced pointers become invalid.
* Thus, the EB_<TYPE>(x) conversions appear late and near their use.
*/
eb_status_t eb_device_flush(eb_device_t devicep) {
eb_status_t eb_device_flush(eb_device_t devicep, int *completed) {
struct eb_socket* socket;
struct eb_socket_aux* aux;
struct eb_device* device;
......@@ -148,6 +148,7 @@ eb_status_t eb_device_flush(eb_device_t devicep) {
/* Deal with OOM cases */
if (cycle->un_ops.dead == cyclep) {
(*cycle->callback)(cycle->user_data, cycle->un_link.device, EB_NULL, EB_OOM);
++*completed;
eb_free_cycle(cyclep);
continue;
}
......@@ -155,6 +156,7 @@ eb_status_t eb_device_flush(eb_device_t devicep) {
/* Was the cycle a no-op? */
if (cycle->un_ops.first == EB_NULL) {
(*cycle->callback)(cycle->user_data, cycle->un_link.device, EB_NULL, EB_OK);
++*completed;
eb_free_cycle(cyclep);
continue;
}
......@@ -215,6 +217,7 @@ eb_status_t eb_device_flush(eb_device_t devicep) {
if (operationp != EB_NULL) {
/* Report the bad operation to the user */
(*cycle->callback)(cycle->user_data, cycle->un_link.device, operationp, reason);
++*completed;
eb_cycle_destroy(cyclep);
eb_free_cycle(cyclep);
continue;
......@@ -225,6 +228,7 @@ eb_status_t eb_device_flush(eb_device_t devicep) {
if (responsep == EB_NULL) {
cycle = EB_CYCLE(cyclep);
(*cycle->callback)(cycle->user_data, cycle->un_link.device, EB_NULL, EB_OOM);
++*completed;
eb_cycle_destroy(cyclep);
eb_free_cycle(cyclep);
continue;
......@@ -415,6 +419,7 @@ eb_status_t eb_device_flush(eb_device_t devicep) {
if (length > eob - wptr) {
/* Blow up in the face of the user */
(*cycle->callback)(cycle->user_data, cycle->un_link.device, operationp, EB_OVERFLOW);
++*completed;
eb_cycle_destroy(cyclep);
eb_free_cycle(cyclep);
eb_free_response(responsep);
......@@ -508,6 +513,7 @@ eb_status_t eb_device_flush(eb_device_t devicep) {
/* No response will arrive, so call callback now */
/* Invalidates pointers, but jumps to top of loop afterwards */
(*cycle->callback)(cycle->user_data, cycle->un_link.device, cycle->un_ops.first, EB_OK);
++*completed;
eb_cycle_destroy(cyclep);
eb_free_cycle(cyclep);
eb_free_response(responsep);
......
......@@ -61,7 +61,7 @@ static void EB_sWRITE(uint8_t* wptr, eb_data_t val, int alignment) {
static uint8_t eb_log2_table[8] = { 0, 1, 2, 4, 7, 3, 6, 5 };
static uint8_t eb_log2(uint8_t x) { return eb_log2_table[(uint8_t)(x * 0x17) >> 5]; }
int eb_device_slave(eb_socket_t socketp, eb_transport_t transportp, eb_device_t devicep, eb_user_data_t user_data, eb_descriptor_callback_t ready) {
int eb_device_slave(eb_socket_t socketp, eb_transport_t transportp, eb_device_t devicep, eb_user_data_t user_data, eb_descriptor_callback_t ready, int* completed) {
struct eb_socket* socket;
struct eb_transport* transport;
struct eb_device* device;
......@@ -333,7 +333,7 @@ resume_cycle:
if (wconfig) {
if (sel_ok)
eb_socket_write_config(socketp, op_width, bwa, wv);
*completed += eb_socket_write_config(socketp, op_width, bwa, wv);
} else {
if (sel_ok)
eb_socket_write(socketp, op_width, bwa_b, bwa_l, wv, &error);
......
......@@ -35,7 +35,7 @@
#include "../memory/memory.h"
#include "../format/bigendian.h"
void eb_socket_write_config(eb_socket_t socketp, eb_width_t widths, eb_address_t addr, eb_data_t value) {
int eb_socket_write_config(eb_socket_t socketp, eb_width_t widths, eb_address_t addr, eb_data_t value) {
/* Write to config space => write-back */
int fail;
eb_response_t *responsepp;
......@@ -55,7 +55,7 @@ void eb_socket_write_config(eb_socket_t socketp, eb_width_t widths, eb_address_t
if ((responsep = *responsepp) == EB_NULL) {
*responsepp = responsep = eb_response_flip(socket->last_response);
socket->last_response = EB_NULL;
if (responsep == EB_NULL) return; /* No matching response record */
if (responsep == EB_NULL) return 0; /* No matching response record */
}
response = EB_RESPONSE(responsep);
......@@ -129,6 +129,9 @@ void eb_socket_write_config(eb_socket_t socketp, eb_width_t widths, eb_address_t
eb_cycle_destroy(cyclep);
eb_free_cycle(cyclep);
eb_free_response(responsep);
return 1;
} else {
return 0;
}
}
......
......@@ -34,6 +34,6 @@
EB_PRIVATE eb_data_t eb_socket_read (eb_socket_t socket, eb_width_t width, eb_address_t addr_b, eb_address_t addr_l, uint64_t* error);
EB_PRIVATE void eb_socket_write (eb_socket_t socket, eb_width_t width, eb_address_t addr_b, eb_address_t addr_l, eb_data_t value, uint64_t* error);
EB_PRIVATE eb_data_t eb_socket_read_config (eb_socket_t socket, eb_width_t width, eb_address_t addr, uint64_t error);
EB_PRIVATE void eb_socket_write_config(eb_socket_t socket, eb_width_t width, eb_address_t addr, eb_data_t value);
EB_PRIVATE int eb_socket_write_config(eb_socket_t socket, eb_width_t width, eb_address_t addr, eb_data_t value);
#endif
......@@ -354,7 +354,7 @@ uint32_t eb_socket_timeout(eb_socket_t socketp) {
}
}
void eb_socket_check(eb_socket_t socketp, uint32_t now, eb_user_data_t user, eb_descriptor_callback_t ready) {
int eb_socket_check(eb_socket_t socketp, uint32_t now, eb_user_data_t user, eb_descriptor_callback_t ready) {
struct eb_socket* socket;
struct eb_socket_aux* aux;
struct eb_device* device;
......@@ -367,9 +367,11 @@ void eb_socket_check(eb_socket_t socketp, uint32_t now, eb_user_data_t user, eb_
eb_response_t responsep;
eb_cycle_t cyclep;
eb_socket_aux_t auxp;
int completed;
socket = EB_SOCKET(socketp);
auxp = socket->aux;
completed = 0;
/* Step 1. Kill any expired timeouts */
while (socket->first_response != EB_NULL &&
......@@ -386,6 +388,7 @@ void eb_socket_check(eb_socket_t socketp, uint32_t now, eb_user_data_t user, eb_
(*cycle->callback)(cycle->user_data, cycle->un_link.device, cycle->un_ops.first, EB_TIMEOUT);
socket = EB_SOCKET(socketp); /* Restore pointer */
++completed;
eb_cycle_destroy(cyclep);
eb_free_cycle(cyclep);
eb_free_response(responsep);
......@@ -413,7 +416,7 @@ void eb_socket_check(eb_socket_t socketp, uint32_t now, eb_user_data_t user, eb_
}
/* Grab top-level messages */
while (eb_device_slave(socketp, transportp, EB_NULL, user, ready) > 0) {
while (eb_device_slave(socketp, transportp, EB_NULL, user, ready, &completed) > 0) {
/* noop */
}
}
......@@ -425,15 +428,17 @@ void eb_socket_check(eb_socket_t socketp, uint32_t now, eb_user_data_t user, eb_
next_devicep = device->next;
while (device->link != EB_NULL &&
eb_device_slave(socketp, device->transport, devicep, user, ready) > 0) {
eb_device_slave(socketp, device->transport, devicep, user, ready, &completed) > 0) {
device = EB_DEVICE(devicep);
}
if (device->un_link.passive != devicep)
eb_device_flush(devicep);
eb_device_flush(devicep, &completed);
}
/* Free the temporary address */
if (new_linkp != EB_NULL)
eb_free_link(new_linkp);
return completed;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment