Changeset c0c388d2 in mainline
- Timestamp:
- 2019-08-03T07:36:48Z (5 years ago)
- 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)
- Location:
- uspace/srv/sysman
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/sysman/job.c
r694253c rc0c388d2 14 14 static fibril_condvar_t job_queue_cv; 15 15 16 static void job_destroy(job_t **); 17 18 16 19 static int job_run_start(job_t *job) 17 20 { … … 72 75 fibril_condvar_broadcast(&job->state_cv); 73 76 fibril_mutex_unlock(&job->state_mtx); 77 78 job_del_ref(&job); 74 79 75 80 return EOK; … … 91 96 * Note that possible use of fibril pool must hold invariant 92 97 * 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. 94 99 */ 95 100 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); 97 102 fibril_add_ready(runner_fibril); 98 103 } … … 135 140 } 136 141 142 /* Only job dispatcher waits, it's correct to notify one only. */ 137 143 fibril_condvar_signal(&job_queue_cv); 138 144 fibril_mutex_unlock(&job_queue_mtx); … … 160 166 } 161 167 168 void job_add_ref(job_t *job) 169 { 170 atomic_inc(&job->refcnt); 171 } 172 173 void 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 162 186 static void job_init(job_t *job, job_type_t type) 163 187 { … … 166 190 link_initialize(&job->link); 167 191 list_initialize(&job->blocking_jobs); 192 193 /* Start with one reference for the creator */ 194 atomic_set(&job->refcnt, 1); 168 195 169 196 job->type = type; … … 185 212 } 186 213 187 void job_destroy(job_t **job_ptr)214 static void job_destroy(job_t **job_ptr) 188 215 { 189 216 job_t *job = *job_ptr; … … 195 222 job_link_t *jl = list_get_instance(cur_link, job_link_t, link); 196 223 list_remove(cur_link); 224 job_del_ref(&jl->job); 197 225 free(jl); 198 226 } -
uspace/srv/sysman/job.h
r694253c rc0c388d2 3 3 4 4 #include <adt/list.h> 5 #include <atomic.h> 5 6 6 7 #include "unit.h" … … 25 26 26 27 struct job { 28 /** Link to queue job is in */ 27 29 link_t link; 28 30 31 /** List of jobs (job_link_t ) that are blocking the job. */ 29 32 list_t blocking_jobs; 33 34 /** Reference counter for the job structure. */ 35 atomic_t refcnt; 30 36 31 37 job_type_t type; … … 36 42 fibril_condvar_t state_cv; 37 43 44 /** Return value of the job, defined only when state == JOB_FINISHED */ 38 45 int retval; 39 46 }; … … 44 51 extern int job_wait(job_t *); 45 52 53 extern void job_add_ref(job_t *); 54 extern void job_del_ref(job_t **); 55 46 56 extern job_t *job_create(job_type_t type); 47 extern void job_destroy(job_t **);48 57 49 58 #endif -
uspace/srv/sysman/sysman.c
r694253c rc0c388d2 27 27 } 28 28 29 /* Job is passed to the accumulator, i.e. no add_ref. */ 29 30 list_append(&job->link, accumulator); 30 31 … … 35 36 36 37 fail: 37 job_de stroy(&job);38 job_del_ref(&job); 38 39 return rc; 39 40 } … … 50 51 } 51 52 53 // TODO handle errors when adding job accumulator 52 54 job_queue_jobs(&new_jobs); 53 55
Note:
See TracChangeset
for help on using the changeset viewer.