本文整理汇总了C++中CSafeStatic类的典型用法代码示例。如果您正苦于以下问题:C++ CSafeStatic类的具体用法?C++ CSafeStatic怎么用?C++ CSafeStatic使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CSafeStatic类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetModuleName
static const string& GetModuleName(const char* moduleName)
{
CFastMutexGuard GUARD(s_ModuleNameMutex);
static CSafeStatic< set<string> > s_ModuleNames;
const string& s = *s_ModuleNames.Get().insert(moduleName).first;
CClassTypeInfoBase::RegisterModule(s);
return s;
}
示例2: CheckNULL
CValueConvert<SRunTimeSqlCP, CDB_Object>::operator const CTime&(void) const
{
CheckNULL(m_Value);
CheckType(m_Value, eDB_SmallDateTime, eDB_DateTime);
EDB_Type cur_type = m_Value.GetType();
if (cur_type == eDB_SmallDateTime) {
return static_cast<const CDB_SmallDateTime&>(m_Value).Value();
} else if (cur_type == eDB_DateTime) {
return static_cast<const CDB_DateTime&>(m_Value).Value();
} else {
ReportTypeConvError(cur_type, "CTime");
}
static CSafeStatic<CTime> value;
return value.Get();
}
示例3: ERR_POST_X
void CRequestContext::SetHitID(const string& hit)
{
if ( m_LoggedHitID ) {
// Show warning when changing hit id after is has been logged.
ERR_POST_X(28, Warning << "Changing hit ID after one has been logged. "
"New hit id is: " << hit);
}
static CSafeStatic<TOnBadHitId> action;
if ( !IsValidHitID(hit) ) {
switch ( action->Get() ) {
case eOnBadPHID_Ignore:
return;
case eOnBadPHID_AllowAndReport:
// Use Warning if bad hit id is acceptable.
ERR_POST_X(27, Warning << "Bad hit ID format: " << hit);
break;
case eOnBadPHID_IgnoreAndReport:
ERR_POST_X(27, "Bad hit ID format: " << hit);
return;
case eOnBadPHID_Throw:
NCBI_THROW(CRequestContextException, eBadHit,
"Bad hit ID format: " + hit);
break;
case eOnBadPHID_Allow:
break;
}
}
x_SetProp(eProp_HitID);
if (m_HitID != hit) {
m_SubHitID = 0;
m_SubHitIDCache.clear();
}
m_HitID = hit;
m_LoggedHitID = false;
x_LogHitID();
}
示例4: s_GetDiagHandler
static int s_GetDiagHandler(void)
{
static CSafeStatic<NCBI_PARAM_TYPE(VDB, DIAG_HANDLER)> s_Value;
return s_Value->Get();
}
示例5: x_GetFixCharsMethodDefault
EFixNonPrint CObjectOStream::x_GetFixCharsMethodDefault(void) const
{
static CSafeStatic<TSerialFixChars> s_SerialFixChars;
return s_SerialFixChars->Get();
}
示例6: Unlock
void CInterProcessLock::Unlock()
{
if (m_Handle == kInvalidLockHandle) {
NCBI_THROW(CInterProcessLockException, eNotLocked,
"Attempt to unlock not-yet-acquired lock");
}
CFastMutexGuard LOCK(s_ProcessLock);
// Check that lock with specified name not already locked
// in the current process.
TLocks::iterator it = s_Locks->find(m_SystemName);
_VERIFY(it != s_Locks->end());
if ( it->second > 1 ) {
// Just decrease reference counter
it->second--;
return;
}
// Release lock
#if defined(NCBI_OS_UNIX)
# if defined(F_TLOCK)
int res = lockf(m_Handle, F_ULOCK, 0);
# elif defined(F_SETLK)
struct flock lockparam;
lockparam.l_type = F_UNLCK;
lockparam.l_whence = SEEK_SET;
lockparam.l_start = 0;
lockparam.l_len = 0; /* whole file */
int res = fcntl(m_Handle, F_SETLK, &lockparam);
# else
# error "No supported lock method. Please port this code."
# endif
if ( res < 0 ) {
NCBI_THROW(CInterProcessLockException, eUnlockError,
"Cannot release the lock");
}
close(m_Handle);
#elif defined(NCBI_OS_MSWIN)
if ( !::ReleaseMutex(m_Handle) ) {
NCBI_THROW(CInterProcessLockException, eUnlockError,
"Cannot release the lock");
}
::CloseHandle(m_Handle);
#endif
m_Handle = kInvalidLockHandle;
s_Locks->erase(m_SystemName);
}
示例7: TConstUidIterator
CEntrez2_id_list::TConstUidIterator
CEntrez2_id_list::GetConstUidIterator() const
{
if (CanGetUids()) {
return TConstUidIterator(GetUids(), kUidSize);
} else {
return TConstUidIterator(s_EmptyList.Get(), kUidSize);
}
}
示例8:
CObjectOStream::CObjectOStream(ESerialDataFormat format,
CNcbiOstream& out, EOwnership edeleteOut)
: m_Output(out, edeleteOut == eTakeOwnership), m_Fail(fNoError), m_Flags(fFlagNone),
m_Separator(""),
m_DataFormat(format),
m_ParseDelayBuffers(eDelayBufferPolicyNotSet),
m_SpecialCaseWrite(eWriteAsNormal),
m_AutoSeparator(false),
m_WriteNamedIntegersByValue(false),
m_FastWriteDouble(s_FastWriteDouble->Get()),
m_EnforceWritingDefaults(false),
m_FixMethod(x_GetFixCharsMethodDefault()),
m_VerifyData(x_GetVerifyDataDefault())
{
}
示例9: g_FindDataFile
string g_FindDataFile(const CTempString& name, CDirEntry::EType type)
{
#ifdef NCBI_OS_MSWIN
static const char* kDelim = ";";
#else
static const char* kDelim = ":";
#endif
if ( !s_IgnoredDataFiles->empty()
&& CDirEntry::MatchesMask(name, *s_IgnoredDataFiles) ) {
return kEmptyStr;
}
list<string> dirs;
if (CDirEntry::IsAbsolutePath(name)) {
dirs.push_back(kEmptyStr);
} else {
TNCBIDataPath path;
TNCBIDataDir dir;
if ( !path.Get().empty() ) {
NStr::Split(path.Get(), kDelim, dirs);
}
if ( !dir.Get().empty() ) {
dirs.push_back(dir.Get());
}
}
CDirEntry candidate;
EFollowLinks fl = (type == CDirEntry::eLink) ? eIgnoreLinks : eFollowLinks;
ITERATE (list<string>, dir, dirs) {
candidate.Reset(CDirEntry::MakePath(*dir, name));
if (candidate.Exists() && candidate.GetType(fl) == type) {
return candidate.GetPath();
}
}
示例10: GetTypeInfo
TTypeInfo CChoicePointerTypeInfo::GetTypeInfo(TTypeInfo base)
{
return s_ChoicePointerTypeInfo_map->GetTypeInfo(base, &CreateTypeInfo);
}
示例11: Lock
void CInterProcessLock::Lock(const CTimeout& timeout,
const CTimeout& granularity)
{
CFastMutexGuard LOCK(s_ProcessLock);
// Check that lock with specified name not already locked
// in the current process.
TLocks::iterator it = s_Locks->find(m_SystemName);
if (m_Handle != kInvalidLockHandle) {
// The lock is already set in this CInterProcessLock object,
// just increase reference counter.
_VERIFY(it != s_Locks->end());
it->second++;
return;
} else {
if (it != s_Locks->end()) {
// The lock already exists in the current process.
// We can use one CInterProcessLock object with
// multiple Lock() calls, but not with different
// CInterProcessLock objects. For example, on MS-Windows,
// we cannot wait on the same mutex in the same thread.
// So, two different objects can set locks simultaneously.
// And for OS-compatibility we can do nothing here,
// except throwing an exception.
NCBI_THROW(CInterProcessLockException, eMultipleLocks,
"Attempt to lock already locked object " \
"in the same process");
}
}
// Try to acquire a lock with specified timeout
#if defined(NCBI_OS_UNIX)
// Open lock file
mode_t perm = CDirEntry::MakeModeT(
CDirEntry::fRead | CDirEntry::fWrite /* user */,
CDirEntry::fRead | CDirEntry::fWrite /* group */,
0, 0 /* other & special */);
int fd = open(m_SystemName.c_str(), O_CREAT | O_RDWR, perm);
if (fd == -1) {
NCBI_THROW(CInterProcessLockException, eCreateError,
string("Error creating lockfile ") + m_SystemName +
": " + strerror(errno));
}
// Try to acquire the lock
int x_errno = 0;
if (timeout.IsInfinite() || timeout.IsDefault()) {
while ((x_errno = s_UnixLock(fd))) {
if (errno != EAGAIN)
break;
}
} else {
unsigned long ms = timeout.GetAsMilliSeconds();
if ( !ms ) {
// Timeout == 0
x_errno = s_UnixLock(fd);
} else {
// Timeout > 0
unsigned long ms_gran;
if ( granularity.IsInfinite() ||
granularity.IsDefault() )
{
ms_gran = min(ms/5, (unsigned long)500);
} else {
ms_gran = granularity.GetAsMilliSeconds();
}
// Try to lock within specified timeout
for (;;) {
x_errno = s_UnixLock(fd);
if ( !x_errno ) {
// Successfully locked
break;
}
if (x_errno != EACCES &&
x_errno != EAGAIN ) {
// Error
break;
}
// Otherwise -- sleep granularity timeout
unsigned long ms_sleep = ms_gran;
if (ms_sleep > ms) {
ms_sleep = ms;
}
if ( !ms_sleep ) {
break;
}
SleepMilliSec(ms_sleep);
ms -= ms_sleep;
}
// Timeout
if ( !ms ) {
close(fd);
NCBI_THROW(CInterProcessLockException, eLockTimeout,
"The lock could not be acquired in the time " \
//.........这里部分代码省略.........
示例12: Get_set
TTypeInfo CStlClassInfoUtil::Get_set(TTypeInfo arg, TTypeInfoCreator1 f)
{
return s_TypeMap_set->GetTypeInfo(arg, f);
}
示例13: GetSet_vector
TTypeInfo CStlClassInfoUtil::GetSet_vector(TTypeInfo arg, TTypeInfoCreator1 f)
{
return s_TypeMapSet_vector->GetTypeInfo(arg, f);
}
示例14: Get_AutoPtr
TTypeInfo CStlClassInfoUtil::Get_AutoPtr(TTypeInfo arg, TTypeInfoCreator1 f)
{
return s_TypeMap_AutoPtr->GetTypeInfo(arg, f);
}
示例15: Get_CConstRef
TTypeInfo CStlClassInfoUtil::Get_CConstRef(TTypeInfo arg, TTypeInfoCreator1 f)
{
return s_TypeMap_CConstRef->GetTypeInfo(arg, f);
}