variant_ptr<T, D> pop_variant(D d = D()) noexcept { auto e = pri_pop(); if (e != nullptr) { if (e->shared()) { ACTX_ASSERTS(!e->unique()); auto ptr = e->free_shared(); ACTX_ASSERTS(!!ptr); return std::move(variant_ptr<T, D>(std::static_pointer_cast<T>(ptr))); } else if (e->unique()) { ACTX_ASSERTS(!e->shared()); e->free_unique(); return std::move(variant_ptr<T, D>(std::unique_ptr<T, D>(e))); } else { ACTX_ASSERTS(!e->unique()); ACTX_ASSERTS(!e->shared()); return std::move(variant_ptr<T, D>(e)); } } return std::move(variant_ptr<T, D>()); }
/** * @note Only call in single-consumer thread. */ std::shared_ptr<T> pop_shared() noexcept { auto e = pri_pop(); if (e != nullptr) { ACTX_ASSERTS(e->shared()); ACTX_ASSERTS(!e->unique()); auto ptr = e->free_shared(); ACTX_ASSERTS(!!ptr); return std::move(std::static_pointer_cast<T>(ptr)); } return std::shared_ptr<T>(); }
void alloc_tex() { int i, ow = tex_w, oh = tex_h; for (tex_w = 1; tex_w < width; tex_w <<= 1); for (tex_h = 1; tex_h < height; tex_h <<= 1); if (tex_h != oh || tex_w != ow) { tex = realloc(tex, tex_h * tex_w * 3 + tex_h * sizeof(rgb_t*)); free_shared(SHARED_tex); SHARED_tex = malloc_shared(MIN(tex_h * tex_w * 3, BLOCK_SIZE), tex + tex_h); } for (tex[0] = (rgb_t *)(tex + tex_h), i = 1; i < tex_h; i++) tex[i] = tex[i - 1] + tex_w; }
int main() { int num_threads = 4; int global[num_threads]; int compare[num_threads]; int increment[num_threads]; pthread_t pool[num_threads]; struct args arg_array[num_threads]; int i, j, max = 10; //printf("Incrementing by %d for %d iterations:\n", increment, max); int *SHARED_MEM_global = malloc_shared(num_threads*sizeof(int), &global, LEGUP_RAM_LOCATION_ONCHIP); for (j = 0; j<num_threads;j++) { global[j] = 5; compare[j] = 5; increment[j] = 2*j; } for (i = 0; i<max; i++) { // pre-accelerator copy memcpy_to_shared(SHARED_MEM_global, &global, num_threads*sizeof(int)); // accelerator call for (j = 0; j < num_threads; j++) { struct args tmp = {&SHARED_MEM_global[j], increment[j]}; memcpy(arg_array+j, &tmp, sizeof(tmp)); pthread_create(pool+j, NULL, ByRef_thread, (void *)(arg_array + j)); } for (j = 0; j < num_threads; j++) { pthread_join(pool[j], NULL); } //ByRef(SHARED_MEM_global, increment); // post-accelerator copy memcpy_from_shared(&global, SHARED_MEM_global, num_threads*sizeof(int)); for (j = 0; j < num_threads; j++) { printf("value from thread %d is %d\n", j, global[j]); } } free_shared(SHARED_MEM_global); return 0; }
int main(int argc, char *argv[]){ pid_t pid; // initialize shared memory for IPCs shared_memory(); pid = fork(); switch(pid){ case -1: // process creation failed die("process creation failed"); case 0: // input process pid = fork(); switch(pid){ case -1: // process creation failed die("process creation failed"); case 0: // event key process (input) return eventkey_process(); default: // input process return input_process(); } default: pid = fork(); switch(pid){ case -1: // process creation failed die("process creation failed"); case 0: // output process return output_process(); default: // main process main_process(); } } free_shared(); return 0; }
static int little_unlock(sqlite3_file *file, int lock) { int res; little_file *self = (little_file*)file; trace("LOCK DOWN %s...\n", locktypeName(lock)); switch (lock) { case SQLITE_LOCK_NONE: free_shared(self->name, self->shared_lock_number); flush(self); self->lastblock = -1; self->shared_lock_number = -1; break; case SQLITE_LOCK_SHARED: set_version(self); res = free_exclusive(self->name); if (res < 0) return SQLITE_ERROR; self->shared_lock_number = res; break; default: return SQLITE_ERROR; } trace("LOCK DOWN %s OK\n", locktypeName(lock)); return SQLITE_OK; }
void free_common_ressources(void) { free_semaphores(0); free_shared(0); }
void free_common_ressources_owner(void) { free_semaphores(1); free_shared(1); }