bool f_shm_detach(int64 shm_identifier) { Lock lock(g_shm_mutex); set<sysvshm_shm*>::iterator iter = g_shms.find((sysvshm_shm*)shm_identifier); if (iter == g_shms.end()) { raise_warning("%lld is not a SysV shared memory index", shm_identifier); return false; } g_shms.erase(iter); delete *iter; return true; }
bool f_shm_has_var(int64 shm_identifier, int64 variable_key) { Lock lock(g_shm_mutex); std::set<sysvshm_shm*>::iterator iter = g_shms.find((sysvshm_shm*)shm_identifier); if (iter == g_shms.end()) { raise_warning("%" PRId64 " is not a SysV shared memory index", shm_identifier); return false; } sysvshm_shm *shm_list_ptr = *iter; long shm_varpos = check_shm_data(shm_list_ptr->ptr, variable_key); return shm_varpos >= 0; }
bool f_shm_remove(int64 shm_identifier) { Lock lock(g_shm_mutex); set<sysvshm_shm*>::iterator iter = g_shms.find((sysvshm_shm*)shm_identifier); if (iter == g_shms.end()) { raise_warning("%lld is not a SysV shared memory index", shm_identifier); return false; } sysvshm_shm *shm_list_ptr = *iter; if (shmctl(shm_list_ptr->id, IPC_RMID,NULL) < 0) { raise_warning("failed for key 0x%x, id %lld: %s", shm_list_ptr->key, shm_identifier, Util::safe_strerror(errno).c_str()); return false; } return true; }
bool f_shm_remove_var(int64 shm_identifier, int64 variable_key) { Lock lock(g_shm_mutex); set<sysvshm_shm*>::iterator iter = g_shms.find((sysvshm_shm*)shm_identifier); if (iter == g_shms.end()) { raise_warning("%lld is not a SysV shared memory index", shm_identifier); return false; } sysvshm_shm *shm_list_ptr = *iter; long shm_varpos = check_shm_data(shm_list_ptr->ptr, variable_key); if (shm_varpos < 0) { raise_warning("variable key %lld doesn't exist", variable_key); return false; } remove_shm_data(shm_list_ptr->ptr, shm_varpos); return true; }
Variant f_shm_get_var(int64 shm_identifier, int64 variable_key) { Lock lock(g_shm_mutex); set<sysvshm_shm*>::iterator iter = g_shms.find((sysvshm_shm*)shm_identifier); if (iter == g_shms.end()) { raise_warning("%lld is not a SysV shared memory index", shm_identifier); return false; } sysvshm_shm *shm_list_ptr = *iter; long shm_varpos = check_shm_data(shm_list_ptr->ptr, variable_key); if (shm_varpos < 0) { return false; } sysvshm_chunk *shm_var = (sysvshm_chunk*)((char *)shm_list_ptr->ptr + shm_varpos); return f_unserialize(String(&shm_var->mem, shm_var->length, AttachLiteral)); }
bool f_shm_put_var(int64 shm_identifier, int64 variable_key, CVarRef variable) { Lock lock(g_shm_mutex); set<sysvshm_shm*>::iterator iter = g_shms.find((sysvshm_shm*)shm_identifier); if (iter == g_shms.end()) { raise_warning("%lld is not a SysV shared memory index", shm_identifier); return false; } sysvshm_shm *shm_list_ptr = *iter; /* setup string-variable and serialize */ String serialized = f_serialize(variable); /* insert serialized variable into shared memory */ int ret = put_shm_data(shm_list_ptr->ptr, variable_key, (char*)serialized.data(), serialized.size()); if (ret == -1) { raise_warning("not enough shared memory left"); return false; } return true; }