/* Create a boxed integer. */ Boxed integer_new(Integer value) { Boxed reference = boxed_new(integer_alloc(value)); if (!reference) goto memory_error; return reference; memory_error: return NULL; }
/* * Allocates a fileset instance, initializes fs_dirgamma and * fs_sizegamma default values, and sets the fileset name to the * supplied name string. Puts the allocated fileset on the * master fileset list and returns a pointer to it. */ fileset_t * fileset_define(char *name) { fileset_t *fileset; if (name == NULL) return (NULL); if ((fileset = (fileset_t *)ipc_malloc(FILEBENCH_FILESET)) == NULL) { filebench_log(LOG_ERROR, "fileset_define: Can't malloc fileset"); return (NULL); } filebench_log(LOG_DEBUG_IMPL, "Defining file %s", name); (void) ipc_mutex_lock(&filebench_shm->fileset_lock); fileset->fs_dirgamma = integer_alloc(1500); fileset->fs_sizegamma = integer_alloc(1500); /* Add fileset to global list */ if (filebench_shm->filesetlist == NULL) { filebench_shm->filesetlist = fileset; fileset->fs_next = NULL; } else { fileset->fs_next = filebench_shm->filesetlist; filebench_shm->filesetlist = fileset; } (void) ipc_mutex_unlock(&filebench_shm->fileset_lock); (void) strcpy(fileset->fs_name, name); return (fileset); }
/* * Allocates a flowop entity and initializes it with inherited * contents from the "inherit" flowop, if it is supplied, or * with zeros otherwise. In either case the file descriptor * (fo_fd) is set to -1, and the fo_next and fo_threadnext * pointers are set to NULL, and fo_thread is set to point to * the owning threadflow. The initialized flowop is placed at * the head of the global flowop list, and also placed on the * tail of thethreadflow's tf_ops list. The routine locks the * flowop's fo_lock and leaves it held on return. If successful, * it returns a pointer to the allocated and initialized flowop, * otherwise NULL. * * filebench_shm->flowop_lock must be held by caller. */ static flowop_t * flowop_define_common(threadflow_t *threadflow, char *name, flowop_t *inherit, int instance, int type) { flowop_t *flowop; if (name == NULL) return (NULL); if ((flowop = (flowop_t *)ipc_malloc(FILEBENCH_FLOWOP)) == NULL) { filebench_log(LOG_ERROR, "flowop_define: Can't malloc flowop"); return (NULL); } filebench_log(LOG_DEBUG_IMPL, "defining flowops %s-%d, addr %zx", name, instance, flowop); if (flowop == NULL) return (NULL); if (inherit) { (void) memcpy(flowop, inherit, sizeof (flowop_t)); (void) pthread_mutex_init(&flowop->fo_lock, ipc_mutexattr()); (void) ipc_mutex_lock(&flowop->fo_lock); flowop->fo_next = NULL; flowop->fo_threadnext = NULL; flowop->fo_fd = -1; filebench_log(LOG_DEBUG_IMPL, "flowop %s-%d calling init", name, instance); } else { (void) memset(flowop, 0, sizeof (flowop_t)); flowop->fo_fd = -1; flowop->fo_iters = integer_alloc(1); flowop->fo_type = type; (void) pthread_mutex_init(&flowop->fo_lock, ipc_mutexattr()); (void) ipc_mutex_lock(&flowop->fo_lock); } /* Create backpointer to thread */ flowop->fo_thread = threadflow; /* Add flowop to global list */ if (filebench_shm->flowoplist == NULL) { filebench_shm->flowoplist = flowop; flowop->fo_next = NULL; } else { flowop->fo_next = filebench_shm->flowoplist; filebench_shm->flowoplist = flowop; } (void) strcpy(flowop->fo_name, name); flowop->fo_instance = instance; if (threadflow == NULL) return (flowop); /* Add flowop to thread op list */ if (threadflow->tf_ops == NULL) { threadflow->tf_ops = flowop; flowop->fo_threadnext = NULL; } else { flowop_t *flowend; /* Find the end of the thread list */ flowend = threadflow->tf_ops; while (flowend->fo_threadnext != NULL) flowend = flowend->fo_threadnext; flowend->fo_threadnext = flowop; flowop->fo_threadnext = NULL; } return (flowop); }