0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
SshThreadsCallbacks.cc
Go to the documentation of this file.
1 /* -*- c++ -*-
2  * Copyright (C) 2007-2014 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 3
9  * of the License, or any later version.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21 
26 
27 #include <Common/Compat.h>
28 
29 #include "SshThreadsCallbacks.h"
30 
31 using namespace Hypertable;
32 using namespace std;
33 
35 
37 
38 unordered_map<thread::id, int> SshThreadsCallbacks::ms_thread_id_map {};
39 
40 struct ssh_threads_callbacks_struct SshThreadsCallbacks::ms_callbacks = {
41  "threads_cpp",
42  mutex_init,
43  mutex_destroy,
44  mutex_lock,
45  mutex_unlock,
46  thread_id
47 };
48 
50  *priv = new mutex();
51  return 0;
52 }
53 
55  delete (mutex *)*lock;
56  return 0;
57 }
58 
60  ((mutex *)*lock)->lock();
61  return 0;
62 }
63 
65  ((mutex *)*lock)->unlock();
66  return 0;
67 }
68 
69 
71  lock_guard<mutex> lock(ms_thread_id_mutex);
72  auto iter = ms_thread_id_map.find(this_thread::get_id());
73  if (iter == ms_thread_id_map.end()) {
74  unsigned long id = ++ms_thread_id_next;
75  ms_thread_id_map[this_thread::get_id()] = id;
76  return id;
77  }
78  return iter->second;
79 }
80 
81 struct ssh_threads_callbacks_struct *SshThreadsCallbacks::get() {
82  return &ms_callbacks;
83 }
84 
static std::mutex mutex
Definition: Logger.cc:43
static unsigned long thread_id()
Callback for obtaining current thread ID.
static struct ssh_threads_callbacks_struct * get()
Gets libssh threads callbacks structure.
static int mutex_init(void **priv)
Mutex initializaton callback.
static std::unordered_map< std::thread::id, int > ms_thread_id_map
Mapping from std::thread::id to unique thread ID number.
static std::mutex ms_thread_id_mutex
Mutex for serializing access to static data members
STL namespace.
static unsigned long ms_thread_id_next
Next thread ID.
Declarations for SshThreadsCallbacks.
static int mutex_destroy(void **lock)
Mutex destroy callback.
static int mutex_unlock(void **lock)
Mutex unlock callback.
static int mutex_lock(void **lock)
Mutex lock callback.
Compatibility Macros for C/C++.
Hypertable definitions
Thread callbacks for libssh