int min_vinit = 1;
#endif /* AFS_DEMAND_ATTACH_FS */
+ /* we must not be called before vol package initialization, since we use
+ * vol package mutexes and conds etc */
+ assert(VInit);
+
SYNC_getAddr(&state->endpoint, &state->addr);
SYNC_cleanupSock(state);
Log("Set thread id %d for FSYNC_sync\n", tid);
#endif /* AFS_PTHREAD_ENV */
+ VOL_LOCK;
+
while (VInit < min_vinit) {
/* Let somebody else run until all volumes have been preattached
* (DAFS), or we have started attaching volumes (non-DAFS). This
* doesn't mean that all volumes have been attached.
*/
#ifdef AFS_PTHREAD_ENV
- pthread_yield();
+ VOL_CV_WAIT(&vol_vinit_cond);
#else /* AFS_PTHREAD_ENV */
LWP_DispatchProcess();
#endif /* AFS_PTHREAD_ENV */
}
+
+ VOL_UNLOCK;
+
state->fd = SYNC_getSock(&state->endpoint);
code = SYNC_bindSock(state);
assert(!code);
pthread_cond_t vol_put_volume_cond;
pthread_cond_t vol_sleep_cond;
pthread_cond_t vol_init_attach_cond;
+pthread_cond_t vol_vinit_cond;
int vol_attach_threads = 1;
#endif /* AFS_PTHREAD_ENV */
}
}
+/**
+ * Set VInit to a certain value, and signal waiters.
+ *
+ * @param[in] value the value to set VInit to
+ *
+ * @pre VOL_LOCK held
+ */
+static void
+VSetVInit_r(int value)
+{
+ VInit = value;
+#ifdef AFS_PTHREAD_ENV
+ assert(pthread_cond_broadcast(&vol_vinit_cond) == 0);
+#endif
+}
+
int
VInitVolumePackage2(ProgramType pt, VolumePackageOptions * opts)
{
assert(pthread_cond_init(&vol_put_volume_cond, NULL) == 0);
assert(pthread_cond_init(&vol_sleep_cond, NULL) == 0);
assert(pthread_cond_init(&vol_init_attach_cond, NULL) == 0);
+ assert(pthread_cond_init(&vol_vinit_cond, NULL) == 0);
#else /* AFS_PTHREAD_ENV */
IOMGR_Initialize();
#endif /* AFS_PTHREAD_ENV */
}
}
VOL_LOCK;
- VInit = 2; /* Initialized, and all volumes have been attached */
+ VSetVInit_r(2); /* Initialized, and all volumes have been attached */
LWP_NoYieldSignal(VInitAttachVolumes);
VOL_UNLOCK;
return 0;
assert(pthread_cond_destroy(¶ms.thread_done_cv) == 0);
}
VOL_LOCK;
- VInit = 2; /* Initialized, and all volumes have been attached */
+ VSetVInit_r(2); /* Initialized, and all volumes have been attached */
assert(pthread_cond_broadcast(&vol_init_attach_cond) == 0);
VOL_UNLOCK;
return 0;
}
VOL_LOCK;
- VInit = 2; /* Initialized, and all volumes have been attached */
+ VSetVInit_r(2); /* Initialized, and all volumes have been attached */
assert(pthread_cond_broadcast(&vol_init_attach_cond) == 0);
VOL_UNLOCK;
(programType != fileServer) &&
(programType != salvager));
rc = FSYNC_clientInit();
- if (rc)
- VInit = 3;
+ if (rc) {
+ VSetVInit_r(3);
+ }
return rc;
}
assert((programType != fileServer) &&
(programType != salvager));
FSYNC_clientFinis();
- VInit = 2;
+ VSetVInit_r(2);
}
/**
* initialization level indicates that all volumes are attached,
* which implies that all partitions are initialized. */
#ifdef AFS_PTHREAD_ENV
- sleep(10);
+ VOL_CV_WAIT(&vol_vinit_cond);
#else /* AFS_PTHREAD_ENV */
IOMGR_Sleep(10);
#endif /* AFS_PTHREAD_ENV */