comparison src/os/bsd/vm/os_bsd.cpp @ 4961:0368109684cb

7132070: Use a mach_port_t as the OSThread thread_id rather than pthread_t on BSD/OSX Summary: Change OSThread to use mach thread_t Reviewed-by: phh, dcubed
author sla
date Sun, 19 Feb 2012 13:11:39 +0100
parents 86ce3208eb18
children 897b7d18bebc 4e0a9aaec0e9
comparison
equal deleted inserted replaced
4960:86ce3208eb18 4961:0368109684cb
996 sync->notify_all(); 996 sync->notify_all();
997 return NULL; 997 return NULL;
998 } 998 }
999 999
1000 #ifdef _ALLBSD_SOURCE 1000 #ifdef _ALLBSD_SOURCE
1001 #ifdef __APPLE__
1002 // thread_id is mach thread on macos
1003 osthread->set_thread_id(::mach_thread_self());
1004 #else
1001 // thread_id is pthread_id on BSD 1005 // thread_id is pthread_id on BSD
1002 osthread->set_thread_id(::pthread_self()); 1006 osthread->set_thread_id(::pthread_self());
1007 #endif
1003 #else 1008 #else
1004 // thread_id is kernel thread id (similar to Solaris LWP id) 1009 // thread_id is kernel thread id (similar to Solaris LWP id)
1005 osthread->set_thread_id(os::Bsd::gettid()); 1010 osthread->set_thread_id(os::Bsd::gettid());
1006 1011
1007 if (UseNUMA) { 1012 if (UseNUMA) {
1188 return false; 1193 return false;
1189 } 1194 }
1190 1195
1191 // Store pthread info into the OSThread 1196 // Store pthread info into the OSThread
1192 #ifdef _ALLBSD_SOURCE 1197 #ifdef _ALLBSD_SOURCE
1198 #ifdef __APPLE__
1199 osthread->set_thread_id(::mach_thread_self());
1200 #else
1193 osthread->set_thread_id(::pthread_self()); 1201 osthread->set_thread_id(::pthread_self());
1202 #endif
1194 #else 1203 #else
1195 osthread->set_thread_id(os::Bsd::gettid()); 1204 osthread->set_thread_id(os::Bsd::gettid());
1196 #endif 1205 #endif
1197 osthread->set_pthread_id(::pthread_self()); 1206 osthread->set_pthread_id(::pthread_self());
1198 1207
1805 ::strncpy(buf, s, n); 1814 ::strncpy(buf, s, n);
1806 buf[n] = '\0'; 1815 buf[n] = '\0';
1807 return n; 1816 return n;
1808 } 1817 }
1809 1818
1810 intx os::current_thread_id() { return (intx)pthread_self(); } 1819 intx os::current_thread_id() {
1820 #ifdef __APPLE__
1821 return (intx)::mach_thread_self();
1822 #else
1823 return (intx)::pthread_self();
1824 #endif
1825 }
1811 int os::current_process_id() { 1826 int os::current_process_id() {
1812 1827
1813 // Under the old bsd thread library, bsd gives each thread 1828 // Under the old bsd thread library, bsd gives each thread
1814 // its own process id. Because of this each thread will return 1829 // its own process id. Because of this each thread will return
1815 // a different pid if this method were to return the result 1830 // a different pid if this method were to return the result
5150 jlong os::thread_cpu_time(Thread *thread, bool user_sys_cpu_time) { 5165 jlong os::thread_cpu_time(Thread *thread, bool user_sys_cpu_time) {
5151 #ifdef __APPLE__ 5166 #ifdef __APPLE__
5152 struct thread_basic_info tinfo; 5167 struct thread_basic_info tinfo;
5153 mach_msg_type_number_t tcount = THREAD_INFO_MAX; 5168 mach_msg_type_number_t tcount = THREAD_INFO_MAX;
5154 kern_return_t kr; 5169 kern_return_t kr;
5155 mach_port_t mach_thread; 5170 thread_t mach_thread;
5156 5171
5157 mach_thread = pthread_mach_thread_np(thread->osthread()->thread_id()); 5172 mach_thread = thread->osthread()->thread_id();
5158 kr = thread_info(mach_thread, THREAD_BASIC_INFO, (thread_info_t)&tinfo, &tcount); 5173 kr = thread_info(mach_thread, THREAD_BASIC_INFO, (thread_info_t)&tinfo, &tcount);
5159 if (kr != KERN_SUCCESS) 5174 if (kr != KERN_SUCCESS)
5160 return -1; 5175 return -1;
5161 5176
5162 if (user_sys_cpu_time) { 5177 if (user_sys_cpu_time) {