Changeset 73f7c4e in mainline for uspace/srv/sysman/sysman.c
- Timestamp:
- 2019-08-06T18:29:02Z (6 years ago)
- Children:
- c2d50c8
- Parents:
- c1b2084
- git-author:
- Michal Koutný <xm.koutny+hos@…> (2015-05-24 09:32:10)
- git-committer:
- Matthieu Riolo <matthieu.riolo@…> (2019-08-06 18:29:02)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/sysman/sysman.c
rc1b2084 r73f7c4e 62 62 static LIST_INITIALIZE(event_queue); 63 63 static fibril_mutex_t event_queue_mtx; 64 static fibril_condvar_t event_queue_cv; 64 static fibril_condvar_t event_queue_nonempty_cv; 65 static fibril_condvar_t event_queue_empty_cv; 65 66 66 67 static hash_table_t observed_objects; … … 123 124 { 124 125 fibril_mutex_initialize(&event_queue_mtx); 125 fibril_condvar_initialize(&event_queue_cv); 126 fibril_condvar_initialize(&event_queue_nonempty_cv); 127 fibril_condvar_initialize(&event_queue_empty_cv); 126 128 127 129 bool table = … … 141 143 fibril_mutex_lock(&event_queue_mtx); 142 144 while (list_empty(&event_queue)) { 143 fibril_condvar_wait(&event_queue_cv, &event_queue_mtx); 145 fibril_condvar_signal(&event_queue_empty_cv); 146 fibril_condvar_wait(&event_queue_nonempty_cv, 147 &event_queue_mtx); 144 148 } 145 149 … … 160 164 /** Create and queue job for unit 161 165 * 166 * If unit already has the same job assigned callback is set to it. 167 * 162 168 * @param[in] callback (optional) callback must explicitly delete reference 163 * to job 164 */ 165 int sysman_queue_job(unit_t *unit, unit_state_t target_state, 169 * to job, void callback(void *job, void *callback_arg) 170 * 171 * return EBUSY unit already has a job assigned of different type 172 */ 173 int sysman_run_job(unit_t *unit, unit_state_t target_state, 166 174 callback_handler_t callback, void *callback_arg) 167 175 { 168 job_t *job = job_create(unit, target_state); 169 if (job == NULL) { 170 return ENOMEM; 176 job_t *job; 177 178 if (unit->job != NULL) { 179 assert(unit->job->state != JOB_UNQUEUED); 180 181 if (unit->job->target_state != target_state) { 182 return EBUSY; 183 } 184 job = unit->job; 185 } else { 186 job = job_create(unit, target_state); 187 if (job == NULL) { 188 return ENOMEM; 189 } 190 /* Reference in unit is enough */ 191 job_del_ref(&job); 171 192 } 172 193 … … 176 197 } 177 198 178 job_add_ref(job); 179 sysman_raise_event(&sysman_event_job_process, job); 180 181 job_del_ref(&job); 199 if (job->state == JOB_UNQUEUED) { 200 job_add_ref(job); 201 sysman_raise_event(&sysman_event_job_process, job); 202 } 203 182 204 return EOK; 183 205 } … … 199 221 list_append(&event->event_queue, &event_queue); 200 222 /* There's only single event loop, broadcast is unnecessary */ 201 fibril_condvar_signal(&event_queue_cv); 223 fibril_condvar_signal(&event_queue_nonempty_cv); 224 fibril_mutex_unlock(&event_queue_mtx); 225 } 226 227 /** Empty current content of event queue 228 * 229 * This is potentially blocking call and as long as fibrils are cooperatively 230 * scheduled, queue will be empty upon return from this function. 231 */ 232 void sysman_process_queue(void) 233 { 234 fibril_mutex_lock(&event_queue_mtx); 235 while (!list_empty(&event_queue)) { 236 fibril_condvar_wait(&event_queue_empty_cv, &event_queue_mtx); 237 } 202 238 fibril_mutex_unlock(&event_queue_mtx); 203 239 }
Note:
See TracChangeset
for help on using the changeset viewer.