Skip to content
This repository was archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
Updated copyright to 2020
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve Scargall committed Jan 11, 2020
1 parent b21b1f7 commit 3e54843
Show file tree
Hide file tree
Showing 98 changed files with 370 additions and 431 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BSD 3-Clause License

Copyright (c) 2019, Persistent Memory Programming
Copyright (c) 2020, Persistent Memory Programming
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Apress Source Code

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

[comment]: #cover
![Cover image](FrontCover.png)
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion chapter1/Makefile → chapter01/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2019, Intel Corporation
# Copyright (c) 2020, Intel Corporation
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion chapter1/pmemkv.cpp → chapter01/pmemkv.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, Intel Corporation
* Copyright (c) 2020, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion chapter3/Makefile → chapter03/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2019, Intel Corporation
# Copyright (c) 2020, Intel Corporation
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
Expand Down
File renamed without changes.
13 changes: 13 additions & 0 deletions chapter03/Windows_Get-PmemDisk.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
PS C:\Users\Administrator> Get-PmemDisk

Number Size Health Atomicity Removable Physical device IDs Unsafe shutdowns
------ ---- ------ --------- --------- ------------------- ----------------
2 249 GB Healthy None True {1} 36


PS C:\Users\Administrator> Get-Disk 2 | Get-Partition

PartitionNumber DriveLetter Offset Size Type
--------------- ----------- ------ ---- ----
1 24576 15.98 MB Reserved
2 D 16777216 248.98 GB Basic
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, Intel Corporation
* Copyright (c) 2020, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
Expand Down
2 changes: 1 addition & 1 deletion chapter3/mmap_example.c → chapter03/mmap_example.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, Intel Corporation
* Copyright (c) 2020, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion chapter3/pmem_map_file.c → chapter03/pmem_map_file.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, Intel Corporation
* Copyright (c) 2020, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion chapter6/Makefile → chapter06/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2019, Intel Corporation
# Copyright (c) 2020, Intel Corporation
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion chapter6/manpage.c → chapter06/manpage.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, Intel Corporation
* Copyright (c) 2020, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
Expand Down
2 changes: 1 addition & 1 deletion chapter6/simple_copy.c → chapter06/simple_copy.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, Intel Corporation
* Copyright (c) 2020, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
Expand Down
4 changes: 2 additions & 2 deletions chapter7/Makefile → chapter07/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2015-2019, Intel Corporation
# Copyright 2015-2020, Intel Corporation
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -34,7 +34,7 @@ CC = gcc
CXX = g++
RM = rm -f

TARGETS = pwriter preader
TARGETS = pwriter preader pmemobj_alloc.c reserve_publish.c tx.c
TARGETS_LISTINGS = $(addsuffix .lst, $(TARGETS))

LIBS = -lpmemobj -lpmem -lpthread
Expand Down
File renamed without changes.
81 changes: 81 additions & 0 deletions chapter07/pmemobj_alloc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright 2015-2020, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

/*
* pmemobj_alloc.c - An example to show how to use
* pmemobj_alloc()
*/

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <libpmemobj.h>

#define die(...) do {fprintf(stderr, __VA_ARGS__); exit(1);} while(0)
#define POOL "/mnt/pmem/paintball"
#define LAYOUT "paintball"

typedef uint32_t color;

static int paintball_init(PMEMobjpool *pop, void *ptr, void *arg)
{
*(color *)ptr = time(0) & 0xffffff;
pmemobj_persist(pop, ptr, sizeof(color));
return 0;
}

int main()
{
PMEMobjpool *pool = pmemobj_open(POOL, LAYOUT);
if (!pool) {
pool = pmemobj_create(POOL, LAYOUT, PMEMOBJ_MIN_POOL, 0666);
if (!pool)
die("Couldn't open pool: %m\n");

}
PMEMoid root = pmemobj_root(pool, sizeof(PMEMoid) * 6);
if (OID_IS_NULL(root))
die("Couldn't access root object.\n");

PMEMoid *chamber = (PMEMoid *)pmemobj_direct(root) + (getpid() % 6);
if (OID_IS_NULL(*chamber)) {
printf("Reloading.\n");
if (pmemobj_alloc(pool, chamber, sizeof(color), 0, paintball_init, 0))
die("Failed to alloc: %m\n");
} else {
printf("Shooting %06x colored bullet.\n", *(color *)pmemobj_direct(*chamber));
pmemobj_free(chamber);
}

pmemobj_close(pool);
return 0;
}
2 changes: 1 addition & 1 deletion chapter7/preader.c → chapter07/preader.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2019, Intel Corporation
* Copyright 2015-2020, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
Expand Down
2 changes: 1 addition & 1 deletion chapter7/pwriter.c → chapter07/pwriter.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2019, Intel Corporation
* Copyright 2015-2020, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
Expand Down
101 changes: 101 additions & 0 deletions chapter07/reserve_publish.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* Copyright 2015-2020, Intel Corporation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

/*
* reserve_publish.c – An example using the
* reserve/publish libpmemobj API
*/

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <libpmemobj.h>

#define die(...) do {fprintf(stderr, __VA_ARGS__); exit(1);} while(0)
#define POOL "/mnt/pmem/balance"

static PMEMobjpool *pool;

struct account {
PMEMoid name;
uint64_t balance;
};
TOID_DECLARE(struct account, 0);

/*
* Even though we return the oid in a volatile register, there's no
* persistent leak as all "struct account" (type 1) allocations are
* reachable via POBJ_FOREACH_TYPE().
*/
static PMEMoid new_account(const char *name, int deposit)
{
int len = strlen(name) + 1;

struct pobj_action act[2];
PMEMoid str = pmemobj_reserve(pool, act + 0, len, 0);
if (OID_IS_NULL(str))
die("Can't allocate string: %m\n");
/*
* memcpy below must flush, but doesn't need to drain -- even just a
* single drain after all flushes is enough.
*/
pmemobj_memcpy(pool, pmemobj_direct(str), name, len, PMEMOBJ_F_MEM_NODRAIN);
TOID(struct account) acc;
PMEMoid acc_oid = pmemobj_reserve(pool, act + 1, sizeof(struct account), 1);
TOID_ASSIGN(acc, acc_oid);
if (TOID_IS_NULL(acc))
die("Can't allocate account: %m\n");
D_RW(acc)->name = str;
D_RW(acc)->balance = deposit;
pmemobj_persist(pool, D_RW(acc), sizeof(struct account));
pmemobj_publish(pool, act, 2);
return acc_oid;
}

int main()
{
if (!(pool = pmemobj_create(POOL, "", PMEMOBJ_MIN_POOL, 0600)))
die("Can't create pool “%s”: %m\n", POOL);

TOID(struct account) account_a, account_b;
TOID_ASSIGN(account_a, new_account("Julius Caesar", 100));
TOID_ASSIGN(account_b, new_account("Mark Anthony", 50));

int price = 42;
struct pobj_action act[2];
pmemobj_set_value(pool, &act[0], &D_RW(account_a)->balance, D_RW(account_a)->balance - price);
pmemobj_set_value(pool, &act[1], &D_RW(account_b)->balance, D_RW(account_b)->balance + price);
pmemobj_publish(pool, act, 2);

pmemobj_close(pool);
return 0;
}
Loading

0 comments on commit 3e54843

Please sign in to comment.