本文整理汇总了C++中mutex_t类的典型用法代码示例。如果您正苦于以下问题:C++ mutex_t类的具体用法?C++ mutex_t怎么用?C++ mutex_t使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了mutex_t类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: release
void media::release(LinkedObject **nat, unsigned expires)
{
assert(nat != NULL);
proxy *member;
time_t expire = 0;
if(!*nat)
return;
if(expires) {
time(&expire);
expire += expires;
}
lock.acquire();
linked_pointer<proxy> pp = *nat;
while(is(pp)) {
member = *pp;
pp.next();
member->release(expires);
member->enlist(&runlist);
}
lock.release();
*nat = NULL;
}
开发者ID:mehulsbhatt,项目名称:sipwitch,代码行数:27,代码来源:media.cpp
示例2: loadKernel
kernel loadKernel(occa::device_v *dHandle,
const std::string &kernelName){
infoID_t infoID;
infoID.modelID = dHandle->modelID();
infoID.kernelName = kernelName;
headerMutex.lock();
const infoHeader_t &h = headerMap[infoID];
headerMutex.unlock();
const std::string hFilename = fileDatabase::getFilename(h.fileID);
FILE *inFD = fopen(hFilename.c_str(), "rb");
char *buffer = new char[h.contentBytes + 1];
buffer[h.contentBytes] = '\0';
fseek(inFD, h.contentOffset, SEEK_SET);
ignoreResult( fread(buffer, sizeof(char), h.contentBytes, inFD) );
fclose(inFD);
kernel k = kernel(dHandle->loadKernelFromLibrary(buffer, kernelName));
delete [] buffer;
fclose(inFD);
return k;
}
开发者ID:Nasrollah,项目名称:bfam,代码行数:30,代码来源:occaLibrary.cpp
示例3: update
void messages::update(const char *uid)
{
assert(uid == NULL || *uid != 0);
linked_pointer<message> mp;
LinkedObject *next;
unsigned path;
time_t now;
if(!uid || !pending)
return;
path = NamedObject::keyindex(uid, keysize);
msglock.lock();
time(&now);
mp = msgs[path];
while(mp) {
next = mp->getNext();
if(!stricmp(mp->user, uid)) {
--pending;
mp->delist(&msgs[path]);
if(mp->expires < now)
mp->enlist(&freelist);
else
mp->enlist(&sending);
}
mp = next;
}
msglock.unlock();
}
开发者ID:mehulsbhatt,项目名称:sipwitch,代码行数:29,代码来源:messages.cpp
示例4: deliver
int messages::deliver(const char *to, const char *reply, const char *from, caddr_t text, size_t len, const char *msgtype, const char *digest)
{
message *msg;
if(!msgtype)
msgtype = "text/plain";
if(len > sizeof(msg->body))
return SIP_MESSAGE_TOO_LARGE;
msglock.lock();
msg = static_cast<message *>(freelist);
if(msg)
freelist = msg->getNext();
msglock.unlock();
if(!msg) {
++allocated;
msg = new message();
}
msg->create();
String::set(msg->reply, sizeof(msg->reply), reply);
String::set(msg->from, sizeof(msg->from), from);
String::set(msg->type, sizeof(msg->type), msgtype);
memset(msg->body, 0, sizeof(msg->body));
if(len)
memcpy(msg->body, text, len);
msg->msglen = len;
if(!strchr(to, '@')) {
String::set(msg->user, sizeof(msg->user), to);
return deliver(msg);
}
return remote(to, msg, digest);
}
开发者ID:mehulsbhatt,项目名称:sipwitch,代码行数:34,代码来源:messages.cpp
示例5: check
bool messages::check(void)
{
shell::log(shell::INFO, "checking messages...");
msglock.lock();
msglock.release();
return true;
}
开发者ID:mehulsbhatt,项目名称:sipwitch,代码行数:7,代码来源:messages.cpp
示例6: genDeviceID
int genDeviceID(){
deviceIDMutex.lock();
const int id = (currentDeviceID++);
deviceIDMutex.unlock();
return id;
}
开发者ID:Nasrollah,项目名称:bfam,代码行数:7,代码来源:occaLibrary.cpp
示例7: offload_timer_init
OffloadHostTimerData* offload_timer_init(const char *file, int line)
{
static bool first_time = true;
OffloadHostTimerData* timer_data = NULL;
timer_data_mutex.lock();
{
if (timer_enabled ||
(offload_report_level && offload_report_enabled)) {
timer_data = (OffloadHostTimerData*)
OFFLOAD_MALLOC(sizeof(OffloadHostTimerData), 0);
memset(timer_data, 0, sizeof(OffloadHostTimerData));
timer_data->offload_number = OFFLOAD_DEBUG_INCR_OFLD_NUM() - 1;
if (timer_data_head == 0) {
timer_data_head = timer_data;
timer_data_tail = timer_data;
}
else {
timer_data_tail->next = timer_data;
timer_data_tail = timer_data;
}
timer_data->file = file;
timer_data->line = line;
}
}
timer_data_mutex.unlock();
return timer_data;
}
开发者ID:SuperLu,项目名称:gcc,代码行数:31,代码来源:offload_timer_host.cpp
示例8: cleanup
void messages::cleanup(void)
{
linked_pointer<message> mp;
LinkedObject *msgnext;
unsigned msgcount = 0;
time_t now;
if(!pending)
return;
while(msgcount < keysize) {
msglock.lock();
time(&now);
mp = msgs[msgcount];
while(mp) {
msgnext = mp->getNext();
if(mp->expires < now) {
mp->delist(&msgs[msgcount]);
mp->enlist(&freelist);
}
mp = msgnext;
}
msglock.unlock();
++msgcount;
}
}
开发者ID:mehulsbhatt,项目名称:sipwitch,代码行数:26,代码来源:messages.cpp
示例9: load
void load(const std::string &filename){
//---[ Load file ]------
std::string sBuffer = readFile(filename);
const char *buffer = sBuffer.c_str();
//---[ Read file ]------
const uint32_t *buffer32 = (const uint32_t*) buffer;
const uint64_t *buffer64;
const uint32_t headerCount = *(buffer32++);
for(uint32_t i = 0; i < headerCount; ++i){
infoID_t infoID;
const int mode_ = *(buffer32++);
buffer64 = (const uint64_t*) buffer32;
const uint64_t flagsOffset = *(buffer64++);
const uint64_t flagsBytes = *(buffer64++);
const uint64_t contentOffset = *(buffer64++);
const uint64_t contentBytes = *(buffer64++);
const uint64_t kernelNameOffset = *(buffer64++);
const uint64_t kernelNameBytes = *(buffer64++);
buffer32 = (const uint32_t*) buffer64;
infoID.kernelName = std::string(buffer + kernelNameOffset,
kernelNameBytes);
deviceIdentifier identifier(mode_,
buffer + flagsOffset, flagsBytes);
infoID.modelID = deviceModelID(identifier);
kernelMutex.lock();
kernelMap[infoID.kernelName].push_back(infoID.modelID);
kernelMutex.unlock();
//---[ Input to header map ]----
headerMutex.lock();
infoHeader_t &h = headerMap[infoID];
h.fileID = fileDatabase::getFileID(filename);
h.mode = mode_;
h.flagsOffset = flagsOffset;
h.flagsBytes = flagsBytes;
h.contentOffset = contentOffset;
h.contentBytes = contentBytes;
h.kernelNameOffset = kernelNameOffset;
h.kernelNameBytes = kernelNameBytes;
headerMutex.unlock();
//==============================
}
}
开发者ID:Nasrollah,项目名称:bfam,代码行数:59,代码来源:occaLibrary.cpp
示例10: addToScratchPad
size_t addToScratchPad(const std::string &s){
scratchMutex.lock();
size_t offset = scratchPad.size();
scratchPad += s;
scratchMutex.unlock();
return offset;
}
开发者ID:Nasrollah,项目名称:bfam,代码行数:10,代码来源:occaLibrary.cpp
示例11: if
void media::thread::run(void)
{
fd_set session;
socket_t max;
shell::log(DEBUG1, "starting media thread");
running = true;
socket_t so;
media::proxy *mp;
time_t now;
while(running) {
lock.acquire();
max = hiwater;
memcpy(&session, &connections, sizeof(session));
lock.release();
select(max, &session, NULL, NULL, NULL);
if(!running)
break;
time(&now);
for(so = 0; so < max; ++so) {
#ifdef _MSWINDOWS_
#else
char buf[1];
if(so == control[0] && FD_ISSET(so, &session)) {
if(::read(so, buf, 1) < 1)
shell::log(shell::ERR, "media control failure");
continue;
}
#endif
mp = NULL;
if(!FD_ISSET(so, &session))
continue;
lock.acquire();
mp = proxymap[so];
if(mp->so == INVALID_SOCKET) {
proxymap[so] = NULL;
mp = NULL;
}
if(mp && mp->expires && mp->expires < now)
mp->release(0);
else if(mp)
mp->copy();
lock.release();
}
}
shell::log(DEBUG1, "stopping media thread");
running = true;
}
开发者ID:mehulsbhatt,项目名称:sipwitch,代码行数:54,代码来源:media.cpp
示例12: getFilename
std::string getFilename(const int id){
OCCA_CHECK((0 <= id) && (id < filesInDatabase),
"File with ID [" << id << "] was not found");
mutex.lock();
std::string filename = itsMap[id];
mutex.unlock();
return filename;
}
开发者ID:Nasrollah,项目名称:bfam,代码行数:12,代码来源:occaLibrary.cpp
示例13: deviceModelID
int deviceModelID(const occa::deviceIdentifier &id){
deviceModelMutex.lock();
deviceModelMapIterator it = deviceModelMap.find(id);
int dID;
if(it != deviceModelMap.end())
dID = it->second;
else{
dID = deviceModelMap.size();
deviceModelMap[id] = dID;
}
deviceModelMutex.unlock();
return dID;
}
开发者ID:Nasrollah,项目名称:bfam,代码行数:18,代码来源:occaLibrary.cpp
示例14: getFileID
int getFileID(const std::string &filename){
int id;
mutex.lock();
stiMapIterator it = stiMap.find(filename);
if(it == stiMap.end()){
id = (filesInDatabase++);
stiMap[filename] = id;
itsMap[id] = filename;
}
else
id = (it->second);
mutex.unlock();
return id;
}
开发者ID:Nasrollah,项目名称:bfam,代码行数:20,代码来源:occaLibrary.cpp
示例15: loadKernelDatabase
occa::kernelDatabase loadKernelDatabase(const std::string &kernelName){
kernelDatabase kdb(kernelName);
kernelMutex.lock();
kernelMapIterator it = kernelMap.find(kernelName);
if(it != kernelMap.end()){
std::vector<int> &ids = it->second;
const int idCount = ids.size();
for(int i = 0; i < idCount; ++i)
kdb.modelKernelIsAvailable(ids[i]);
}
kernelMutex.unlock();
return kdb;
}
开发者ID:Nasrollah,项目名称:bfam,代码行数:20,代码来源:occaLibrary.cpp
示例16: ClearInterruptFlag
void ClearInterruptFlag(uint32 flag)
{
intflags_mutex.lock();
InterruptFlags &= ~flag;
intflags_mutex.unlock();
}
开发者ID:tycho,项目名称:sheepshaver,代码行数:6,代码来源:main_windows.cpp
示例17: SetInterruptFlag
void SetInterruptFlag(uint32 flag)
{
intflags_mutex.lock();
InterruptFlags |= flag;
intflags_mutex.unlock();
}
开发者ID:tycho,项目名称:sheepshaver,代码行数:6,代码来源:main_windows.cpp
示例18: while
void media::sdp::check_media(char *buffer, size_t len)
{
char *cp, *ep, *sp;
char tmp[128];
char mtype[32];
unsigned tport;
unsigned count = 1;
media::proxy *pp;
if(strnicmp(buffer, "m=", 2))
return;
cp = sp = strchr(buffer, ' ');
if(!cp)
return;
while(isspace(*cp))
++cp;
tport = atoi(cp);
if(!tport)
return;
ep = strchr(cp, '/');
if(ep)
count = atoi(ep + 1);
// at the moment we can only do rtp/rtcp pairs...
if(count > 2) {
result = NULL;
return;
}
mediacount = count;
count = align(count);
ep = strchr(cp, ' ');
if(!ep)
ep = (char *)"";
else while(isspace(*ep))
++ep;
mediaport = tport;
mediacount = count;
tport = 0;
lock.acquire();
String::set(tmp, sizeof(tmp), ep);
while(count--) {
pp = media::get(this);
if(!pp) {
result = NULL;
lock.release();
return;
}
if(!tport)
tport = (pp->port / 2) * 2;
}
lock.release();
*sp = 0;
String::set(mtype, sizeof(mtype), buffer);
if(mediacount > 1)
snprintf(buffer, len, "%s %u/%u %s",
mtype, tport, mediacount, tmp);
else
snprintf(buffer, len, "%s %u %s",
mtype, tport, tmp);
mediacount = align(mediacount);
}
开发者ID:mehulsbhatt,项目名称:sipwitch,代码行数:71,代码来源:media.cpp
示例19: save
void save(const std::string &filename){
headerMutex.lock();
FILE *outFD = fopen(filename.c_str(), "wb");
uint32_t headerCount = headerMap.size();
if(headerCount == 0){
headerMutex.unlock();
return;
}
fwrite(&headerCount, sizeof(uint32_t), 1, outFD);
cHeaderMapIterator it = headerMap.begin();
const uint64_t headerOffset = headerCount * (( sizeof(uint32_t)) +
(6*sizeof(uint64_t)));
uint64_t contentOffsets = sizeof(headerCount) + headerOffset;
for(uint32_t i = 0; i < headerCount; ++i){
const infoHeader_t &h = it->second;
fwrite(&(h.mode), sizeof(uint32_t), 1, outFD);
fwrite(&(contentOffsets), sizeof(uint64_t), 1, outFD);
fwrite(&(h.flagsBytes) , sizeof(uint64_t), 1, outFD);
contentOffsets += h.flagsBytes;
fwrite(&(contentOffsets), sizeof(uint64_t), 1, outFD);
fwrite(&(h.contentBytes), sizeof(uint64_t), 1, outFD);
contentOffsets += h.contentBytes;
fwrite(&(contentOffsets) , sizeof(uint64_t), 1, outFD);
fwrite(&(h.kernelNameBytes), sizeof(uint64_t), 1, outFD);
contentOffsets += h.kernelNameBytes;
++it;
}
it = headerMap.begin();
for(uint32_t i = 0; i < headerCount; ++i){
const infoHeader_t &h = it->second;
++it;
char *buffer = new char[std::max(h.flagsBytes,
std::max(h.contentBytes,
h.kernelNameBytes))];
if(0 <= h.fileID){
const std::string hFilename = fileDatabase::getFilename(h.fileID);
FILE *inFD = fopen(hFilename.c_str(), "rb");
fseek(inFD, h.flagsOffset, SEEK_SET);
ignoreResult( fread(buffer , sizeof(char), h.flagsBytes, inFD) );
fwrite(buffer, sizeof(char), h.flagsBytes, outFD);
ignoreResult( fread(buffer , sizeof(char), h.contentBytes, inFD) );
fwrite(buffer, sizeof(char), h.contentBytes, outFD);
ignoreResult( fread(buffer , sizeof(char), h.kernelNameBytes, inFD) );
fwrite(buffer, sizeof(char), h.kernelNameBytes, outFD);
fclose(inFD);
delete [] buffer;
}
else{
const char *c = scratchPad.c_str();
const char *c1 = c + h.flagsOffset;
const char *c2 = c + h.contentOffset;
const char *c3 = c + h.kernelNameOffset;
fwrite(c1, sizeof(char), h.flagsBytes , outFD);
fwrite(c2, sizeof(char), h.contentBytes , outFD);
fwrite(c3, sizeof(char), h.kernelNameBytes, outFD);
}
}
fclose(outFD);
headerMutex.unlock();
}
开发者ID:Nasrollah,项目名称:bfam,代码行数:85,代码来源:occaLibrary.cpp
注:本文中的mutex_t类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论