Skip to content

Commit cf49ace

Browse files
almost finished with the iterator return type. need to test on a few more platforms, and with the qthreads compile flag on. ran into a bug in qthreads on a harpertown intel platform. will check out...appears to hang on a spinlock inside qthreads lib, will check in the AM.
1 parent a77b84b commit cf49ace

File tree

6 files changed

+286
-35
lines changed

6 files changed

+286
-35
lines changed

raftinc/kernel.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "port.hpp"
3030
#include "signalvars.hpp"
3131
#include "rafttypes.hpp"
32+
#include "kernel_wrapper.hpp"
3233

3334
/** pre-declare for friends **/
3435
class MapBase;
@@ -85,11 +86,11 @@ class kernel
8586

8687
template < class T /** kernel type **/,
8788
class ... Args >
88-
static kernel* make( Args&&... params )
89+
static kernel_wrapper make( Args&&... params )
8990
{
9091
auto *output( new T( std::forward< Args >( params )... ) );
9192
output->internal_alloc = true;
92-
return( output );
93+
return( kernel_wrapper( output ) );
9394
}
9495

9596
/**

raftinc/kernel_wrapper.hpp

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/**
2+
* kernel_wrapper.hpp - this class is designed to be used only by the kernel.hpp
3+
* make kernel function. It's supposed to be a wrapper class for the kernel type
4+
* and sub-types. It should ahve a destructor that destroys the wrapped pointer
5+
* on scope exit if it hasn't already been deallocated (attempting to be extra
6+
* safe). Its main function is to provide a syntax marker for the operator >>
7+
* overloads in the kpair.hpp file so that the compiler knows exactly what to
8+
* link to. The other reason for this class's existence is b/c we can't really
9+
* use the move syntax without a complicated copy. The kernel itself cannot live
10+
* on the stack, it must live in the heap or elsewhere.
11+
*
12+
* @author: Jonathan Beard
13+
* @version: Thu Sep 1 16:12:43 2016
14+
*
15+
* Copyright 2016 Jonathan Beard
16+
*
17+
* Licensed under the Apache License, Version 2.0 (the "License");
18+
* you may not use this file except in compliance with the License.
19+
* You may obtain a copy of the License at:
20+
*
21+
* http://www.apache.org/licenses/LICENSE-2.0
22+
*
23+
* Unless required by applicable law or agreed to in writing, software
24+
* distributed under the License is distributed on an "AS IS" BASIS,
25+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26+
* See the License for the specific language governing permissions and
27+
* limitations under the License.
28+
*/
29+
#ifndef _KERNEL_WRAPPER_HPP_
30+
#define _KERNEL_WRAPPER_HPP_ 1
31+
#include <cstdint>
32+
33+
/** pre-declare kpair, header included in cpp file **/
34+
class kpair;
35+
36+
namespace raft
37+
{
38+
39+
/** pre-declare this one too, header in cpp file **/
40+
class kernel;
41+
42+
class kernel_wrapper
43+
{
44+
const static std::uintptr_t sentinel = 0x7070707070707070;
45+
public:
46+
/**
47+
* kernel_wrapper - copy constructor. Takes ownership
48+
* of the kernel wrapped by other, sets other to the
49+
* sentinel value so that it no longer has a valid kernel
50+
* to own, and it also prevents a double free.
51+
* @param other - const kernel_wrapper
52+
*/
53+
kernel_wrapper( const kernel_wrapper &other );
54+
55+
/**
56+
* destructor deletes stored kernel
57+
* if it exits scope...should exit
58+
* scope if it's actually being used
59+
*/
60+
virtual ~kernel_wrapper();
61+
62+
63+
64+
protected:
65+
/**
66+
* kernel_wrapper - constructor for the wrapper
67+
* object, this does exactly what it says and
68+
* sets the wrapper to the parameter kernel.
69+
* @param k - raft::kernel* const
70+
*/
71+
kernel_wrapper( raft::kernel * const k );
72+
73+
/**
74+
* operator * - this function will be used by the
75+
* kpair object when it takes ownership of the
76+
* pointer. This will then be passed to the map
77+
* object. The wrapped pointer will be set with
78+
* the sentinal value so that it isn't double
79+
* freed.
80+
* @return raft::kernel*
81+
*/
82+
raft::kernel* operator * ();
83+
84+
85+
raft::kernel *k = reinterpret_cast< raft::kernel* >( sentinel );
86+
87+
/**
88+
* kernel will need to access the constructor for the
89+
* static make function
90+
*/
91+
friend class kernel;
92+
/**
93+
* kpair will need to access so it can get to the operator*
94+
* overload
95+
*/
96+
friend class ::kpair;
97+
};
98+
99+
}
100+
101+
#endif /* END _KERNEL_WRAPPER_HPP_ */

raftinc/kpair.hpp

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
namespace raft
2929
{
3030
class kernel;
31+
class kernel_wrapper;
3132
class map;
3233
}
3334

@@ -53,16 +54,41 @@ class kpair
5354
raft::kernel &b,
5455
const bool split,
5556
const bool join );
57+
58+
kpair( raft::kernel &a,
59+
raft::kernel_wrapper &b,
60+
const bool split,
61+
const bool join );
62+
63+
kpair( raft::kernel_wrapper &a,
64+
raft::kernel &b,
65+
const bool split,
66+
const bool join );
67+
68+
kpair( raft::kernel_wrapper &a,
69+
raft::kernel_wrapper &b,
70+
const bool split,
71+
const bool join );
5672

5773
kpair( kpair &a,
5874
raft::kernel &b,
5975
const bool split,
6076
const bool join );
77+
78+
kpair( kpair &a,
79+
raft::kernel_wrapper &b,
80+
const bool split,
81+
const bool join );
6182

6283
kpair( raft::kernel &a,
6384
kpair &n,
6485
const bool split,
6586
const bool join );
87+
88+
kpair( raft::kernel_wrapper &a,
89+
kpair &n,
90+
const bool split,
91+
const bool join );
6692

6793
kpair( kpair &a,
6894
kpair &b,
@@ -71,6 +97,15 @@ class kpair
7197

7298
kpair( raft::kernel &a, raft::kernel &b );
7399

100+
kpair( raft::kernel &a,
101+
raft::kernel_wrapper &b );
102+
103+
kpair( raft::kernel_wrapper &a,
104+
raft::kernel &b );
105+
106+
kpair( raft::kernel_wrapper &a,
107+
raft::kernel_wrapper &b );
108+
74109
void setOoO() noexcept;
75110

76111
protected:
@@ -91,44 +126,37 @@ class kpair
91126

92127
bool out_of_order = false;
93128
friend class raft::map;
94-
friend kpair& operator >= ( kpair &a, raft::kernel &&b );
95-
friend kpair& operator >= ( kpair &a, raft::kernel &b );
96-
friend kpair& operator <= ( raft::kernel &a, raft::kernel &b );
97-
friend kpair& operator <= ( raft::kernel &&a, raft::kernel &&b );
98-
friend kpair& operator <= ( raft::kernel &a, kpair &b );
99-
friend kpair& operator <= ( raft::kernel &&a, kpair &b );
100-
friend kpair& operator >= ( kpair &a, kpair &b );
101-
friend kpair& operator >= ( raft::kernel &a, kpair &b );
102-
friend kpair& operator >= ( raft::kernel &&a, kpair &b );
103129
};
104130

105131

106132

107133
kpair& operator >> ( raft::kernel &a, raft::kernel &b );
108-
kpair& operator >> ( raft::kernel &&a, raft::kernel &&b );
134+
kpair& operator >> ( raft::kernel_wrapper &&a, raft::kernel_wrapper &&b );
135+
kpair& operator >> ( raft::kernel &a, raft::kernel_wrapper &&w );
136+
109137
kpair& operator >> ( kpair &a, raft::kernel &b );
110-
kpair& operator >> ( kpair &a, raft::kernel &&b );
138+
kpair& operator >> ( kpair &a, raft::kernel_wrapper &&w );
111139

112140
LOoOkpair& operator >> ( raft::kernel &a, const raft::order::spec &&order );
113141
kpair& operator >> ( LOoOkpair &a, raft::kernel &b );
114-
kpair& operator >> ( LOoOkpair &a, raft::kernel &&b );
142+
kpair& operator >> ( LOoOkpair &a, raft::kernel_wrapper &&w );
115143

116144
ROoOkpair& operator >> ( kpair &a, const raft::order::spec &&order );
117145
kpair& operator >> ( ROoOkpair &a, raft::kernel &b );
118-
kpair& operator >> ( ROoOkpair &a, raft::kernel &&b );
146+
kpair& operator >> ( ROoOkpair &a, raft::kernel_wrapper &&w );
119147

120148

121149
kpair& operator <= ( raft::kernel &a, raft::kernel &b );
122-
kpair& operator <= ( raft::kernel &&a, raft::kernel &&b );
150+
kpair& operator <= ( raft::kernel_wrapper &&a, raft::kernel_wrapper &&b );
123151
kpair& operator <= ( raft::kernel &a, kpair &b );
124-
kpair& operator <= ( raft::kernel &&a, kpair &b );
152+
kpair& operator <= ( raft::kernel_wrapper &&w, kpair &b );
125153

126154
kpair& operator >= ( kpair &a, raft::kernel &b );
127-
kpair& operator >= ( kpair &a, raft::kernel &&b );
155+
kpair& operator >= ( kpair &a, raft::kernel_wrapper &&w );
128156
kpair& operator >= ( kpair &a, kpair &b );
129157

130158
kpair& operator >= ( raft::kernel &a, kpair &b );
131-
kpair& operator >= ( raft::kernel &&a, kpair &b );
159+
kpair& operator >= ( raft::kernel_wrapper &&w, kpair &b );
132160

133161

134162
#endif /* END _KPAIR_HPP_ */

src/kernel_wrapper.cpp

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/**
2+
* kernel_wrapper.cpp -
3+
* @author: Jonathan Beard
4+
* @version: Thu Sep 1 16:12:43 2016
5+
*
6+
* Copyright 2016 Jonathan Beard
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License");
9+
* you may not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at:
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
#include "kernel_wrapper.hpp"
21+
#include "kernel.hpp"
22+
23+
using namespace raft;
24+
25+
kernel_wrapper::kernel_wrapper( raft::kernel * const k ) : k( k ){}
26+
27+
kernel_wrapper::kernel_wrapper( const kernel_wrapper &other ) : k( other.k )
28+
{
29+
/**
30+
* ensures other wrapper no longer valid, also prevents
31+
* double free.
32+
*/
33+
const_cast<kernel_wrapper&>( other ).k
34+
= reinterpret_cast< raft::kernel* >( kernel_wrapper::sentinel );
35+
}
36+
37+
kernel_wrapper::~kernel_wrapper()
38+
{
39+
/**
40+
* check for sentinal value, if it's there..then we don't need
41+
* to delete this one as the map object already has ownership
42+
*/
43+
if( reinterpret_cast< std::uintptr_t >( k ) != kernel_wrapper::sentinel )
44+
{
45+
delete( k );
46+
/**
47+
* set sentinal value just in case this one happens to belong to two
48+
* wrapper objects. It also helps to make sure you can't accidentally
49+
* pass the map an invalid wrapped kernel
50+
*/
51+
k = reinterpret_cast< raft::kernel* >( kernel_wrapper::sentinel );
52+
}
53+
}
54+
55+
raft::kernel* kernel_wrapper::operator *()
56+
57+
58+
{
59+
auto * const ptr( k );
60+
/** reset sentinel value so that the delete doesn't accidentally delete it **/
61+
k = reinterpret_cast< raft::kernel* >( kernel_wrapper::sentinel );
62+
return( ptr );
63+
}

0 commit comments

Comments
 (0)