This repository was archived by the owner on Nov 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Steve Scargall
committed
Jan 11, 2020
1 parent
b21b1f7
commit 3e54843
Showing
98 changed files
with
370 additions
and
431 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
2 changes: 1 addition & 1 deletion
2
chapter3/map_file_windows_example.c → chapter03/map_file_windows_example.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
Oops, something went wrong.