Lines Matching refs:cn

110 	dsvcd_container_t *cn;
115 cn = calloc(1, sizeof (dsvcd_container_t));
116 if (cn == NULL)
119 cn->cn_id = strdup(cn_id);
120 if (cn->cn_id == NULL) {
121 free(cn);
125 (void) mutex_init(&cn->cn_lock, USYNC_THREAD, NULL);
126 (void) mutex_init(&cn->cn_hlock_lock, USYNC_THREAD, NULL);
127 (void) mutex_init(&cn->cn_nholds_lock, USYNC_THREAD, NULL);
129 (void) cond_init(&cn->cn_hlockcv, USYNC_THREAD, NULL);
131 cn->cn_whead = NULL;
132 cn->cn_wtail = NULL;
133 cn->cn_nholds = 0;
134 cn->cn_closing = B_FALSE;
135 cn->cn_crosshost = crosshost;
136 cn->cn_hlockstate = CN_HUNLOCKED;
137 cn->cn_hlockcount = 0;
139 return (cn);
143 * Destroy container `cn'; wait a decent amount of time for activity on the
148 cn_destroy(dsvcd_container_t *cn)
153 dhcpmsg(MSG_VERBOSE, "destroying container synchpoint `%s'", cn->cn_id);
155 (void) mutex_lock(&cn->cn_lock);
156 cn->cn_closing = B_TRUE;
157 (void) mutex_unlock(&cn->cn_lock);
166 nstalelocks = cn_nlocks(cn);
175 "container `%s'", cn->cn_id);
178 "container `%s'", nstalelocks, cn->cn_id);
181 (void) cond_destroy(&cn->cn_hlockcv);
182 (void) mutex_destroy(&cn->cn_nholds_lock);
183 (void) mutex_destroy(&cn->cn_hlock_lock);
184 (void) mutex_destroy(&cn->cn_lock);
186 free(cn->cn_id);
187 free(cn);
192 * `cn'. Returns a DSVC_* return code; if DSVC_SUCCESS is returned, then
197 cn_wait_for_lock(dsvcd_container_t *cn, dsvcd_locktype_t locktype)
202 assert(MUTEX_HELD(&cn->cn_nholds_lock));
203 assert(cn->cn_nholds != 0);
219 if (cn->cn_whead != NULL) {
220 waititem.wl_prev = cn->cn_wtail;
221 cn->cn_wtail->wl_next = &waititem;
222 cn->cn_wtail = &waititem;
224 cn->cn_whead = &waititem;
225 cn->cn_wtail = &waititem;
229 if (cond_wait(&waititem.wl_cv, &cn->cn_nholds_lock) != 0) {
234 } while ((locktype == DSVCD_RDLOCK && cn->cn_nholds == -1) ||
235 (locktype == DSVCD_WRLOCK && cn->cn_nholds != 0));
239 assert(MUTEX_HELD(&cn->cn_nholds_lock));
247 cn->cn_whead = waititem.wl_next;
252 cn->cn_wtail = waititem.wl_prev;
256 cn->cn_nholds = -1;
258 cn->cn_nholds++;
267 if (locktype == DSVCD_RDLOCK && cn->cn_whead != NULL &&
268 cn->cn_whead->wl_locktype == DSVCD_RDLOCK)
269 (void) cond_signal(&cn->cn_whead->wl_cv);
271 (void) mutex_unlock(&cn->cn_nholds_lock);
276 * Lock container `cn' for reader (shared) access. If the container cannot
283 cn_rdlock(dsvcd_container_t *cn, boolean_t nonblock)
290 (void) mutex_lock(&cn->cn_lock);
291 if (cn->cn_closing) {
292 (void) mutex_unlock(&cn->cn_lock);
295 (void) mutex_unlock(&cn->cn_lock);
306 (void) mutex_lock(&cn->cn_nholds_lock);
308 if (cn->cn_nholds != -1 && cn->cn_whead == NULL &&
309 host_lock(cn, F_RDLCK, B_TRUE) == DSVC_SUCCESS) {
310 cn->cn_nholds++;
311 (void) mutex_unlock(&cn->cn_nholds_lock);
315 (void) mutex_unlock(&cn->cn_nholds_lock);
324 retval = host_lock(cn, F_RDLCK, B_FALSE);
347 (void) mutex_lock(&cn->cn_nholds_lock);
348 if (cn->cn_nholds != -1 &&
349 (cn->cn_whead == NULL || cn->cn_nholds == 0)) {
350 cn->cn_nholds++;
351 (void) mutex_unlock(&cn->cn_nholds_lock);
356 retval = cn_wait_for_lock(cn, DSVCD_RDLOCK);
358 (void) host_unlock(cn);
365 * Lock container `cn' for writer (exclusive) access. If the container
371 cn_wrlock(dsvcd_container_t *cn, boolean_t nonblock)
378 (void) mutex_lock(&cn->cn_lock);
379 if (cn->cn_closing) {
380 (void) mutex_unlock(&cn->cn_lock);
383 (void) mutex_unlock(&cn->cn_lock);
390 (void) mutex_lock(&cn->cn_nholds_lock);
392 if (cn->cn_nholds == 0 &&
393 host_lock(cn, F_WRLCK, B_TRUE) == DSVC_SUCCESS) {
394 cn->cn_nholds = -1;
395 (void) mutex_unlock(&cn->cn_nholds_lock);
399 (void) mutex_unlock(&cn->cn_nholds_lock);
408 retval = host_lock(cn, F_WRLCK, B_FALSE);
416 (void) mutex_lock(&cn->cn_nholds_lock);
417 if (cn->cn_nholds == 0) {
418 cn->cn_nholds = -1;
419 (void) mutex_unlock(&cn->cn_nholds_lock);
424 retval = cn_wait_for_lock(cn, DSVCD_WRLOCK);
426 (void) host_unlock(cn);
433 * Unlock reader or writer lock on container `cn'; returns a DSVC_* code
436 cn_unlock(dsvcd_container_t *cn)
438 (void) mutex_lock(&cn->cn_nholds_lock);
440 if (cn->cn_nholds == 0) {
441 (void) mutex_unlock(&cn->cn_nholds_lock);
445 if (cn->cn_nholds != -1 && cn->cn_nholds != 1) {
446 cn->cn_nholds--;
447 (void) host_unlock(cn);
448 (void) mutex_unlock(&cn->cn_nholds_lock);
459 cn->cn_nholds = 0;
460 if (cn->cn_whead != NULL)
461 (void) cond_signal(&cn->cn_whead->wl_cv);
463 (void) host_unlock(cn);
464 (void) mutex_unlock(&cn->cn_nholds_lock);
470 * Find out what kind of lock is on `cn'. Note that this is just a
475 cn_locktype(dsvcd_container_t *cn)
479 (void) mutex_lock(&cn->cn_nholds_lock);
480 nholds = cn->cn_nholds;
481 (void) mutex_unlock(&cn->cn_nholds_lock);
492 * Obtain a lock of type `locktype' on container `cn' such that we have
499 host_lock(dsvcd_container_t *cn, int locktype, boolean_t nonblock)
506 if (!cn->cn_crosshost)
513 (void) mutex_lock(&cn->cn_lock);
514 if (cn->cn_closing) {
515 (void) mutex_unlock(&cn->cn_lock);
518 (void) mutex_unlock(&cn->cn_lock);
541 (void) mutex_lock(&cn->cn_hlock_lock);
543 while (cn->cn_hlockstate == CN_HPENDING ||
544 cn->cn_hlockstate == CN_HRDLOCKED && locktype == F_WRLCK) {
546 (void) mutex_unlock(&cn->cn_hlock_lock);
550 if (cond_wait(&cn->cn_hlockcv, &cn->cn_hlock_lock) != 0) {
551 (void) mutex_unlock(&cn->cn_hlock_lock);
556 if (cn->cn_hlockstate == CN_HRDLOCKED ||
557 cn->cn_hlockstate == CN_HWRLOCKED) {
561 assert(cn->cn_hlockcount > 0);
562 cn->cn_hlockcount++;
563 (void) mutex_unlock(&cn->cn_hlock_lock);
571 assert(cn->cn_hlockcount == 0);
579 basename = strrchr(cn->cn_id, '/');
581 basename = cn->cn_id;
586 basename - cn->cn_id, cn->cn_id, basename);
589 (void) mutex_unlock(&cn->cn_hlock_lock);
593 cn->cn_hlockstate = CN_HPENDING;
594 (void) mutex_unlock(&cn->cn_hlock_lock);
608 (void) mutex_lock(&cn->cn_hlock_lock);
609 cn->cn_hlockstate = CN_HUNLOCKED;
610 (void) cond_signal(&cn->cn_hlockcv);
611 (void) mutex_unlock(&cn->cn_hlock_lock);
619 (void) mutex_lock(&cn->cn_hlock_lock);
620 cn->cn_hlockstate = (locktype == F_WRLCK ? CN_HWRLOCKED : CN_HRDLOCKED);
621 cn->cn_hlockcount++;
622 cn->cn_hlockfd = fd;
623 (void) cond_broadcast(&cn->cn_hlockcv);
624 (void) mutex_unlock(&cn->cn_hlock_lock);
631 * `cn'; if the number of checked out instances goes to zero, then the host
635 host_unlock(dsvcd_container_t *cn)
639 if (!cn->cn_crosshost)
642 assert(cn->cn_hlockcount > 0);
644 (void) mutex_lock(&cn->cn_hlock_lock);
645 if (cn->cn_hlockcount > 1) {
650 cn->cn_hlockcount--;
651 (void) mutex_unlock(&cn->cn_hlock_lock);
660 if (fcntl(cn->cn_hlockfd, F_SETLK, &flock) == -1) {
661 (void) mutex_unlock(&cn->cn_hlock_lock);
681 (void) close(cn->cn_hlockfd);
682 cn->cn_hlockcount = 0;
683 cn->cn_hlockstate = CN_HUNLOCKED;
689 (void) cond_signal(&cn->cn_hlockcv);
690 (void) mutex_unlock(&cn->cn_hlock_lock);
696 * Return the number of locks currently held for container `cn'.
699 cn_nlocks(dsvcd_container_t *cn)
703 (void) mutex_lock(&cn->cn_nholds_lock);
704 (void) mutex_lock(&cn->cn_hlock_lock);
706 switch (cn->cn_nholds) {
708 nlocks = cn->cn_hlockcount;
714 nlocks = cn->cn_nholds;
719 cn->cn_nholds, cn->cn_hlockstate, cn->cn_hlockcount);
721 (void) mutex_unlock(&cn->cn_hlock_lock);
722 (void) mutex_unlock(&cn->cn_nholds_lock);