[Swift-commit] cog r3949
swift at ci.uchicago.edu
swift at ci.uchicago.edu
Mon Jun 23 10:50:03 CDT 2014
------------------------------------------------------------------------
r3949 | timgarmstrong | 2014-06-23 10:48:26 -0500 (Mon, 23 Jun 2014) | 1 line
Add C API functionality to wait for jobs. Minor additions to C++ API to wait for single completion of any job and to get bounded number of completed jobs
------------------------------------------------------------------------
Index: modules/provider-coaster-c-client/src/CoasterClient.cpp
===================================================================
--- modules/provider-coaster-c-client/src/CoasterClient.cpp (revision 3948)
+++ modules/provider-coaster-c-client/src/CoasterClient.cpp (working copy)
@@ -276,12 +276,28 @@
}
}
+int CoasterClient::getAndPurgeDoneJobs(int size, Job** jobs)
+ { Lock::Scoped l(lock);
+ int count = 0;
+ while (count < size && !doneJobs.empty()) {
+ jobs[count++] = doneJobs.front();
+ doneJobs.pop_front();
+ }
+ return count;
+}
+
void CoasterClient::waitForJobs() { Lock::Scoped l(lock);
while (jobs.size() != 0) {
cv.wait(lock);
}
}
+void CoasterClient::waitForAnyJob() { Lock::Scoped l(lock);
+ while (doneJobs.size() == 0) {
+ cv.wait(lock);
+ }
+}
+
void CoasterClient::waitForJob(const Job& job) { Lock::Scoped l(lock);
while (jobs.count(job.getIdentity()) != 0) {
cv.wait(lock);
Index: modules/provider-coaster-c-client/src/coasters.cpp
===================================================================
--- modules/provider-coaster-c-client/src/coasters.cpp (revision 3948)
+++ modules/provider-coaster-c-client/src/coasters.cpp (working copy)
@@ -461,6 +461,51 @@
}
}
+coaster_rc
+coaster_check_jobs(coaster_client *client, bool wait, int maxjobs,
+ job_id_t *jobs, int *njobs)
+ COASTERS_THROWS_NOTHING {
+ if (client == NULL) {
+ return COASTER_ERROR_INVALID;
+ }
+
+ try {
+ if (wait) {
+ client->client.waitForAnyJob();
+ }
+
+ int count = 0;
+
+ // Need to use temporary storage for job pointers
+ const int job_buf_size = 32;
+ Job *job_buf[job_buf_size];
+
+ while (count < maxjobs) {
+ int maxleft = maxjobs - count;
+ int maxbatch = (maxleft < job_buf_size) ? maxleft : job_buf_size;
+
+ int n = client->client.getAndPurgeDoneJobs(maxbatch, job_buf);
+
+ for (int i = 0; i < n; i++) {
+ jobs[count++] = job_buf[i]->getIdentity();
+ }
+
+ if (n < maxbatch) {
+ // Got last job
+ break;
+ }
+ }
+
+ *njobs = count;
+ return COASTER_SUCCESS;
+
+ } catch (const CoasterError& err) {
+ return coaster_error_rc(err);
+ } catch (const std::exception& ex) {
+ return exception_rc(ex);
+ }
+}
+
const char *coaster_rc_string(coaster_rc code)
{
switch (code)
Index: modules/provider-coaster-c-client/src/CoasterClient.h
===================================================================
--- modules/provider-coaster-c-client/src/CoasterClient.h (revision 3948)
+++ modules/provider-coaster-c-client/src/CoasterClient.h (working copy)
@@ -60,8 +60,8 @@
virtual ~CoasterClient();
void start();
void stop();
-
- // TODO: how long does this hold a reference to settings?
+
+ // TODO: how long does this hold a reference to settings?
void setOptions(Settings& settings);
/*
@@ -80,10 +80,22 @@
/*
* Return a list of done jobs and remove references from this
- * client.
+ * client. This returns jobs in FIFO order of completion
*/
list<Job*>* getAndPurgeDoneJobs();
+
+ /*
+ * Give back up to size done jobs and remove references.
+ * jobs: array with space for at least size jobs
+ * returns number of completed jobs added to array
+ */
+ int getAndPurgeDoneJobs(int size, Job** jobs);
+
void waitForJobs();
+ /*
+ * Wait until there is at least one done job
+ */
+ void waitForAnyJob();
void updateJobStatus(const string& remoteJobId, JobStatus* status);
void updateJobStatus(job_id_t jobId, JobStatus* status);
Index: modules/provider-coaster-c-client/src/coasters.h
===================================================================
--- modules/provider-coaster-c-client/src/coasters.h (revision 3948)
+++ modules/provider-coaster-c-client/src/coasters.h (working copy)
@@ -256,6 +256,21 @@
coaster_submit(coaster_client *client, coaster_job *job)
COASTERS_THROWS_NOTHING;
+/*
+ * Check for completion of jobs.
+ *
+ * NOTE: we only return job ids, client is responsible for reconciling
+ * these with the job objects.
+ *
+ * wait: if true, don't return until at least one job completes
+ * maxjobs: maximum number of jobs to return
+ * jobs: output array large enough to hold maxjobs
+ * njobs: output for number of jobs returned in jobs
+ */
+coaster_rc
+coaster_check_jobs(coaster_client *client, bool wait, int maxjobs,
+ job_id_t *jobs, int *njobs)
+ COASTERS_THROWS_NOTHING;
/*
* Get name of return code. Returns NULL if invalid code.
More information about the Swift-commit
mailing list