Changeset f0950d2 in mainline


Ignore:
Timestamp:
2025-06-17T13:23:57Z (5 days ago)
Author:
Miroslav Cimerman <mc@…>
Children:
d574c11
Parents:
234212a
Message:

hr: add malloc_waitok() and calloc_waitok()

Location:
uspace/srv/bd/hr
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/bd/hr/util.c

    r234212a rf0950d2  
    7676extern fibril_rwlock_t hr_volumes_lock;
    7777
     78/*
     79 * malloc() wrapper that behaves like
     80 * FreeBSD malloc(9) with M_WAITOK flag.
     81 *
     82 * Return value is never NULL.
     83 */
     84void *malloc_waitok(size_t size)
     85{
     86        void *ret;
     87        while ((ret = malloc(size)) == NULL)
     88                fibril_usleep(MSEC2USEC(250)); /* sleep 250ms */
     89
     90        return ret;
     91}
     92
     93void *calloc_waitok(size_t nmemb, size_t size)
     94{
     95        void *ret;
     96        while ((ret = calloc(nmemb, size)) == NULL)
     97                fibril_usleep(MSEC2USEC(250)); /* sleep 250ms */
     98
     99        return ret;
     100}
     101
    78102errno_t hr_create_vol_struct(hr_volume_t **rvol, hr_level_t level,
    79103    const char *devname, hr_metadata_type_t metadata_type)
  • uspace/srv/bd/hr/util.h

    r234212a rf0950d2  
    7777} hr_range_lock_t;
    7878
     79extern void *malloc_waitok(size_t)
     80    __attribute__((malloc));
     81
     82extern void *calloc_waitok(size_t, size_t)
     83    __attribute__((malloc));
     84
    7985extern errno_t hr_create_vol_struct(hr_volume_t **, hr_level_t, const char *,
    8086    hr_metadata_type_t);
Note: See TracChangeset for help on using the changeset viewer.