tlds
Transactional Operations for Linked Data Structures
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
BlockOperations.h
Go to the documentation of this file.
1 /**
2  * Copyright (C) 2011
3  * University of Rochester Department of Computer Science
4  * and
5  * Lehigh University Department of Computer Science and Engineering
6  *
7  * License: Modified BSD
8  * Please see the file LICENSE.RSTM for licensing information
9  */
10 
11 #ifndef STM_ITM2STM_BLOCK_OPERATIONS_H
12 #define STM_ITM2STM_BLOCK_OPERATIONS_H
13 
14 #include <cstddef>
15 #include <stdint.h>
16 
17 // -----------------------------------------------------------------------------
18 // These block operations are used in the implementations of all of the memcpy,
19 // memmove, and memset operations. They have a special interface, they return
20 // the number of bytes that they actually read or wrote.
21 //
22 // There are some guarantees.
23 //
24 // 1) The return value will always be smaller than a word.
25 // 2) If ((uint8_t*)from) + bytes fits in an aligned word, all of the bytes
26 // will be written.
27 //
28 // This essentially means that, if you update your to and from cursors based on
29 // the returned size, you can succeed using the following loop.
30 //
31 // TxThread& tx;
32 // size_t block_size;
33 // void* to;
34 // const void* from;
35 // while (block_size) {
36 // size_t bytes_handled = block_write/read(tx, to, from, block_size);
37 // block_size -= bytes_handled;
38 // (uint8_t*)to += bytes_handled;
39 // (uint8_t*)from += bytes_handled;
40 // }
41 //
42 // -----------------------------------------------------------------------------
43 
44 namespace stm {
45 struct TxThread;
46 }
47 
48 namespace itm2stm {
49 size_t block_write(stm::TxThread&, void* target, const void* source, size_t bytes)
50  __attribute__((nonnull));
51 size_t block_read(stm::TxThread&, void* target, const void* source, size_t bytes)
52  __attribute__((nonnull));
53 void block_set(stm::TxThread&, void* target, uint8_t c, size_t bytes)
54  __attribute__((nonnull));
55 
56 // -----------------------------------------------------------------------------
57 // Used as a "binder" for the stm::TxThread& parameter in block_read.
58 // -----------------------------------------------------------------------------
59 struct BlockReader {
61 
63  }
64 
65  inline size_t
66  operator()(void* to, const void* from, size_t length) {
67  return block_read(tx_, to, from, length);
68  }
69 };
70 
71 // -----------------------------------------------------------------------------
72 // Used as a "binder" for the stm::TxThread& parameter in block_write.
73 // -----------------------------------------------------------------------------
74 struct BlockWriter {
77  }
78 
79  inline size_t
80  operator()(void* to, const void* from, size_t length) {
81  return block_write(tx_, to, from, length);
82  }
83 };
84 }
85 
86 #endif // STM_ITM2STM_BLOCK_OPERATIONS_H
size_t block_read(stm::TxThread &, void *target, const void *source, size_t bytes) __attribute__((nonnull))
Definition: BlockOperations.cpp:79
Definition: stm_fraser.c:61
Definition: BlockOperations.h:59
size_t operator()(void *to, const void *from, size_t length)
Definition: BlockOperations.h:66
size_t operator()(void *to, const void *from, size_t length)
Definition: BlockOperations.h:80
stm::TxThread & tx_
Definition: BlockOperations.h:60
class simple_queue __attribute__
BlockReader(stm::TxThread &tx)
Definition: BlockOperations.h:62
size_t block_write(stm::TxThread &, void *target, const void *source, size_t bytes) __attribute__((nonnull))
Definition: BlockOperations.cpp:145
stm_tx * tx
Definition: stmskip.cc:245
Definition: txthread.hpp:47
Definition: BlockOperations.h:74
BlockWriter(stm::TxThread &tx)
Definition: BlockOperations.h:76
stm::TxThread & tx_
Definition: BlockOperations.h:75
void block_set(stm::TxThread &, void *target, uint8_t c, size_t bytes) __attribute__((nonnull))
Definition: BlockOperations.cpp:197