Changeset 81c4e6ec in mainline
- Timestamp:
- 2020-07-05T20:46:27Z (5 years ago)
- Parents:
- a73aaec1
- git-author:
- Matthieu Riolo <matthieu.riolo@…> (2020-07-05 20:37:10)
- git-committer:
- Matthieu Riolo <matthieu.riolo@…> (2020-07-05 20:46:27)
- Location:
- uspace
- Files:
-
- 3 deleted
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/Makefile
ra73aaec1 r81c4e6ec 145 145 generic/loader.c \ 146 146 generic/getopt.c \ 147 generic/adt/array.c \148 147 generic/adt/checksum.c \ 149 148 generic/adt/circ_buf.c \ … … 192 191 193 192 TEST_SOURCES = \ 194 test/adt/array.c \195 193 test/adt/circ_buf.c \ 196 194 test/adt/odict.c \ -
uspace/lib/c/test/main.c
ra73aaec1 r81c4e6ec 32 32 PCUT_INIT; 33 33 34 PCUT_IMPORT(array);35 34 PCUT_IMPORT(cap); 36 35 PCUT_IMPORT(casting); -
uspace/srv/sysman/job.c
ra73aaec1 r81c4e6ec 70 70 job->unit = u; 71 71 72 array_initialize(&job->blocked_jobs, job_t *);72 list_initialize(&job->blocked_jobs); 73 73 job->blocking_jobs = 0; 74 74 job->blocking_job_failed = false; … … 120 120 assert(!link_used(&job->job_queue)); 121 121 122 array_foreach(job->blocked_jobs, job_t *, job_it) { 123 job_del_ref(&(*job_it)); 124 } 125 array_destroy(&job->blocked_jobs); 122 while (!list_empty(&job->blocked_jobs)) { 123 job_link_t *job_it = list_pop(&job->blocked_jobs, job_link_t, link); 124 job_del_ref(&job_it->job); 125 free(job_it); 126 } 126 127 127 128 free(job); … … 256 257 257 258 /* First remove references, then clear the array */ 258 assert(job->blocked_jobs.size == job->blocked_jobs_count); 259 array_foreach(job->blocked_jobs, job_t *, job_it) { 260 job_unblock(*job_it, job); 261 } 262 array_clear(&job->blocked_jobs); 259 assert(list_count(&job->blocked_jobs) == job->blocked_jobs_count); 260 261 while (!list_empty(&job->blocked_jobs)) { 262 job_link_t *job_it = list_pop(&job->blocked_jobs, job_link_t, link); 263 job_unblock(job_it->job, job); 264 free(job_it); 265 } 263 266 264 267 /* Add reference for event handler */ -
uspace/srv/sysman/job.h
ra73aaec1 r81c4e6ec 30 30 #define SYSMAN_JOB_H 31 31 32 #include <adt/array.h>33 32 #include <adt/list.h> 34 33 #include <stdatomic.h> … … 56 55 typedef struct job job_t; 57 56 57 typedef struct { 58 link_t link; 59 job_t *job; 60 } job_link_t; 61 58 62 struct job { 59 63 link_t job_queue; … … 64 68 65 69 /** Jobs that this job is preventing from running */ 66 array_t blocked_jobs;70 list_t blocked_jobs; 67 71 /** 68 72 * No. of jobs that the job is actually blocking (may differ from size -
uspace/srv/sysman/job_closure.c
ra73aaec1 r81c4e6ec 63 63 static errno_t job_add_blocked_job(job_t *blocking_job, job_t *blocked_job) 64 64 { 65 assert( blocking_job->blocked_jobs.size==65 assert(list_count(&blocking_job->blocked_jobs) == 66 66 blocking_job->blocked_jobs_count); 67 67 68 errno_t rc = array_append(&blocking_job->blocked_jobs, job_t *, 69 blocked_job); 70 if (rc != EOK) { 68 job_link_t *job_link = calloc(1, sizeof(job_link_t)); 69 if (job_link == NULL) { 71 70 return ENOMEM; 72 71 } 72 73 job_link->job = blocked_job; 74 75 list_append(&job_link->link, &blocking_job->blocked_jobs); 76 73 77 job_add_ref(blocked_job); 74 78 … … 97 101 goto finish; 98 102 } 99 job_t *first_job = array_last(closure, job_t *); 103 104 link_t *last_link = list_last(closure); 105 job_link_t *job_link = list_get_instance(last_link, job_link_t, link); 106 job_t *first_job = job_link->job; 100 107 101 108 job_add_ref(first_job); … … 118 125 } 119 126 127 job_link_t *job_link = calloc(1, sizeof(job_link_t)); 128 if (job_link == NULL) { 129 goto finish; 130 } 131 132 job_link->job = created_job; 133 120 134 /* Pass job reference to closure and add one for unit */ 121 rc = array_append(closure, job_t *, created_job); 122 if (rc != EOK) { 123 goto finish; 124 } 135 list_append(&job_link->link, closure); 125 136 126 137 job_add_ref(created_job); … … 164 175 } 165 176 177 job_link_t *job_link = calloc(1, sizeof(job_link_t)); 178 if (job_link == NULL) { 179 goto finish; 180 } 181 182 job_link->job = created_job; 183 166 184 /* Pass job reference to closure and add one for unit */ 167 rc = array_append(closure, job_t *, created_job); 168 if (rc != EOK) { 169 goto finish; 170 } 185 list_append(&job_link->link, closure); 171 186 } 172 187 rc = visit_propagate_job(u, e, ops, closure); … … 308 323 } 309 324 310 errno_t rc = array_append(job_closure, job_t *, main_job); 311 if (rc != EOK) { 312 return rc; 313 } 325 job_link_t *job_link = calloc(1, sizeof(job_link_t)); 326 if (job_link == NULL) { 327 return ENOMEM; 328 } 329 330 job_link->job = main_job; 331 332 list_append(&job_link->link, job_closure); 333 314 334 job_add_ref(main_job); /* Add one for the closure */ 315 335 … … 330 350 } 331 351 332 rc = bfs_traverse_component(main_job->unit, &propagate_ops, job_closure);352 errno_t rc = bfs_traverse_component(main_job->unit, &propagate_ops, job_closure); 333 353 334 354 sysman_log(LVL_DEBUG2, "%s: %i&%i", __func__, flags, CLOSURE_ISOLATE); … … 343 363 344 364 if (rc == EOK) { 345 array_foreach(*job_closure, job_t *, job_it) { 365 list_foreach(*job_closure, link, job_link_t, job_it) { 366 job_t *job = job_it->job; 346 367 sysman_log(LVL_DEBUG2, "%s\t%s, refs: %u", __func__, 347 unit_name( (*job_it)->unit), atomic_load(&(*job_it)->refcnt));368 unit_name(job->unit), atomic_load(&job->refcnt)); 348 369 } 349 370 } 350 371 351 372 /* Clean after ourselves (BFS tag jobs) */ 352 array_foreach(*job_closure, job_t *, job_it) {353 job_t *j = (*job_it)->unit->bfs_data;354 assert( *job_it== j);373 list_foreach(*job_closure, link, job_link_t, job_it) { 374 job_t *j = job_it->job->unit->bfs_data; 375 assert(job_it->job == j); 355 376 job_del_ref(&j); 356 (*job_it)->unit->bfs_data = NULL;357 } 358 359 return rc; 360 } 377 job_it->job->unit->bfs_data = NULL; 378 } 379 380 return rc; 381 } -
uspace/srv/sysman/job_closure.h
ra73aaec1 r81c4e6ec 30 30 #define SYSMAN_JOB_CLOSURE_H 31 31 32 #include <adt/ array.h>32 #include <adt/list.h> 33 33 34 34 #include "job.h" … … 36 36 #define CLOSURE_ISOLATE 0x1 37 37 38 typedef array_t job_closure_t;38 typedef list_t job_closure_t; 39 39 40 40 extern errno_t job_create_closure(job_t *, job_closure_t *, int); -
uspace/srv/sysman/job_queue.c
ra73aaec1 r81c4e6ec 103 103 * @return error code on fail 104 104 */ 105 static errno_tjob_pre_merge(job_t *trunk, job_t *other)105 static void job_pre_merge(job_t *trunk, job_t *other) 106 106 { 107 107 assert(trunk->unit == other->unit); 108 108 assert(trunk->target_state == other->target_state); 109 assert( trunk->blocked_jobs.size== trunk->blocked_jobs_count);109 assert(list_count(&trunk->blocked_jobs) == trunk->blocked_jobs_count); 110 110 assert(other->merged_into == NULL); 111 111 112 errno_t rc = array_concat(&trunk->blocked_jobs, &other->blocked_jobs); 113 if (rc != EOK) { 114 return rc; 115 } 116 array_clear(&other->blocked_jobs); 112 list_concat(&trunk->blocked_jobs, &other->blocked_jobs); 113 114 while (!list_empty(&other->blocked_jobs)) { 115 job_link_t *job_link = list_pop(&other->blocked_jobs, job_link_t, link); 116 free(job_link); 117 } 117 118 118 119 // TODO allocate observed object 119 120 120 121 other->merged_into = trunk; 121 122 return EOK;123 122 } 124 123 125 124 static void job_finish_merge(job_t *trunk, job_t *other) 126 125 { 127 assert( trunk->blocked_jobs.size>= trunk->blocked_jobs_count);126 assert(list_count(&trunk->blocked_jobs) >= trunk->blocked_jobs_count); 128 127 //TODO aggregate merged blocked_jobs 129 trunk->blocked_jobs_count = other->blocked_jobs.size;128 trunk->blocked_jobs_count = list_count(&other->blocked_jobs); 130 129 131 130 /* … … 144 143 static void job_undo_merge(job_t *trunk) 145 144 { 146 assert(trunk->blocked_jobs.size >= trunk->blocked_jobs_count); 147 array_clear_range(&trunk->blocked_jobs, 148 trunk->blocked_jobs_count, trunk->blocked_jobs.size); 145 unsigned long count = list_count(&trunk->blocked_jobs); 146 assert(count >= trunk->blocked_jobs_count); 147 148 while (count-- > 0) { 149 link_t *last_link = list_last(&trunk->blocked_jobs); 150 job_link_t *job_link = list_get_instance(last_link, job_link_t, link); 151 list_remove(last_link); 152 free(job_link); 153 } 149 154 } 150 155 … … 172 177 173 178 /* Check consistency with existing jobs. */ 174 array_foreach(*closure, job_t *, job_it) {175 job_t *job = *job_it;179 list_foreach(*closure, link, job_link_t, job_it) { 180 job_t *job = job_it->job; 176 181 job_t *other_job = job->unit->job; 177 182 … … 205 210 // TODO think about other options to merging 206 211 // (replacing, cancelling) 207 rc = job_pre_merge(other_job, job); 208 if (rc != EOK) { 209 break; 210 } 212 job_pre_merge(other_job, job); 211 213 } 212 214 } … … 214 216 /* Aggregate merged jobs, or rollback any changes in existing jobs */ 215 217 bool finish_merge = (rc == EOK) && !has_error; 216 array_foreach(*closure, job_t *, job_it) { 217 if ((*job_it)->merged_into == NULL) { 218 list_foreach(*closure, link, job_link_t, job_it) { 219 job_t *job = job_it->job; 220 if (job->merged_into == NULL) { 218 221 continue; 219 222 } 220 223 if (finish_merge) { 221 job_finish_merge( (*job_it)->merged_into, *job_it);224 job_finish_merge(job->merged_into, job); 222 225 } else { 223 job_undo_merge( (*job_it)->merged_into);226 job_undo_merge(job->merged_into); 224 227 } 225 228 } … … 236 239 * in their blocked_jobs array. 237 240 */ 238 array_foreach(*closure, job_t *, job_it) {239 job_t *job = (*job_it);241 list_foreach(*closure, link, job_link_t, job_it) { 242 job_t *job = job_it->job; 240 243 if (job->merged_into != NULL) { 241 244 job_del_ref(&job); … … 255 258 256 259 /* We've stolen references from the closure, so erase it */ 257 array_clear(closure); 260 while (!list_empty(closure)) { 261 job_link_t *job_link = list_pop(closure, job_link_t, link); 262 free(job_link); 263 } 258 264 259 265 return EOK; -
uspace/srv/sysman/sysman.c
ra73aaec1 r81c4e6ec 366 366 job_t *job = job_args->job; 367 367 int flags = job_args->flags; 368 array_t job_closure;369 array_initialize(&job_closure, job_t *);368 list_t job_closure; 369 list_initialize(&job_closure); 370 370 371 371 if (job_args->callback != NULL) { … … 402 402 job_del_ref(&job); 403 403 404 array_foreach(job_closure, job_t *, closure_job) { 405 job_del_ref(&(*closure_job)); 406 } 407 array_destroy(&job_closure); 404 while (!list_empty(&job_closure)) { 405 job_link_t *job_link = list_pop(&job_closure, job_link_t, link); 406 job_del_ref(&job_link->job); 407 free(job_link); 408 } 408 409 } 409 410 -
uspace/srv/sysman/test/job_closure.c
ra73aaec1 r81c4e6ec 40 40 PCUT_TEST_SUITE(job_closure); 41 41 42 static array_t exp_closure;43 static array_t act_closure;42 static list_t exp_closure; 43 static list_t act_closure; 44 44 45 45 static bool same_job(job_t *expected, job_t *actual) … … 49 49 } 50 50 51 static bool same_jobs( array_t *expected, array_t *actual)52 { 53 if ( expected->size != actual->size) {51 static bool same_jobs(list_t *expected, list_t *actual) 52 { 53 if (list_count(expected) != list_count(actual)) { 54 54 printf("%s: |expected|, |actual| = %zu, %zu\n", 55 __func__, expected->size, actual->size);55 __func__, list_count(expected), list_count(actual)); 56 56 return false; 57 57 } 58 58 59 59 /* Verify expected \subseteq actual (we've compared sizes) */ 60 array_foreach(*expected, job_t *, it_exp) {60 list_foreach(*expected, link, job_link_t, it_exp) { 61 61 bool found = false; 62 array_foreach(*actual, job_t *, it_act) {63 if (same_job( *it_exp, *it_act)) {62 list_foreach(*actual, link, job_link_t, it_act) { 63 if (same_job(it_exp->job, it_act->job)) { 64 64 found = true; 65 65 break; … … 68 68 if (!found) { 69 69 printf("%s: expected job for %s\n", 70 __func__, unit_name( (*it_exp)->unit));70 __func__, unit_name(it_exp->job->unit)); 71 71 return false; 72 72 } … … 79 79 { 80 80 bool found = false; 81 array_foreach(blocking_job->blocked_jobs, job_t *, it) {82 if ( *it== blocked_job) {81 list_foreach(blocking_job->blocked_jobs, link, job_link_t, it) { 82 if (it->job == blocked_job) { 83 83 found = true; 84 84 break; … … 94 94 } 95 95 96 static void dummy_add_closure( array_t *closure)97 { 98 array_foreach(*closure, job_t *, it) {99 (*it)->unit->job = *it;100 } 101 } 102 103 static void destroy_job_closure( array_t *closure)104 { 105 array_foreach(*closure, job_t *, it) {106 job_del_ref(& (*it));96 static void dummy_add_closure(list_t *closure) 97 { 98 list_foreach(*closure, link, job_link_t, it) { 99 it->job->unit->job = it->job; 100 } 101 } 102 103 static void destroy_job_closure(list_t *closure) 104 { 105 list_foreach(*closure, link, job_link_t, it) { 106 job_del_ref(&it->job); 107 107 } 108 108 } … … 113 113 mock_set_units_state(STATE_STOPPED); 114 114 115 array_initialize(&exp_closure, job_t *); 116 errno_t rc = array_reserve(&exp_closure, MAX_TYPES * MAX_UNITS); 117 assert(rc == EOK); 118 119 array_initialize(&act_closure, job_t *); 120 rc = array_reserve(&act_closure, MAX_TYPES * MAX_UNITS); 121 assert(rc == EOK); 115 list_initialize(&exp_closure); 116 list_initialize(&act_closure); 122 117 123 118 repo_init(); … … 127 122 { 128 123 destroy_job_closure(&act_closure); 129 array_destroy(&act_closure); 124 while (!list_empty(&act_closure)) { 125 job_link_t *job_link = list_pop(&act_closure, job_link_t, link); 126 free(job_link); 127 } 130 128 131 129 destroy_job_closure(&exp_closure); 132 array_destroy(&exp_closure); 130 while (!list_empty(&exp_closure)) { 131 job_link_t *job_link = list_pop(&exp_closure, job_link_t, link); 132 free(job_link); 133 } 133 134 134 135 mock_destroy_units(); … … 156 157 PCUT_ASSERT_INT_EQUALS(EOK, rc); 157 158 158 array_append(&exp_closure, job_t *, dummy_job(u1, STATE_STARTED)); 159 array_append(&exp_closure, job_t *, dummy_job(u2, STATE_STARTED)); 160 array_append(&exp_closure, job_t *, dummy_job(u3, STATE_STARTED)); 159 job_link_t *job_link = calloc(1, sizeof(job_link_t)); 160 PCUT_ASSERT_NOT_NULL(job_link); 161 job_link->job = dummy_job(u1, STATE_STARTED); 162 163 list_append(&job_link->link, &exp_closure); 164 165 job_link = calloc(1, sizeof(job_link_t)); 166 PCUT_ASSERT_NOT_NULL(job_link); 167 job_link->job = dummy_job(u2, STATE_STARTED); 168 169 list_append(&job_link->link, &exp_closure); 170 171 job_link = calloc(1, sizeof(job_link_t)); 172 PCUT_ASSERT_NOT_NULL(job_link); 173 job_link->job = dummy_job(u3, STATE_STARTED); 174 175 list_append(&job_link->link, &exp_closure); 161 176 162 177 dummy_add_closure(&act_closure); … … 188 203 PCUT_ASSERT_INT_EQUALS(EOK, rc); 189 204 190 array_append(&exp_closure, job_t *, dummy_job(u1, STATE_STARTED)); 191 array_append(&exp_closure, job_t *, dummy_job(u2, STATE_STARTED)); 192 array_append(&exp_closure, job_t *, dummy_job(u3, STATE_STARTED)); 205 job_link_t *job_link = calloc(1, sizeof(job_link_t)); 206 PCUT_ASSERT_NOT_NULL(job_link); 207 job_link->job = dummy_job(u1, STATE_STARTED); 208 209 list_append(&job_link->link, &exp_closure); 210 211 job_link = calloc(1, sizeof(job_link_t)); 212 PCUT_ASSERT_NOT_NULL(job_link); 213 job_link->job = dummy_job(u2, STATE_STARTED); 214 215 list_append(&job_link->link, &exp_closure); 216 217 job_link = calloc(1, sizeof(job_link_t)); 218 PCUT_ASSERT_NOT_NULL(job_link); 219 job_link->job = dummy_job(u3, STATE_STARTED); 220 221 list_append(&job_link->link, &exp_closure); 193 222 194 223 dummy_add_closure(&act_closure); … … 222 251 PCUT_ASSERT_INT_EQUALS(EOK, rc); 223 252 224 array_append(&exp_closure, job_t *, dummy_job(u1, STATE_STARTED)); 225 array_append(&exp_closure, job_t *, dummy_job(u2, STATE_STARTED)); 226 array_append(&exp_closure, job_t *, dummy_job(u3, STATE_STARTED)); 253 job_link_t *job_link = calloc(1, sizeof(job_link_t)); 254 PCUT_ASSERT_NOT_NULL(job_link); 255 job_link->job = dummy_job(u1, STATE_STARTED); 256 257 list_append(&job_link->link, &exp_closure); 258 259 job_link = calloc(1, sizeof(job_link_t)); 260 PCUT_ASSERT_NOT_NULL(job_link); 261 job_link->job = dummy_job(u2, STATE_STARTED); 262 263 list_append(&job_link->link, &exp_closure); 264 265 job_link = calloc(1, sizeof(job_link_t)); 266 PCUT_ASSERT_NOT_NULL(job_link); 267 job_link->job = dummy_job(u3, STATE_STARTED); 268 269 list_append(&job_link->link, &exp_closure); 227 270 228 271 dummy_add_closure(&act_closure); … … 270 313 PCUT_ASSERT_INT_EQUALS(EOK, rc); 271 314 272 array_append(&exp_closure, job_t *, dummy_job(u0, STATE_STOPPED)); 273 array_append(&exp_closure, job_t *, dummy_job(u1, STATE_STARTED)); 274 array_append(&exp_closure, job_t *, dummy_job(u2, STATE_STARTED)); 275 array_append(&exp_closure, job_t *, dummy_job(u3, STATE_STOPPED)); 276 array_append(&exp_closure, job_t *, dummy_job(u4, STATE_STOPPED)); 277 array_append(&exp_closure, job_t *, dummy_job(u5, STATE_STOPPED)); 278 array_append(&exp_closure, job_t *, dummy_job(u6, STATE_STOPPED)); 315 job_link_t *job_link = calloc(1, sizeof(job_link_t)); 316 PCUT_ASSERT_NOT_NULL(job_link); 317 job_link->job = dummy_job(u0, STATE_STOPPED); 318 319 list_append(&job_link->link, &exp_closure); 320 321 job_link = calloc(1, sizeof(job_link_t)); 322 PCUT_ASSERT_NOT_NULL(job_link); 323 job_link->job = dummy_job(u1, STATE_STARTED); 324 325 list_append(&job_link->link, &exp_closure); 326 327 job_link = calloc(1, sizeof(job_link_t)); 328 PCUT_ASSERT_NOT_NULL(job_link); 329 job_link->job = dummy_job(u2, STATE_STARTED); 330 331 list_append(&job_link->link, &exp_closure); 332 333 job_link = calloc(1, sizeof(job_link_t)); 334 PCUT_ASSERT_NOT_NULL(job_link); 335 job_link->job = dummy_job(u3, STATE_STOPPED); 336 337 list_append(&job_link->link, &exp_closure); 338 339 job_link = calloc(1, sizeof(job_link_t)); 340 PCUT_ASSERT_NOT_NULL(job_link); 341 job_link->job = dummy_job(u4, STATE_STOPPED); 342 343 list_append(&job_link->link, &exp_closure); 344 345 job_link = calloc(1, sizeof(job_link_t)); 346 PCUT_ASSERT_NOT_NULL(job_link); 347 job_link->job = dummy_job(u5, STATE_STOPPED); 348 349 list_append(&job_link->link, &exp_closure); 350 351 job_link = calloc(1, sizeof(job_link_t)); 352 PCUT_ASSERT_NOT_NULL(job_link); 353 job_link->job = dummy_job(u6, STATE_STOPPED); 354 355 list_append(&job_link->link, &exp_closure); 279 356 280 357 dummy_add_closure(&act_closure);
Note:
See TracChangeset
for help on using the changeset viewer.