Permalink
Browse files

Add char-based getThreadID functions

  • Loading branch information...
1 parent 5546d98 commit db221c3633b0b355013db879378d09249f76f55c @snrkiwi committed Nov 11, 2009
@@ -25,6 +25,16 @@ namespace log4cpp {
sprintf(buffer, "not available");
return std::string(buffer);
};
+ /**
+ * returns the thread ID
+ * @param buffer Character buffer of at least 14 in size
+ * @return buffer
+ */
+ static char* getThreadId(char* buffer) {
+ // Boost.Threads stores the thread ID but doesn't expose it
+ sprintf(buffer, "not available");
+ return buffer;
+ };
typedef boost::mutex Mutex;
typedef boost::mutex::scoped_lock ScopedLock;
@@ -17,7 +17,16 @@
namespace log4cpp {
namespace threading {
std::string getThreadId();
-
+ /**
+ * Return an identifier for the current thread. What these
+ * identifiers look like is completely up to the underlying
+ * thread library. OmniThreads returns the POSIX thread Id.
+ *
+ * @param buffer Character buffer of at least 16 in size
+ * @return buffer
+ */
+ char* getThreadId(char* buffer);
+
/**
Dummy type 'int' for Mutex. Yes, this adds a bit of overhead in
the for of extra memory, but unfortunately 'void' is illegal.
@@ -41,12 +41,21 @@
namespace log4cpp {
namespace threading {
/**
- * Return an identifier for the current thread. What these
- * identifiers look like is completely up to the underlying
+ * Return an identifier for the current thread. What these
+ * identifiers look like is completely up to the underlying
* thread library.
**/
std::string getThreadId();
-
+ /**
+ * Return an identifier for the current thread. What these
+ * identifiers look like is completely up to the underlying
+ * thread library.
+ *
+ * @param buffer Character buffer of at least 16 in size
+ * @return buffer
+ **/
+ char* getThreadId(char* buffer);
+
/**
* A simple object wrapper around CreateMutex() and DeleteMutex()
*/
@@ -24,6 +24,16 @@ namespace log4cpp {
**/
std::string getThreadId();
+ /**
+ * Return an identifier for the current thread. What these
+ * identifiers look like is completely up to the underlying
+ * thread library. OmniThreads returns the POSIX thread Id.
+ *
+ * @param buffer Character buffer of at least 16 in size
+ * @return buffer
+ */
+ char* getThreadId(char* buffer);
+
/**
* A simple, non recursive Mutex.
* Equivalent to Boost.Threads boost::mutex
@@ -24,6 +24,13 @@ namespace log4cpp {
**/
std::string getThreadId();
+ /**
+ * returns the thread ID
+ * @param buffer Character buffer of at least 16 in size
+ * @return buffer
+ */
+ char* getThreadId(char* buffer);
+
/**
**/
class Mutex {
View
@@ -10,6 +10,12 @@ namespace log4cpp {
return std::string("thread1");
}
+ char* getThreadId(char* buffer) {
+ // more useful would be to return the PID.
+ sprintf(buffer, "thread1");
+ return buffer;
+ }
+
}
}
View
@@ -11,6 +11,10 @@ namespace log4cpp {
sprintf(buffer, "%lu", GetCurrentThreadId());
return std::string(buffer);
};
+ char* getThreadId(char* buffer) {
+ sprintf(buffer, "%lu", GetCurrentThreadId());
+ return buffer;
+ };
}
}
View
@@ -5,6 +5,11 @@
namespace log4cpp {
namespace threading {
+ char* getThreadId(char* buffer) {
+ ::sprintf(buffer, "%d", ::omni_thread::self()->id()););
+ return buffer;
+ }
+
std::string getThreadId() {
char buffer[16];
sprintf(buffer, "%d", ::omni_thread::self()->id());
View
@@ -5,9 +5,14 @@
namespace log4cpp {
namespace threading {
+ char* getThreadId(char* buffer) {
+ ::sprintf(buffer, "%ld", (long int)pthread_self());
+ return buffer;
+ }
+
std::string getThreadId() {
char buffer[16];
- ::sprintf(buffer, "%ld", pthread_self());
+ ::sprintf(buffer, "%ld", (long int)pthread_self());
return std::string(buffer);
}

0 comments on commit db221c3

Please sign in to comment.