mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
Uemis downloader: add helper function to estimate memory needs
[Dirk Hohndel: refactored one huge commit into smaller pieces] Signed-off-by: Guido Lerch <guido.lerch@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
4ba5dd85d4
commit
ff0859ff21
1 changed files with 36 additions and 0 deletions
|
@ -34,6 +34,9 @@
|
|||
//#define UEMIS_DEBUG 1 + 2
|
||||
|
||||
#define UEMIS_MAX_FILES 4000
|
||||
#define UEMIS_MEM_FULL 3
|
||||
#define UEMIS_MEM_CRITICAL 1
|
||||
#define UEMIS_MEM_OK 0
|
||||
|
||||
#if UEMIS_DEBUG & 64 /* we are reading from a copy of the filesystem, not the device - no need to wait */
|
||||
#define UEMIS_TIMEOUT 50 /* 50ns */
|
||||
|
@ -900,6 +903,39 @@ static char *uemis_get_divenr(char *deviceidstr)
|
|||
return strdup(divenr);
|
||||
}
|
||||
|
||||
/* do some more sophisticated calculations here to try and predict if the next round of
|
||||
* divelog/divedetail reads will fit into the UEMIS buffer,
|
||||
* filenr holds now the uemis filenr after having read several logs including the dive details,
|
||||
* fCapacity will five us the average number of files needed for all currently loaded data
|
||||
* remember the maximum file usage per dive
|
||||
* return : UEMIS_MEM_OK if there is enough memeory for a full round
|
||||
* UEMIS_MEM_CRITICAL if the memory is good for reading the dive logs
|
||||
* UEMIS_MEM_FULL if the memory is exhaused
|
||||
*/
|
||||
static int get_memory(struct dive_table *td)
|
||||
{
|
||||
|
||||
if (td->nr == 0)
|
||||
return UEMIS_MEM_OK;
|
||||
|
||||
if (filenr / td->nr > max_mem_used)
|
||||
max_mem_used = filenr / td->nr;
|
||||
/* predict based on the max_mem_used value if the set of next 11 divelogs plus details
|
||||
* fit into the memory before we have to disconnect the UEMIS and continuem. To be on
|
||||
* the safe side we calculate using 12 dives. */
|
||||
if (max_mem_used * 11 > UEMIS_MAX_FILES - filenr) {
|
||||
/* the next set of divelogs will most likely not fit into the memory */
|
||||
if (nr_divespots * 2 > UEMIS_MAX_FILES - filenr) {
|
||||
/* if we get here we have a severe issue as the divespots will not fit into
|
||||
* this run either. */
|
||||
return UEMIS_MEM_FULL;
|
||||
}
|
||||
/* we continue reading the divespots */
|
||||
return UEMIS_MEM_CRITICAL;
|
||||
}
|
||||
return UEMIS_MEM_OK;
|
||||
}
|
||||
|
||||
const char *do_uemis_import(device_data_t *data)
|
||||
{
|
||||
const char *mountpath = data->devname;
|
||||
|
|
Loading…
Reference in a new issue