public static void sched_setaffinity(final BitSet affinity) { final CLibrary lib = CLibrary.INSTANCE; final cpu_set_t cpuset = new cpu_set_t(); final int size = version.isSameOrNewer(VERSION_2_6) ? cpu_set_t.SIZE_OF_CPU_SET_T : NativeLong.SIZE; final long[] bits = affinity.toLongArray(); for (int i = 0; i < bits.length; i++) { if (Platform.is64Bit()) { cpuset.__bits[i].setValue(bits[i]); } else { cpuset.__bits[i * 2].setValue(bits[i] & 0xFFFFFFFFL); cpuset.__bits[i * 2 + 1].setValue((bits[i] >>> 32) & 0xFFFFFFFFL); } } try { if (lib.sched_setaffinity(0, size, cpuset) != 0) { throw new IllegalStateException( "sched_setaffinity(0, " + size + ", 0x" + Utilities.toHexString(affinity) + ") failed; errno=" + Native.getLastError()); } } catch (LastErrorException e) { throw new IllegalStateException( "sched_setaffinity(0, " + size + ", 0x" + Utilities.toHexString(affinity) + ") failed; errno=" + e.getErrorCode(), e); } }
public <T> UpdateResults<T> update(T ent, UpdateOperations<T> ops) { MappedClass mc = mapr.getMappedClass(ent); Query<T> q = (Query<T>) createQuery(mc.getClazz()); q.disableValidation().filter(Mapper.ID_KEY, getId(ent)); if (mc.getFieldsAnnotatedWith(Version.class).size() > 0) { MappedField versionMF = mc.getFieldsAnnotatedWith(Version.class).get(0); Long oldVer = (Long) versionMF.getFieldValue(ent); q.filter(versionMF.getNameToStore(), oldVer); ops.set(versionMF.getNameToStore(), VersionHelper.nextValue(oldVer)); } return update(q, ops); }
public static @NotNull cpu_set_t sched_getaffinity() { final CLibrary lib = CLibrary.INSTANCE; final cpu_set_t cpuset = new cpu_set_t(); final int size = version.isSameOrNewer(VERSION_2_6) ? cpu_set_t.SIZE_OF_CPU_SET_T : NativeLong.SIZE; try { if (lib.sched_getaffinity(0, size, cpuset) != 0) { throw new IllegalStateException( "sched_getaffinity(0, " + size + ", cpuset) failed; errno=" + Native.getLastError()); } } catch (LastErrorException e) { throw new IllegalStateException( "sched_getaffinity(0, (" + size + ") , cpuset) failed; errno=" + e.getErrorCode(), e); } return cpuset; }
protected <T> WriteResult tryVersionedUpdate( DBCollection dbColl, T entity, DBObject dbObj, WriteConcern wc, DB db, MappedClass mc) { WriteResult wr = null; if (mc.getFieldsAnnotatedWith(Version.class).isEmpty()) return wr; MappedField mfVersion = mc.getFieldsAnnotatedWith(Version.class).get(0); String versionKeyName = mfVersion.getNameToStore(); Long oldVersion = (Long) mfVersion.getFieldValue(entity); long newVersion = VersionHelper.nextValue(oldVersion); dbObj.put(versionKeyName, newVersion); if (oldVersion != null && oldVersion > 0) { Object idValue = dbObj.get(Mapper.ID_KEY); UpdateResults<T> res = update( find((Class<T>) entity.getClass(), Mapper.ID_KEY, idValue) .filter(versionKeyName, oldVersion), dbObj, false, false, wc); wr = res.getWriteResult(); if (res.getUpdatedCount() != 1) throw new ConcurrentModificationException( "Entity of class " + entity.getClass().getName() + " (id='" + idValue + "',version='" + oldVersion + "') was concurrently updated."); } else if (wc == null) wr = dbColl.save(dbObj); else wr = dbColl.save(dbObj, wc); // update the version. mfVersion.setFieldValue(entity, newVersion); return wr; }
@Override public String getCatalogVersion() { return version.getVersion(); }