static void test_atomic_flag(void) { pg_atomic_flag flag; pg_atomic_init_flag(&flag); if (!pg_atomic_unlocked_test_flag(&flag)) elog(ERROR, "flag: unexpectedly set"); if (!pg_atomic_test_set_flag(&flag)) elog(ERROR, "flag: couldn't set"); if (pg_atomic_unlocked_test_flag(&flag)) elog(ERROR, "flag: unexpectedly unset"); if (pg_atomic_test_set_flag(&flag)) elog(ERROR, "flag: set spuriously #2"); pg_atomic_clear_flag(&flag); if (!pg_atomic_unlocked_test_flag(&flag)) elog(ERROR, "flag: unexpectedly set #2"); if (!pg_atomic_test_set_flag(&flag)) elog(ERROR, "flag: couldn't set"); pg_atomic_clear_flag(&flag); }
void cfs_initialize() { cfs_state = (CfsState*)ShmemAlloc(sizeof(CfsState)); pg_atomic_init_flag(&cfs_state->gc_started); if (cfs_encryption) { cfs_rc4_init(); } elog(LOG, "Start CFS version %s compression algorithm %s encryption %s", CFS_VERSION, cfs_algorithm(), cfs_encryption ? "enabled" : "disabled"); }
/* * IPCMessageBrokerShmemInit */ void IPCMessageBrokerShmemInit(void) { bool found; Size size = IPCMessageBrokerShmemSize(); LWLockAcquire(IPCMessageBrokerIndexLock, LW_EXCLUSIVE); broker_meta = ShmemInitStruct("BrokerMeta", size, &found); if (!found) { HASHCTL ctl; int i; MemSet(broker_meta, 0, size); pg_atomic_init_flag(&broker_meta->waiting); MemSet(&ctl, 0, sizeof(HASHCTL)); ctl.keysize = sizeof(Oid); ctl.entrysize = broker_db_meta_size; ctl.hash = oid_hash; broker_meta->db_meta_hash = ShmemInitHash("BrokerDBMetaHash", 4, 16, &ctl, HASH_ELEM | HASH_FUNCTION); /* Initialize LWLocks that we'll use for all IPC queues */ broker_meta->tranche_id = LWLockNewTrancheId(); broker_meta->tranche.name = "BrokerMetaLWLocks"; broker_meta->tranche.array_base = (void *) broker_meta->locks; broker_meta->tranche.array_stride = sizeof(lw_lock_slot); for (i = 0; i < max_worker_processes; i++) { lw_lock_slot *slot = &broker_meta->locks[i]; LWLockInitialize(&slot->lock, broker_meta->tranche_id); slot->dbid = InvalidOid; } } LWLockRelease(IPCMessageBrokerIndexLock); LWLockRegisterTranche(broker_meta->tranche_id, &broker_meta->tranche); }