Skip to content

Commit 3e54843

Browse files
author
Steve Scargall
committed
Updated copyright to 2020
1 parent b21b1f7 commit 3e54843

File tree

98 files changed

+370
-431
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+370
-431
lines changed

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
BSD 3-Clause License
22

3-
Copyright (c) 2019, Persistent Memory Programming
3+
Copyright (c) 2020, Persistent Memory Programming
44
All rights reserved.
55

66
Redistribution and use in source and binary forms, with or without

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Apress Source Code
22

3-
This repository accompanies *Programming Persistent Memory - A Comprehensive Guide for Developers* by Steve Scargall (Apress, 2019).
3+
This repository accompanies *Programming Persistent Memory - A Comprehensive Guide for Developers* by Steve Scargall (Apress, 2020).
44

55
[comment]: #cover
66
![Cover image](FrontCover.png)
File renamed without changes.

chapter1/Makefile renamed to chapter01/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2019, Intel Corporation
1+
# Copyright (c) 2020, Intel Corporation
22
#
33
# Redistribution and use in source and binary forms, with or without
44
# modification, are permitted provided that the following conditions
File renamed without changes.

chapter1/pmemkv.cpp renamed to chapter01/pmemkv.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, Intel Corporation
2+
* Copyright (c) 2020, Intel Corporation
33
*
44
* Redistribution and use in source and binary forms, with or without
55
* modification, are permitted provided that the following conditions
File renamed without changes.
File renamed without changes.

chapter3/Makefile renamed to chapter03/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2019, Intel Corporation
1+
# Copyright (c) 2020, Intel Corporation
22
#
33
# Redistribution and use in source and binary forms, with or without
44
# modification, are permitted provided that the following conditions
File renamed without changes.

chapter03/Windows_Get-PmemDisk.out

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
PS C:\Users\Administrator> Get-PmemDisk
2+
3+
Number Size Health Atomicity Removable Physical device IDs Unsafe shutdowns
4+
------ ---- ------ --------- --------- ------------------- ----------------
5+
2 249 GB Healthy None True {1} 36
6+
7+
8+
PS C:\Users\Administrator> Get-Disk 2 | Get-Partition
9+
10+
PartitionNumber DriveLetter Offset Size Type
11+
--------------- ----------- ------ ---- ----
12+
1 24576 15.98 MB Reserved
13+
2 D 16777216 248.98 GB Basic
File renamed without changes.
File renamed without changes.
File renamed without changes.

chapter3/map_file_windows_example.c renamed to chapter03/map_file_windows_example.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, Intel Corporation
2+
* Copyright (c) 2020, Intel Corporation
33
*
44
* Redistribution and use in source and binary forms, with or without
55
* modification, are permitted provided that the following conditions

chapter3/mmap_example.c renamed to chapter03/mmap_example.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, Intel Corporation
2+
* Copyright (c) 2020, Intel Corporation
33
*
44
* Redistribution and use in source and binary forms, with or without
55
* modification, are permitted provided that the following conditions
File renamed without changes.

chapter3/pmem_map_file.c renamed to chapter03/pmem_map_file.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, Intel Corporation
2+
* Copyright (c) 2020, Intel Corporation
33
*
44
* Redistribution and use in source and binary forms, with or without
55
* modification, are permitted provided that the following conditions
File renamed without changes.
File renamed without changes.
File renamed without changes.

chapter6/Makefile renamed to chapter06/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2019, Intel Corporation
1+
# Copyright (c) 2020, Intel Corporation
22
#
33
# Redistribution and use in source and binary forms, with or without
44
# modification, are permitted provided that the following conditions
File renamed without changes.
File renamed without changes.

chapter6/manpage.c renamed to chapter06/manpage.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, Intel Corporation
2+
* Copyright (c) 2020, Intel Corporation
33
*
44
* Redistribution and use in source and binary forms, with or without
55
* modification, are permitted provided that the following conditions

chapter6/simple_copy.c renamed to chapter06/simple_copy.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, Intel Corporation
2+
* Copyright (c) 2020, Intel Corporation
33
*
44
* Redistribution and use in source and binary forms, with or without
55
* modification, are permitted provided that the following conditions

chapter7/Makefile renamed to chapter07/Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright 2015-2019, Intel Corporation
2+
# Copyright 2015-2020, Intel Corporation
33
#
44
# Redistribution and use in source and binary forms, with or without
55
# modification, are permitted provided that the following conditions
@@ -34,7 +34,7 @@ CC = gcc
3434
CXX = g++
3535
RM = rm -f
3636

37-
TARGETS = pwriter preader
37+
TARGETS = pwriter preader pmemobj_alloc.c reserve_publish.c tx.c
3838
TARGETS_LISTINGS = $(addsuffix .lst, $(TARGETS))
3939

4040
LIBS = -lpmemobj -lpmem -lpthread
File renamed without changes.

chapter07/pmemobj_alloc.c

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Copyright 2015-2020, Intel Corporation
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions
6+
* are met:
7+
*
8+
* * Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
*
11+
* * Redistributions in binary form must reproduce the above copyright
12+
* notice, this list of conditions and the following disclaimer in
13+
* the documentation and/or other materials provided with the
14+
* distribution.
15+
*
16+
* * Neither the name of the copyright holder nor the names of its
17+
* contributors may be used to endorse or promote products derived
18+
* from this software without specific prior written permission.
19+
*
20+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
*/
32+
33+
/*
34+
* pmemobj_alloc.c - An example to show how to use
35+
* pmemobj_alloc()
36+
*/
37+
38+
#include <stdio.h>
39+
#include <unistd.h>
40+
#include <stdlib.h>
41+
#include <libpmemobj.h>
42+
43+
#define die(...) do {fprintf(stderr, __VA_ARGS__); exit(1);} while(0)
44+
#define POOL "/mnt/pmem/paintball"
45+
#define LAYOUT "paintball"
46+
47+
typedef uint32_t color;
48+
49+
static int paintball_init(PMEMobjpool *pop, void *ptr, void *arg)
50+
{
51+
*(color *)ptr = time(0) & 0xffffff;
52+
pmemobj_persist(pop, ptr, sizeof(color));
53+
return 0;
54+
}
55+
56+
int main()
57+
{
58+
PMEMobjpool *pool = pmemobj_open(POOL, LAYOUT);
59+
if (!pool) {
60+
pool = pmemobj_create(POOL, LAYOUT, PMEMOBJ_MIN_POOL, 0666);
61+
if (!pool)
62+
die("Couldn't open pool: %m\n");
63+
64+
}
65+
PMEMoid root = pmemobj_root(pool, sizeof(PMEMoid) * 6);
66+
if (OID_IS_NULL(root))
67+
die("Couldn't access root object.\n");
68+
69+
PMEMoid *chamber = (PMEMoid *)pmemobj_direct(root) + (getpid() % 6);
70+
if (OID_IS_NULL(*chamber)) {
71+
printf("Reloading.\n");
72+
if (pmemobj_alloc(pool, chamber, sizeof(color), 0, paintball_init, 0))
73+
die("Failed to alloc: %m\n");
74+
} else {
75+
printf("Shooting %06x colored bullet.\n", *(color *)pmemobj_direct(*chamber));
76+
pmemobj_free(chamber);
77+
}
78+
79+
pmemobj_close(pool);
80+
return 0;
81+
}

chapter7/preader.c renamed to chapter07/preader.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015-2019, Intel Corporation
2+
* Copyright 2015-2020, Intel Corporation
33
*
44
* Redistribution and use in source and binary forms, with or without
55
* modification, are permitted provided that the following conditions

chapter7/pwriter.c renamed to chapter07/pwriter.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015-2019, Intel Corporation
2+
* Copyright 2015-2020, Intel Corporation
33
*
44
* Redistribution and use in source and binary forms, with or without
55
* modification, are permitted provided that the following conditions

chapter07/reserve_publish.c

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*
2+
* Copyright 2015-2020, Intel Corporation
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions
6+
* are met:
7+
*
8+
* * Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
*
11+
* * Redistributions in binary form must reproduce the above copyright
12+
* notice, this list of conditions and the following disclaimer in
13+
* the documentation and/or other materials provided with the
14+
* distribution.
15+
*
16+
* * Neither the name of the copyright holder nor the names of its
17+
* contributors may be used to endorse or promote products derived
18+
* from this software without specific prior written permission.
19+
*
20+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
*/
32+
33+
/*
34+
* reserve_publish.c – An example using the
35+
* reserve/publish libpmemobj API
36+
*/
37+
38+
#include <stdio.h>
39+
#include <unistd.h>
40+
#include <stdlib.h>
41+
#include <libpmemobj.h>
42+
43+
#define die(...) do {fprintf(stderr, __VA_ARGS__); exit(1);} while(0)
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+
54+
/*
55+
* Even though we return the oid in a volatile register, there's no
56+
* persistent leak as all "struct account" (type 1) allocations are
57+
* reachable via POBJ_FOREACH_TYPE().
58+
*/
59+
static PMEMoid new_account(const char *name, int deposit)
60+
{
61+
int len = strlen(name) + 1;
62+
63+
struct pobj_action act[2];
64+
PMEMoid str = pmemobj_reserve(pool, act + 0, len, 0);
65+
if (OID_IS_NULL(str))
66+
die("Can't allocate string: %m\n");
67+
/*
68+
* memcpy below must flush, but doesn't need to drain -- even just a
69+
* single drain after all flushes is enough.
70+
*/
71+
pmemobj_memcpy(pool, pmemobj_direct(str), name, len, PMEMOBJ_F_MEM_NODRAIN);
72+
TOID(struct account) acc;
73+
PMEMoid acc_oid = pmemobj_reserve(pool, act + 1, sizeof(struct account), 1);
74+
TOID_ASSIGN(acc, acc_oid);
75+
if (TOID_IS_NULL(acc))
76+
die("Can't allocate account: %m\n");
77+
D_RW(acc)->name = str;
78+
D_RW(acc)->balance = deposit;
79+
pmemobj_persist(pool, D_RW(acc), sizeof(struct account));
80+
pmemobj_publish(pool, act, 2);
81+
return acc_oid;
82+
}
83+
84+
int main()
85+
{
86+
if (!(pool = pmemobj_create(POOL, "", PMEMOBJ_MIN_POOL, 0600)))
87+
die("Can't create pool “%s”: %m\n", POOL);
88+
89+
TOID(struct account) account_a, account_b;
90+
TOID_ASSIGN(account_a, new_account("Julius Caesar", 100));
91+
TOID_ASSIGN(account_b, new_account("Mark Anthony", 50));
92+
93+
int price = 42;
94+
struct pobj_action act[2];
95+
pmemobj_set_value(pool, &act[0], &D_RW(account_a)->balance, D_RW(account_a)->balance - price);
96+
pmemobj_set_value(pool, &act[1], &D_RW(account_b)->balance, D_RW(account_b)->balance + price);
97+
pmemobj_publish(pool, act, 2);
98+
99+
pmemobj_close(pool);
100+
return 0;
101+
}

0 commit comments

Comments
 (0)