Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/include/id_map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,14 @@

class id_map
{
std::map<std::string, int> str_map;
std::vector<std::string> names;
std::map<std::string, int> *str_map;
std::vector<std::string> *names;
pthread_mutex_t mutex;
int counter;

public:
id_map();
~id_map();
id_map(const id_map &other);
int get_new_id(const char *name);
int get_id(const char *name);
Expand Down
26 changes: 18 additions & 8 deletions src/server/id_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@ int id_map::get_new_id(

try
{
id = this->str_map.at(nname);
id = this->str_map->at(nname);
}
catch (...)
{
id = this->counter++;
std::pair<std::string, int> p1(nname, id);
this->str_map.insert(p1);
this->names.push_back(nname);
this->str_map->insert(p1);
this->names->push_back(nname);
}
pthread_mutex_unlock(&this->mutex);

Expand All @@ -121,7 +121,7 @@ int id_map::get_id(
try
{
std::string nname(name);
id = this->str_map.at(nname);
id = this->str_map->at(nname);
}
catch (...)
{
Expand All @@ -142,7 +142,7 @@ const char *id_map::get_name(
pthread_mutex_lock(&this->mutex);
try
{
std::string const &nname = this->names.at(id);
std::string const &nname = this->names->at(id);
name = nname.c_str();
}
catch (...)
Expand All @@ -154,18 +154,28 @@ const char *id_map::get_name(
}


id_map::~id_map()
{
// leave the destructor blank. C++ destroys globally constructed
// objects when the main thread exits, and this class is only destroyed
// at shutdown, so we don't care about the memory usage at that point.
}

id_map::id_map() : counter(0)


id_map::id_map() : counter(0)
{
str_map = new std::map<std::string,int>();
names = new std::vector<std::string>();
pthread_mutex_init(&mutex, NULL);
}



id_map::id_map(const id_map &other) : counter(other.counter), names(other.names), str_map(other.str_map)

id_map::id_map(const id_map &other) : counter(other.counter)
{
str_map = new std::map<std::string,int>(*other.str_map);
names = new std::vector<std::string>(*other.names);
pthread_mutex_init(&mutex, NULL);
}

1 change: 1 addition & 0 deletions src/server/test/exiting_jobs/scaffolding.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ void on_job_exit(batch_request *preq, char *jobid) {}
void force_purge_work(job *pjob) {}

void log_event(int eventtype, int objclass, const char *objname, const char *text) {}

1 change: 1 addition & 0 deletions src/server/test/job_container/scaffolding.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,4 @@ job *job_alloc(void)

return(pj);
}

3 changes: 2 additions & 1 deletion src/server/test/job_func/scaffolding.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <stdio.h> /* fprintf */
#include <pthread.h>
#include <errno.h>
#include <string>

#include "pbs_ifl.h" /* MAXPATHLEN, PBS_MAXSERVERNAME */
#include "server.h" /* server, NO_BUFFER_SPACE */
Expand All @@ -13,7 +14,6 @@
#include "batch_request.h" /* batch_request */
#include "work_task.h" /* all_tasks */
#include "array.h" /* ArrayEventsEnum */
#include <string>

/* This section is for manipulting function return values */
#include "test_job_func.h" /* *_SUITE */
Expand Down Expand Up @@ -591,3 +591,4 @@ job *find_job_by_array(

return(pj);
} /* END find_job_by_array() */

1 change: 1 addition & 0 deletions src/server/test/job_recov/scaffolding.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,3 +330,4 @@ job *find_job_by_array(all_jobs *aj, char *job_id, int get_subjob, bool locked)
{
return(NULL);
}

5 changes: 5 additions & 0 deletions src/server/test/node_func/scaffolding.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,11 @@ int id_map::get_new_id(char const *name)
return(id++);
}

id_map::~id_map()
{
}


id_map node_mapper;

struct pbsnode *tfind_addr(
Expand Down
5 changes: 5 additions & 0 deletions src/server/test/node_manager/scaffolding.c
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,11 @@ const char *id_map::get_name(int id)
return(strdup(buf));
}

id_map::~id_map()
{
}


id_map node_mapper;

#ifdef CAN_TIME
Expand Down
2 changes: 1 addition & 1 deletion src/server/test/req_jobobit/scaffolding.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include "queue.h" /* pbs_queue */



const char *msg_momnoexec2 = "Job cannot be executed\nSee job standard error file";
const char *msg_job_end_sig = "Terminated on signal %d";
const char *msg_obitnojob = "Job Obit notice received from %s has error %d";
Expand Down Expand Up @@ -325,3 +324,4 @@ void log_record(int eventtype, int objclass, const char *objname, const char *te
void account_jobend(job *pjob, char *used) {}

void update_array_values(job_array *pa, int old_state, enum ArrayEventsEnum event, char *job_id, long job_atr_hold, int job_exit_status) {}

1 change: 0 additions & 1 deletion src/server/test/req_quejob/scaffolding.c
Original file line number Diff line number Diff line change
Expand Up @@ -411,4 +411,3 @@ job *find_job_by_array(all_jobs *aj, char *jobid, int get_subjob, bool locked)
}