diff --git a/dtool/src/dtoolbase/atomicAdjustWin32Impl.I b/dtool/src/dtoolbase/atomicAdjustWin32Impl.I index dd24689999..966d7611a4 100644 --- a/dtool/src/dtoolbase/atomicAdjustWin32Impl.I +++ b/dtool/src/dtoolbase/atomicAdjustWin32Impl.I @@ -53,10 +53,12 @@ dec(TVOLATILE AtomicAdjustWin32Impl::Integer &var) { //////////////////////////////////////////////////////////////////// INLINE void AtomicAdjustWin32Impl:: add(TVOLATILE AtomicAdjustWin32Impl::Integer &var, AtomicAdjustWin32Impl::Integer delta) { - AtomicAdjustWin32Impl::Integer orig_value = var; - while (compare_and_exchange(var, orig_value, orig_value + delta) != orig_value) { - orig_value = var; - } + assert((((size_t)&var) & (sizeof(Integer) - 1)) == 0); +#ifdef _WIN64 + InterlockedAdd64(&var, delta); +#else + InterlockedAdd(&var, delta); +#endif // _WIN64 } //////////////////////////////////////////////////////////////////// @@ -87,13 +89,12 @@ set(TVOLATILE AtomicAdjustWin32Impl::Integer &var, //////////////////////////////////////////////////////////////////// INLINE AtomicAdjustWin32Impl::Integer AtomicAdjustWin32Impl:: get(const TVOLATILE AtomicAdjustWin32Impl::Integer &var) { - // On Intel platforms, word-aligned loads are atomic (if performed - // in a single instruction). We can't guarantee the compiler will - // generate a single instruction to load this value, but it - // certainly won't happen if its address isn't word-aligned, so make - // sure that's the case. assert((((size_t)&var) & (sizeof(Integer) - 1)) == 0); - return var; +#ifdef _WIN64 + return InterlockedAdd64((TVOLATILE AtomicAdjustWin32Impl::Integer *)&var, 0); +#else + return InterlockedAdd((TVOLATILE AtomicAdjustWin32Impl::Integer *)&var, 0); +#endif // _WIN64 } //////////////////////////////////////////////////////////////////// @@ -116,13 +117,12 @@ set_ptr(TVOLATILE AtomicAdjustWin32Impl::Pointer &var, // indicated variable. This is the only guaranteed safe // way to retrieve the value that other threads might be // asynchronously setting, incrementing, or decrementing -// (via other AtomicAjust methods). +// (via other AtomicAdjust methods). //////////////////////////////////////////////////////////////////// INLINE AtomicAdjustWin32Impl::Pointer AtomicAdjustWin32Impl:: get_ptr(const TVOLATILE AtomicAdjustWin32Impl::Pointer &var) { - // As in get(), make sure the address is word-aligned. - assert((((size_t)&var) & (sizeof(Pointer) - 1)) == 0); - return var; + assert(sizeof(Pointer) == sizeof(Integer)); + return (Pointer)get(*(const TVOLATILE Integer *)&var); } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/movies/ffmpegVideoCursor.cxx b/panda/src/movies/ffmpegVideoCursor.cxx index 8b065a80ff..48943d02c6 100644 --- a/panda/src/movies/ffmpegVideoCursor.cxx +++ b/panda/src/movies/ffmpegVideoCursor.cxx @@ -31,6 +31,10 @@ extern "C" { ReMutex FfmpegVideoCursor::_av_lock; TypeHandle FfmpegVideoCursor::_type_handle; +PStatCollector FfmpegVideoCursor::_fetch_buffer_pcollector("*:FFMPEG Video Decoding:Fetch"); +PStatCollector FfmpegVideoCursor::_seek_pcollector("*:FFMPEG Video Decoding:Seek"); +PStatCollector FfmpegVideoCursor::_export_frame_pcollector("*:FFMPEG Convert Video to BGR"); + #if LIBAVFORMAT_VERSION_MAJOR < 53 #define AVMEDIA_TYPE_VIDEO CODEC_TYPE_VIDEO @@ -898,8 +902,7 @@ flip_packets() { //////////////////////////////////////////////////////////////////// void FfmpegVideoCursor:: fetch_frame(int frame) { - static PStatCollector fetch_buffer_pcollector("*:FFMPEG Video Decoding:Fetch"); - PStatTimer timer(fetch_buffer_pcollector); + PStatTimer timer(_fetch_buffer_pcollector); int finished = 0; @@ -918,8 +921,7 @@ fetch_frame(int frame) { return; } while (_packet_frame <= frame) { - static PStatCollector seek_pcollector("*:FFMPEG Video Decoding:Seek"); - PStatTimer timer(seek_pcollector); + PStatTimer timer(_seek_pcollector); // Decode and discard the previous packet. decode_frame(finished, _packet1); @@ -993,8 +995,7 @@ do_decode_frame(int &finished, AVPacket *packet) { //////////////////////////////////////////////////////////////////// void FfmpegVideoCursor:: seek(int frame, bool backward) { - static PStatCollector seek_pcollector("*:FFMPEG Video Decoding:Seek"); - PStatTimer timer(seek_pcollector); + PStatTimer timer(_seek_pcollector); if (ffmpeg_support_seek) { if (ffmpeg_global_lock) { @@ -1121,8 +1122,7 @@ reset_stream() { //////////////////////////////////////////////////////////////////// void FfmpegVideoCursor:: advance_to_frame(int frame) { - static PStatCollector fetch_buffer_pcollector("*:FFMPEG Video Decoding:Fetch"); - PStatTimer timer(fetch_buffer_pcollector); + PStatTimer timer(_fetch_buffer_pcollector); if (frame < _begin_frame) { // Frame is in the past. @@ -1210,8 +1210,7 @@ advance_to_frame(int frame) { //////////////////////////////////////////////////////////////////// void FfmpegVideoCursor:: export_frame(FfmpegBuffer *buffer) { - static PStatCollector export_frame_collector("*:FFMPEG Convert Video to BGR"); - PStatTimer timer(export_frame_collector); + PStatTimer timer(_export_frame_pcollector); if (!_frame_ready) { // No frame data ready, just fill with black. diff --git a/panda/src/movies/ffmpegVideoCursor.h b/panda/src/movies/ffmpegVideoCursor.h index 13faa170a3..d306fb98f7 100644 --- a/panda/src/movies/ffmpegVideoCursor.h +++ b/panda/src/movies/ffmpegVideoCursor.h @@ -155,6 +155,11 @@ private: bool _frame_ready; bool _eof_known; int _eof_frame; + + // PStat collectors. + static PStatCollector _fetch_buffer_pcollector; + static PStatCollector _seek_pcollector; + static PStatCollector _export_frame_pcollector; public: static void register_with_read_factory(); diff --git a/panda/src/pstatclient/Sources.pp b/panda/src/pstatclient/Sources.pp index 1f3a09e9fd..d0dabd7af7 100644 --- a/panda/src/pstatclient/Sources.pp +++ b/panda/src/pstatclient/Sources.pp @@ -23,7 +23,9 @@ #define INCLUDED_SOURCES \ config_pstats.cxx pStatClient.cxx pStatClientImpl.cxx \ pStatClientVersion.cxx \ - pStatClientControlMessage.cxx pStatCollectorDef.cxx \ + pStatClientControlMessage.cxx \ + pStatCollector.cxx \ + pStatCollectorDef.cxx \ pStatCollectorForward.cxx \ pStatFrameData.cxx pStatProperties.cxx \ pStatServerControlMessage.cxx \ diff --git a/panda/src/pstatclient/pStatCollector.I b/panda/src/pstatclient/pStatCollector.I index ba98a73e6f..b6fd3f027a 100644 --- a/panda/src/pstatclient/pStatCollector.I +++ b/panda/src/pstatclient/pStatCollector.I @@ -472,6 +472,7 @@ is_started(const PStatThread &thread) { //////////////////////////////////////////////////////////////////// INLINE void PStatCollector:: start(const PStatThread &thread) { + nassertv(_client != NULL); _client->start(_index, thread._index); } diff --git a/panda/src/pstatclient/pStatCollector.cxx b/panda/src/pstatclient/pStatCollector.cxx new file mode 100755 index 0000000000..a5e4ad5653 --- /dev/null +++ b/panda/src/pstatclient/pStatCollector.cxx @@ -0,0 +1,15 @@ +// Filename: pStatCollector.cxx +// Created by: drose (18Nov11) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "pStatCollector.h" diff --git a/panda/src/pstatclient/pstatclient_composite1.cxx b/panda/src/pstatclient/pstatclient_composite1.cxx index cff704072c..e1a29761d7 100644 --- a/panda/src/pstatclient/pstatclient_composite1.cxx +++ b/panda/src/pstatclient/pstatclient_composite1.cxx @@ -4,3 +4,4 @@ #include "pStatClientImpl.cxx" #include "pStatClientVersion.cxx" #include "pStatClientControlMessage.cxx" +#include "pStatCollector.cxx"