Skip to content

Commit 1d0334f

Browse files
committed
Merge pull request opencv#19584 from diablodale:fix19573_ocl_move
2 parents 6c57428 + 96a1543 commit 1d0334f

File tree

4 files changed

+311
-7
lines changed

4 files changed

+311
-7
lines changed

modules/core/include/opencv2/core/ocl.hpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ class CV_EXPORTS_W_SIMPLE Device
7474
explicit Device(void* d);
7575
Device(const Device& d);
7676
Device& operator = (const Device& d);
77+
Device(Device&& d) CV_NOEXCEPT;
78+
Device& operator = (Device&& d) CV_NOEXCEPT;
7779
CV_WRAP ~Device();
7880

7981
void set(void* d);
@@ -250,6 +252,8 @@ class CV_EXPORTS Context
250252
~Context();
251253
Context(const Context& c);
252254
Context& operator= (const Context& c);
255+
Context(Context&& c) CV_NOEXCEPT;
256+
Context& operator = (Context&& c) CV_NOEXCEPT;
253257

254258
/** @deprecated */
255259
bool create();
@@ -302,6 +306,8 @@ class CV_EXPORTS Platform
302306
~Platform();
303307
Platform(const Platform& p);
304308
Platform& operator = (const Platform& p);
309+
Platform(Platform&& p) CV_NOEXCEPT;
310+
Platform& operator = (Platform&& p) CV_NOEXCEPT;
305311

306312
void* ptr() const;
307313

@@ -362,6 +368,8 @@ class CV_EXPORTS Queue
362368
~Queue();
363369
Queue(const Queue& q);
364370
Queue& operator = (const Queue& q);
371+
Queue(Queue&& q) CV_NOEXCEPT;
372+
Queue& operator = (Queue&& q) CV_NOEXCEPT;
365373

366374
bool create(const Context& c=Context(), const Device& d=Device());
367375
void finish();
@@ -384,7 +392,7 @@ class CV_EXPORTS KernelArg
384392
public:
385393
enum { LOCAL=1, READ_ONLY=2, WRITE_ONLY=4, READ_WRITE=6, CONSTANT=8, PTR_ONLY = 16, NO_SIZE=256 };
386394
KernelArg(int _flags, UMat* _m, int wscale=1, int iwscale=1, const void* _obj=0, size_t _sz=0);
387-
KernelArg();
395+
KernelArg() CV_NOEXCEPT;
388396

389397
static KernelArg Local(size_t localMemSize)
390398
{ return KernelArg(LOCAL, 0, 1, 1, 0, localMemSize); }
@@ -428,6 +436,8 @@ class CV_EXPORTS Kernel
428436
~Kernel();
429437
Kernel(const Kernel& k);
430438
Kernel& operator = (const Kernel& k);
439+
Kernel(Kernel&& k) CV_NOEXCEPT;
440+
Kernel& operator = (Kernel&& k) CV_NOEXCEPT;
431441

432442
bool empty() const;
433443
bool create(const char* kname, const Program& prog);
@@ -502,8 +512,9 @@ class CV_EXPORTS Program
502512
Program(const ProgramSource& src,
503513
const String& buildflags, String& errmsg);
504514
Program(const Program& prog);
505-
506515
Program& operator = (const Program& prog);
516+
Program(Program&& prog) CV_NOEXCEPT;
517+
Program& operator = (Program&& prog) CV_NOEXCEPT;
507518
~Program();
508519

509520
bool create(const ProgramSource& src,
@@ -551,6 +562,8 @@ class CV_EXPORTS ProgramSource
551562
~ProgramSource();
552563
ProgramSource(const ProgramSource& prog);
553564
ProgramSource& operator = (const ProgramSource& prog);
565+
ProgramSource(ProgramSource&& prog) CV_NOEXCEPT;
566+
ProgramSource& operator = (ProgramSource&& prog) CV_NOEXCEPT;
554567

555568
const String& source() const; // deprecated
556569
hash_t hash() const; // deprecated
@@ -623,6 +636,8 @@ class CV_EXPORTS PlatformInfo
623636

624637
PlatformInfo(const PlatformInfo& i);
625638
PlatformInfo& operator =(const PlatformInfo& i);
639+
PlatformInfo(PlatformInfo&& i) CV_NOEXCEPT;
640+
PlatformInfo& operator = (PlatformInfo&& i) CV_NOEXCEPT;
626641

627642
String name() const;
628643
String vendor() const;
@@ -683,7 +698,7 @@ CV_EXPORTS void buildOptionsAddMatrixDescription(String& buildOptions, const Str
683698
class CV_EXPORTS Image2D
684699
{
685700
public:
686-
Image2D();
701+
Image2D() CV_NOEXCEPT;
687702

688703
/**
689704
@param src UMat object from which to get image properties and data
@@ -696,6 +711,8 @@ class CV_EXPORTS Image2D
696711
~Image2D();
697712

698713
Image2D & operator = (const Image2D & i);
714+
Image2D(Image2D &&) CV_NOEXCEPT;
715+
Image2D &operator=(Image2D &&) CV_NOEXCEPT;
699716

700717
/** Indicates if creating an aliased image should succeed.
701718
Depends on the underlying platform and the dimensions of the UMat.

modules/core/src/ocl.cpp

Lines changed: 155 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,6 +1480,23 @@ Platform& Platform::operator = (const Platform& pl)
14801480
return *this;
14811481
}
14821482

1483+
Platform::Platform(Platform&& pl) CV_NOEXCEPT
1484+
{
1485+
p = pl.p;
1486+
pl.p = nullptr;
1487+
}
1488+
1489+
Platform& Platform::operator = (Platform&& pl) CV_NOEXCEPT
1490+
{
1491+
if (this != &pl) {
1492+
if(p)
1493+
p->release();
1494+
p = pl.p;
1495+
pl.p = nullptr;
1496+
}
1497+
return *this;
1498+
}
1499+
14831500
void* Platform::ptr() const
14841501
{
14851502
return p ? p->handle : 0;
@@ -1706,6 +1723,23 @@ Device& Device::operator = (const Device& d)
17061723
return *this;
17071724
}
17081725

1726+
Device::Device(Device&& d) CV_NOEXCEPT
1727+
{
1728+
p = d.p;
1729+
d.p = nullptr;
1730+
}
1731+
1732+
Device& Device::operator = (Device&& d) CV_NOEXCEPT
1733+
{
1734+
if (this != &d) {
1735+
if(p)
1736+
p->release();
1737+
p = d.p;
1738+
d.p = nullptr;
1739+
}
1740+
return *this;
1741+
}
1742+
17091743
Device::~Device()
17101744
{
17111745
if(p)
@@ -2919,6 +2953,23 @@ Context& Context::operator = (const Context& c)
29192953
return *this;
29202954
}
29212955

2956+
Context::Context(Context&& c) CV_NOEXCEPT
2957+
{
2958+
p = c.p;
2959+
c.p = nullptr;
2960+
}
2961+
2962+
Context& Context::operator = (Context&& c) CV_NOEXCEPT
2963+
{
2964+
if (this != &c) {
2965+
if(p)
2966+
p->release();
2967+
p = c.p;
2968+
c.p = nullptr;
2969+
}
2970+
return *this;
2971+
}
2972+
29222973
void* Context::ptr() const
29232974
{
29242975
return p == NULL ? NULL : p->handle;
@@ -3260,6 +3311,23 @@ Queue& Queue::operator = (const Queue& q)
32603311
return *this;
32613312
}
32623313

3314+
Queue::Queue(Queue&& q) CV_NOEXCEPT
3315+
{
3316+
p = q.p;
3317+
q.p = nullptr;
3318+
}
3319+
3320+
Queue& Queue::operator = (Queue&& q) CV_NOEXCEPT
3321+
{
3322+
if (this != &q) {
3323+
if(p)
3324+
p->release();
3325+
p = q.p;
3326+
q.p = nullptr;
3327+
}
3328+
return *this;
3329+
}
3330+
32633331
Queue::~Queue()
32643332
{
32653333
if(p)
@@ -3315,7 +3383,7 @@ static cl_command_queue getQueue(const Queue& q)
33153383

33163384
/////////////////////////////////////////// KernelArg /////////////////////////////////////////////
33173385

3318-
KernelArg::KernelArg()
3386+
KernelArg::KernelArg() CV_NOEXCEPT
33193387
: flags(0), m(0), obj(0), sz(0), wscale(1), iwscale(1)
33203388
{
33213389
}
@@ -3493,6 +3561,23 @@ Kernel& Kernel::operator = (const Kernel& k)
34933561
return *this;
34943562
}
34953563

3564+
Kernel::Kernel(Kernel&& k) CV_NOEXCEPT
3565+
{
3566+
p = k.p;
3567+
k.p = nullptr;
3568+
}
3569+
3570+
Kernel& Kernel::operator = (Kernel&& k) CV_NOEXCEPT
3571+
{
3572+
if (this != &k) {
3573+
if(p)
3574+
p->release();
3575+
p = k.p;
3576+
k.p = nullptr;
3577+
}
3578+
return *this;
3579+
}
3580+
34963581
Kernel::~Kernel()
34973582
{
34983583
if(p)
@@ -4091,6 +4176,23 @@ ProgramSource& ProgramSource::operator = (const ProgramSource& prog)
40914176
return *this;
40924177
}
40934178

4179+
ProgramSource::ProgramSource(ProgramSource&& prog) CV_NOEXCEPT
4180+
{
4181+
p = prog.p;
4182+
prog.p = nullptr;
4183+
}
4184+
4185+
ProgramSource& ProgramSource::operator = (ProgramSource&& prog) CV_NOEXCEPT
4186+
{
4187+
if (this != &prog) {
4188+
if(p)
4189+
p->release();
4190+
p = prog.p;
4191+
prog.p = nullptr;
4192+
}
4193+
return *this;
4194+
}
4195+
40944196
const String& ProgramSource::source() const
40954197
{
40964198
CV_Assert(p);
@@ -4586,6 +4688,23 @@ Program& Program::operator = (const Program& prog)
45864688
return *this;
45874689
}
45884690

4691+
Program::Program(Program&& prog) CV_NOEXCEPT
4692+
{
4693+
p = prog.p;
4694+
prog.p = nullptr;
4695+
}
4696+
4697+
Program& Program::operator = (Program&& prog) CV_NOEXCEPT
4698+
{
4699+
if (this != &prog) {
4700+
if(p)
4701+
p->release();
4702+
p = prog.p;
4703+
prog.p = nullptr;
4704+
}
4705+
return *this;
4706+
}
4707+
45894708
Program::~Program()
45904709
{
45914710
if(p)
@@ -6647,6 +6766,23 @@ PlatformInfo& PlatformInfo::operator =(const PlatformInfo& i)
66476766
return *this;
66486767
}
66496768

6769+
PlatformInfo::PlatformInfo(PlatformInfo&& i) CV_NOEXCEPT
6770+
{
6771+
p = i.p;
6772+
i.p = nullptr;
6773+
}
6774+
6775+
PlatformInfo& PlatformInfo::operator = (PlatformInfo&& i) CV_NOEXCEPT
6776+
{
6777+
if (this != &i) {
6778+
if(p)
6779+
p->release();
6780+
p = i.p;
6781+
i.p = nullptr;
6782+
}
6783+
return *this;
6784+
}
6785+
66506786
int PlatformInfo::deviceNumber() const
66516787
{
66526788
return p ? (int)p->devices.size() : 0;
@@ -7187,7 +7323,7 @@ struct Image2D::Impl
71877323
cl_mem handle;
71887324
};
71897325

7190-
Image2D::Image2D()
7326+
Image2D::Image2D() CV_NOEXCEPT
71917327
{
71927328
p = NULL;
71937329
}
@@ -7245,6 +7381,23 @@ Image2D & Image2D::operator = (const Image2D & i)
72457381
return *this;
72467382
}
72477383

7384+
Image2D::Image2D(Image2D&& i) CV_NOEXCEPT
7385+
{
7386+
p = i.p;
7387+
i.p = nullptr;
7388+
}
7389+
7390+
Image2D& Image2D::operator = (Image2D&& i) CV_NOEXCEPT
7391+
{
7392+
if (this != &i) {
7393+
if (p)
7394+
p->release();
7395+
p = i.p;
7396+
i.p = nullptr;
7397+
}
7398+
return *this;
7399+
}
7400+
72487401
Image2D::~Image2D()
72497402
{
72507403
if (p)

0 commit comments

Comments
 (0)