本文整理汇总了C++中mutex_t类的典型用法代码示例。如果您正苦于以下问题:C++ mutex_t类的具体用法?C++ mutex_t怎么用?C++ mutex_t使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了mutex_t类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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;
}
示例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();
}
示例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);
}
示例5: check
bool messages::check(void)
{
shell::log(shell::INFO, "checking messages...");
msglock.lock();
msglock.release();
return true;
}
示例6: genDeviceID
int genDeviceID(){
deviceIDMutex.lock();
const int id = (currentDeviceID++);
deviceIDMutex.unlock();
return id;
}
示例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;
}
示例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;
}
}
示例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();
//==============================
}
}
示例10: addToScratchPad
size_t addToScratchPad(const std::string &s){
scratchMutex.lock();
size_t offset = scratchPad.size();
scratchPad += s;
scratchMutex.unlock();
return offset;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}