98
struct pobj_action *act);
void pmemobj_set_value(PMEMobjpool *pop,
struct pobj_action *act, uint64_t *ptr, uint64_t value);
int pmemobj_publish(PMEMobjpool *pop,
struct pobj_action *actv, size_t actvcnt);
void pmemobj_cancel(PMEMobjpool *pop,
struct pobj_action *actv, size_t actvcnt);
Listing 7-6 is a simple banking example that demonstrates how to change multiple
scalars (account balances) before publishing the updates into the pool.
Listing 7-6. Using the reserve/publish API to modify bank account balances
32
33 /*
34 * reserve_publish.c – An example using the
35 *
reserve/publish libpmemobj API
36 */
37
..
44 #define POOL "/mnt/pmem/balance"
45
46 static PMEMobjpool *pool;
47
48 struct account {
49
PMEMoid name;
50
uint64_t balance;
51 };
52 TOID_DECLARE(struct account, 0);
53
..
60 static PMEMoid new_account(const char *name,
61
int deposit)
62 {
63
int len = strlen(name) + 1;
64
65
struct pobj_action act[2];
Chapter 7 libpmemobj: a Native traNsaCtioNal objeCt store
Précédent

- 125/457

Suivant