OSF DCE Application Development Guide--Core Components
OSF DCE Application Development Guide—Core Components
pthread_once(&init_once_blk, store_mgmt_init);
/* The following loop goes through all the storelets, looking for */
/* one whose reference count is zero. As soon as one such is */
/* found, a handle is allocated for it, storage is allocated for */
/* its store structure, and the loop (and the call) terminates. If */
/* no unreferenced storelet is found, a status of -1 is returned */
/* and no handle is allocated... */
for(i = 0; i < NUM_STORELETS; i++)
{
/* Go to the next storelet... */
hdr = headers + i;
/* Is it unreferenced?... */
if (hdr->refcount == 0)
{
/* If so, lock the header... */
*status = pthread_mutex_lock((pthread_mutex_t *)hdr);
if (*status != 0)
{
return;
}
/* ...and check the reference count again... */
if (hdr->refcount == 0)
{
/* Now we know we "really" have this one. */
/* Only one open is allowed, so lock only */
/* the reference count... */
hdr->refcount++;
/* Now unlock the header so other threads */
/* can continue to check it... */
*status = pthread_mutex_unlock((pthread_mutex_t *)hdr);
if (*status != 0)
return;
/* Now allocate space for the specifica- */
/* tion structure... */
spec = (store_spec_t *)malloc(sizeof(store_spec_t));
spec->number = i;
spec->offset = 0;
*store_h = spec;
/* Allocate space for the storage part of */
/* the header... */
hdr->storage = (idl_byte *)malloc(store_size);
hdr->size = store_size;
/* Finally, set the return status to OK, */
/* and return... */
*status = error_status_ok;
return;
}
16 − 16 Tandem Computers Incorporated 124245