annotate OrthancServer/Sources/ServerJobs/LuaJobManager.cpp @ 5410:16cbfefa15e9

Solved a deadlock related to the Job Engine events and plugins
author Alain Mazy <am@osimis.io>
date Tue, 07 Nov 2023 12:52:37 +0100
parents 0ea402b4d901
children 48b8dae6dc77
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
5185
0ea402b4d901 upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
0ea402b4d901 upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4892
diff changeset
6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * This program is free software: you can redistribute it and/or
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * modify it under the terms of the GNU General Public License as
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * published by the Free Software Foundation, either version 3 of the
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * License, or (at your option) any later version.
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 *
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful, but
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * General Public License for more details.
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 *
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 **/
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 #include "../PrecompiledHeadersServer.h"
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "LuaJobManager.h"
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
2940
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2730
diff changeset
26 #include "../OrthancConfiguration.h"
4045
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
27 #include "../../../OrthancFramework/Sources/Logging.h"
2620
1232922c8793 speeding up shutdown if Lua script is in trailing phase
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2616
diff changeset
28
4045
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
29 #include "../../../OrthancFramework/Sources/JobsEngine/Operations/LogJobOperation.h"
2641
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2624
diff changeset
30 #include "Operations/DeleteResourceOperation.h"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2624
diff changeset
31 #include "Operations/ModifyInstanceOperation.h"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2624
diff changeset
32 #include "Operations/StorePeerOperation.h"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2624
diff changeset
33 #include "Operations/StoreScuOperation.h"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2624
diff changeset
34 #include "Operations/SystemCallOperation.h"
2604
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
35
4045
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
36 #include "../../../OrthancFramework/Sources/JobsEngine/Operations/NullOperationValue.h"
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
37 #include "../../../OrthancFramework/Sources/JobsEngine/Operations/StringOperationValue.h"
2641
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2624
diff changeset
38 #include "Operations/DicomInstanceOperationValue.h"
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 namespace Orthanc
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 void LuaJobManager::SignalDone(const SequenceOfOperationsJob& job)
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 boost::mutex::scoped_lock lock(mutex_);
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 if (&job == currentJob_)
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 currentId_.clear();
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 currentJob_ = NULL;
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53
2604
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
54 LuaJobManager::LuaJobManager() :
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 currentJob_(NULL),
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 maxOperations_(1000),
2609
f7a84b551ee4 switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2608
diff changeset
57 priority_(0),
f7a84b551ee4 switch Lua to new jobs engine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2608
diff changeset
58 trailingTimeout_(5000)
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 {
3851
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
60 unsigned int dicomTimeout;
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
61
2940
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2730
diff changeset
62 {
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2730
diff changeset
63 OrthancConfiguration::ReaderLock lock;
3851
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
64 dicomTimeout = lock.GetConfiguration().GetUnsignedIntegerParameter("DicomAssociationCloseDelay", 5);
2940
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2730
diff changeset
65 }
4767d36679ed refactoring access to Orthanc configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2730
diff changeset
66
3851
6498739a3c3c refactoring: TimeoutDicomConnectionManager is now only used by Lua
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
67 connectionManager_.SetInactivityTimeout(dicomTimeout * 1000); // Milliseconds expected
4295
90f91b78d708 applied log categories
Alain Mazy <alain@mazy.be>
parents: 4045
diff changeset
68 CLOG(INFO, LUA) << "Lua: DICOM associations will be closed after "
90f91b78d708 applied log categories
Alain Mazy <alain@mazy.be>
parents: 4045
diff changeset
69 << dicomTimeout << " seconds of inactivity";
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 void LuaJobManager::SetMaxOperationsPerJob(size_t count)
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 boost::mutex::scoped_lock lock(mutex_);
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 maxOperations_ = count;
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 void LuaJobManager::SetPriority(int priority)
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 boost::mutex::scoped_lock lock(mutex_);
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 priority_ = priority;
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 void LuaJobManager::SetTrailingOperationTimeout(unsigned int timeout)
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 {
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 boost::mutex::scoped_lock lock(mutex_);
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 trailingTimeout_ = timeout;
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93
2620
1232922c8793 speeding up shutdown if Lua script is in trailing phase
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2616
diff changeset
94 void LuaJobManager::AwakeTrailingSleep()
1232922c8793 speeding up shutdown if Lua script is in trailing phase
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2616
diff changeset
95 {
1232922c8793 speeding up shutdown if Lua script is in trailing phase
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2616
diff changeset
96 boost::mutex::scoped_lock lock(mutex_);
1232922c8793 speeding up shutdown if Lua script is in trailing phase
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2616
diff changeset
97
4295
90f91b78d708 applied log categories
Alain Mazy <alain@mazy.be>
parents: 4045
diff changeset
98 CLOG(INFO, LUA) << "Awaking trailing sleep";
2620
1232922c8793 speeding up shutdown if Lua script is in trailing phase
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2616
diff changeset
99
1232922c8793 speeding up shutdown if Lua script is in trailing phase
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2616
diff changeset
100 if (currentJob_ != NULL)
1232922c8793 speeding up shutdown if Lua script is in trailing phase
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2616
diff changeset
101 {
1232922c8793 speeding up shutdown if Lua script is in trailing phase
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2616
diff changeset
102 currentJob_->AwakeTrailingSleep();
1232922c8793 speeding up shutdown if Lua script is in trailing phase
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2616
diff changeset
103 }
1232922c8793 speeding up shutdown if Lua script is in trailing phase
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2616
diff changeset
104 }
1232922c8793 speeding up shutdown if Lua script is in trailing phase
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2616
diff changeset
105
1232922c8793 speeding up shutdown if Lua script is in trailing phase
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2616
diff changeset
106
2604
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
107 LuaJobManager::Lock::Lock(LuaJobManager& that,
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
108 JobsEngine& engine) :
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
109 that_(that),
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
110 lock_(that.mutex_),
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
111 engine_(engine)
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 {
2604
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
113 if (that_.currentJob_ == NULL)
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
114 {
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
115 isNewJob_ = true;
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
116 }
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
117 else
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 {
2604
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
119 jobLock_.reset(new SequenceOfOperationsJob::Lock(*that_.currentJob_));
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120
2604
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
121 if (jobLock_->IsDone() ||
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
122 jobLock_->GetOperationsCount() >= that_.maxOperations_)
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 {
2604
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
124 jobLock_.reset(NULL);
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
125 isNewJob_ = true;
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
126 }
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
127 else
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
128 {
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
129 isNewJob_ = false;
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132
2604
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
133 if (isNewJob_)
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
134 {
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
135 // Need to create a new job, as the previous one is either
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
136 // finished, or is getting too long
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
137 that_.currentJob_ = new SequenceOfOperationsJob;
2950
dc18d5804746 support of JobsHistorySize set to zero
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2940
diff changeset
138 that_.currentJob_->Register(that_);
2616
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
139 that_.currentJob_->SetDescription("Lua");
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
140
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
141 {
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
142 jobLock_.reset(new SequenceOfOperationsJob::Lock(*that_.currentJob_));
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
143 jobLock_->SetTrailingOperationTimeout(that_.trailingTimeout_);
2f3007bf0708 event queues in Lua, serialization of sequence of operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2609
diff changeset
144 }
2604
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
145 }
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
146
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
147 assert(jobLock_.get() != NULL);
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
148 }
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
149
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
150
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
151 LuaJobManager::Lock::~Lock()
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
152 {
2624
714dcddeb65f asynchronous c-movoe
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2620
diff changeset
153 bool isEmpty;
714dcddeb65f asynchronous c-movoe
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2620
diff changeset
154
2604
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
155 assert(jobLock_.get() != NULL);
2624
714dcddeb65f asynchronous c-movoe
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2620
diff changeset
156 isEmpty = (isNewJob_ &&
714dcddeb65f asynchronous c-movoe
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2620
diff changeset
157 jobLock_->GetOperationsCount() == 0);
714dcddeb65f asynchronous c-movoe
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2620
diff changeset
158
2604
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
159 jobLock_.reset(NULL);
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
160
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
161 if (isNewJob_)
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
162 {
2624
714dcddeb65f asynchronous c-movoe
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2620
diff changeset
163 if (isEmpty)
714dcddeb65f asynchronous c-movoe
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2620
diff changeset
164 {
714dcddeb65f asynchronous c-movoe
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2620
diff changeset
165 // No operation was added, discard the newly created job
714dcddeb65f asynchronous c-movoe
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2620
diff changeset
166 isNewJob_ = false;
714dcddeb65f asynchronous c-movoe
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2620
diff changeset
167 delete that_.currentJob_;
714dcddeb65f asynchronous c-movoe
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2620
diff changeset
168 that_.currentJob_ = NULL;
714dcddeb65f asynchronous c-movoe
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2620
diff changeset
169 }
714dcddeb65f asynchronous c-movoe
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2620
diff changeset
170 else
714dcddeb65f asynchronous c-movoe
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2620
diff changeset
171 {
714dcddeb65f asynchronous c-movoe
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2620
diff changeset
172 engine_.GetRegistry().Submit(that_.currentId_, that_.currentJob_, that_.priority_);
714dcddeb65f asynchronous c-movoe
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2620
diff changeset
173 }
2604
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
174 }
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
175 }
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
176
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
177
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
178 size_t LuaJobManager::Lock::AddDeleteResourceOperation(ServerContext& context)
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
179 {
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
180 assert(jobLock_.get() != NULL);
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
181 return jobLock_->AddOperation(new DeleteResourceOperation(context));
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
182 }
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
183
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
184
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
185 size_t LuaJobManager::Lock::AddLogOperation()
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
186 {
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
187 assert(jobLock_.get() != NULL);
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
188 return jobLock_->AddOperation(new LogJobOperation);
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
189 }
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
190
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191
3894
8f7ad4989fec transcoding to uncompressed transfer syntaxes over DICOM protocol is implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3851
diff changeset
192 size_t LuaJobManager::Lock::AddStoreScuOperation(ServerContext& context,
8f7ad4989fec transcoding to uncompressed transfer syntaxes over DICOM protocol is implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3851
diff changeset
193 const std::string& localAet,
2605
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2604
diff changeset
194 const RemoteModalityParameters& modality)
2604
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
195 {
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
196 assert(jobLock_.get() != NULL);
3894
8f7ad4989fec transcoding to uncompressed transfer syntaxes over DICOM protocol is implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3851
diff changeset
197 return jobLock_->AddOperation(new StoreScuOperation(
8f7ad4989fec transcoding to uncompressed transfer syntaxes over DICOM protocol is implemented
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3851
diff changeset
198 context, that_.connectionManager_, localAet, modality));
2604
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
199 }
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
200
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
201
2605
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2604
diff changeset
202 size_t LuaJobManager::Lock::AddStorePeerOperation(const WebServiceParameters& peer)
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2604
diff changeset
203 {
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2604
diff changeset
204 assert(jobLock_.get() != NULL);
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2604
diff changeset
205 return jobLock_->AddOperation(new StorePeerOperation(peer));
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2604
diff changeset
206 }
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2604
diff changeset
207
1e11b0229e04 StorePeerOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2604
diff changeset
208
2606
f2b9d3256060 SystemCallOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2605
diff changeset
209 size_t LuaJobManager::Lock::AddSystemCallOperation(const std::string& command)
f2b9d3256060 SystemCallOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2605
diff changeset
210 {
f2b9d3256060 SystemCallOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2605
diff changeset
211 assert(jobLock_.get() != NULL);
f2b9d3256060 SystemCallOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2605
diff changeset
212 return jobLock_->AddOperation(new SystemCallOperation(command));
f2b9d3256060 SystemCallOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2605
diff changeset
213 }
2607
44e268605478 ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2606
diff changeset
214
2606
f2b9d3256060 SystemCallOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2605
diff changeset
215
f2b9d3256060 SystemCallOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2605
diff changeset
216 size_t LuaJobManager::Lock::AddSystemCallOperation
f2b9d3256060 SystemCallOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2605
diff changeset
217 (const std::string& command,
f2b9d3256060 SystemCallOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2605
diff changeset
218 const std::vector<std::string>& preArguments,
f2b9d3256060 SystemCallOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2605
diff changeset
219 const std::vector<std::string>& postArguments)
f2b9d3256060 SystemCallOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2605
diff changeset
220 {
f2b9d3256060 SystemCallOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2605
diff changeset
221 assert(jobLock_.get() != NULL);
f2b9d3256060 SystemCallOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2605
diff changeset
222 return jobLock_->AddOperation
f2b9d3256060 SystemCallOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2605
diff changeset
223 (new SystemCallOperation(command, preArguments, postArguments));
f2b9d3256060 SystemCallOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2605
diff changeset
224 }
f2b9d3256060 SystemCallOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2605
diff changeset
225
f2b9d3256060 SystemCallOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2605
diff changeset
226
2607
44e268605478 ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2606
diff changeset
227 size_t LuaJobManager::Lock::AddModifyInstanceOperation(ServerContext& context,
44e268605478 ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2606
diff changeset
228 DicomModification* modification)
44e268605478 ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2606
diff changeset
229 {
44e268605478 ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2606
diff changeset
230 assert(jobLock_.get() != NULL);
44e268605478 ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2606
diff changeset
231 return jobLock_->AddOperation
44e268605478 ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2606
diff changeset
232 (new ModifyInstanceOperation(context, RequestOrigin_Lua, modification));
44e268605478 ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2606
diff changeset
233 }
44e268605478 ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2606
diff changeset
234
44e268605478 ModifyInstanceOperation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2606
diff changeset
235
2604
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
236 void LuaJobManager::Lock::AddNullInput(size_t operation)
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
237 {
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
238 assert(jobLock_.get() != NULL);
2730
cb1b26a7db98 fix mingw compilation
s.jodogne@gmail.com
parents: 2641
diff changeset
239 NullOperationValue null;
cb1b26a7db98 fix mingw compilation
s.jodogne@gmail.com
parents: 2641
diff changeset
240 jobLock_->AddInput(operation, null);
2604
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
241 }
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
242
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243
2604
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
244 void LuaJobManager::Lock::AddStringInput(size_t operation,
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
245 const std::string& content)
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
246 {
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
247 assert(jobLock_.get() != NULL);
2730
cb1b26a7db98 fix mingw compilation
s.jodogne@gmail.com
parents: 2641
diff changeset
248 StringOperationValue value(content);
cb1b26a7db98 fix mingw compilation
s.jodogne@gmail.com
parents: 2641
diff changeset
249 jobLock_->AddInput(operation, value);
2604
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
250 }
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
251
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252
2604
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
253 void LuaJobManager::Lock::AddDicomInstanceInput(size_t operation,
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
254 ServerContext& context,
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
255 const std::string& instanceId)
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
256 {
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
257 assert(jobLock_.get() != NULL);
2730
cb1b26a7db98 fix mingw compilation
s.jodogne@gmail.com
parents: 2641
diff changeset
258 DicomInstanceOperationValue value(context, instanceId);
cb1b26a7db98 fix mingw compilation
s.jodogne@gmail.com
parents: 2641
diff changeset
259 jobLock_->AddInput(operation, value);
2604
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
260 }
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
261
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
262
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
263 void LuaJobManager::Lock::Connect(size_t operation1,
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
264 size_t operation2)
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
265 {
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
266 assert(jobLock_.get() != NULL);
76ef12fa136c fix race conditions if creating Lua jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2603
diff changeset
267 jobLock_->Connect(operation1, operation2);
2603
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 }
988936118354 reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269 }