Changeset c0c388d2 in mainline


Ignore:
Timestamp:
2019-08-03T07:36:48Z (5 years ago)
Author:
Matthieu Riolo <matthieu.riolo@…>
Children:
4fe7fcb
Parents:
694253c
git-author:
Michal Koutný <xm.koutny+hos@…> (2015-03-16 19:31:17)
git-committer:
Matthieu Riolo <matthieu.riolo@…> (2019-08-03 07:36:48)
Message:

Sysman jobs memory management (refcnt)

Location:
uspace/srv/sysman
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/sysman/job.c

    r694253c rc0c388d2  
    1414static fibril_condvar_t job_queue_cv;
    1515
     16static void job_destroy(job_t **);
     17
     18
    1619static int job_run_start(job_t *job)
    1720{
     
    7275        fibril_condvar_broadcast(&job->state_cv);
    7376        fibril_mutex_unlock(&job->state_mtx);
     77
     78        job_del_ref(&job);
    7479
    7580        return EOK;
     
    9196                 * Note that possible use of fibril pool must hold invariant
    9297                 * that job is started asynchronously. In the case there exists
    93                  * circular dependency between jobs, it may attain a deadlock.
     98                 * circular dependency between jobs, it may result in a deadlock.
    9499                 */
    95100                job_t *job = list_get_instance(link, job_t, link);
    96                 fid_t runner_fibril = fibril_create(job_runner, job); // TODO cast to void*?
     101                fid_t runner_fibril = fibril_create(job_runner, job);
    97102                fibril_add_ready(runner_fibril);
    98103        }
     
    135140        }
    136141
     142        /* Only job dispatcher waits, it's correct to notify one only. */
    137143        fibril_condvar_signal(&job_queue_cv);
    138144        fibril_mutex_unlock(&job_queue_mtx);
     
    160166}
    161167
     168void job_add_ref(job_t *job)
     169{
     170        atomic_inc(&job->refcnt);
     171}
     172
     173void job_del_ref(job_t **job_ptr)
     174{
     175        job_t *job = *job_ptr;
     176        if (job == NULL) {
     177                return;
     178        }
     179
     180        assert(atomic_get(&job->refcnt) > 0);
     181        if (atomic_predec(&job->refcnt) == 0) {
     182                job_destroy(job_ptr);
     183        }
     184}
     185
    162186static void job_init(job_t *job, job_type_t type)
    163187{
     
    166190        link_initialize(&job->link);
    167191        list_initialize(&job->blocking_jobs);
     192
     193        /* Start with one reference for the creator */
     194        atomic_set(&job->refcnt, 1);
    168195
    169196        job->type = type;
     
    185212}
    186213
    187 void job_destroy(job_t **job_ptr)
     214static void job_destroy(job_t **job_ptr)
    188215{
    189216        job_t *job = *job_ptr;
     
    195222                job_link_t *jl = list_get_instance(cur_link, job_link_t, link);
    196223                list_remove(cur_link);
     224                job_del_ref(&jl->job);
    197225                free(jl);
    198226        }
  • uspace/srv/sysman/job.h

    r694253c rc0c388d2  
    33
    44#include <adt/list.h>
     5#include <atomic.h>
    56
    67#include "unit.h"
     
    2526
    2627struct job {
     28        /** Link to queue job is in */
    2729        link_t link;
    2830
     31        /** List of jobs (job_link_t ) that are blocking the job. */
    2932        list_t blocking_jobs;
     33
     34        /** Reference counter for the job structure. */
     35        atomic_t refcnt;
    3036
    3137        job_type_t type;
     
    3642        fibril_condvar_t state_cv;
    3743
     44        /** Return value of the job, defined only when state == JOB_FINISHED */
    3845        int retval;
    3946};
     
    4451extern int job_wait(job_t *);
    4552
     53extern void job_add_ref(job_t *);
     54extern void job_del_ref(job_t **);
     55
    4656extern job_t *job_create(job_type_t type);
    47 extern void job_destroy(job_t **);
    4857
    4958#endif
  • uspace/srv/sysman/sysman.c

    r694253c rc0c388d2  
    2727        }
    2828
     29        /* Job is passed to the accumulator, i.e. no add_ref. */
    2930        list_append(&job->link, accumulator);
    3031
     
    3536
    3637fail:
    37         job_destroy(&job);
     38        job_del_ref(&job);
    3839        return rc;
    3940}
     
    5051        }
    5152
     53        // TODO handle errors when adding job accumulator
    5254        job_queue_jobs(&new_jobs);
    5355
Note: See TracChangeset for help on using the changeset viewer.