本文整理汇总了C++中release_lock函数的典型用法代码示例。如果您正苦于以下问题:C++ release_lock函数的具体用法?C++ release_lock怎么用?C++ release_lock使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了release_lock函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: nrnbbs_take_string
boolean nrnbbs_take_string(const char* key, char* sval) {
history("take", key);
get_lock();
boolean b = false;
FILE* f = fopen(fname(NRNBBS), "r");
if (f != (FILE*)0) {
char name[256], val[256];
FILE* f2 = fopen(fname(TMPFILE), "w");
while (fgets(name, 256, f)) {
name[strlen(name) -1] = '\0';
if (name[0] == '\0') {
continue;
}
fgets(val, 256, f);
val[strlen(val) - 1] = '\0';
if (!b && strcmp(name, key) == 0) {
history(" found", val);
b = true;
strcpy(sval, val);
continue;
}
fprintf(f2, "%s\n%s\n", name, val);
}
fclose(f2);
fclose(f);
if (b) {
rename(fname(TMPFILE), fname(NRNBBS));
}
}else{
b = false;
}
release_lock();
return b;
}
示例2: hao_initialize
/*---------------------------------------------------------------------------*/
static int hao_initialize(void)
{
int i = 0;
int rc;
initialize_lock(&ao_lock);
/* serialize */
obtain_lock(&ao_lock);
/* initialize variables */
for(i = 0; i < HAO_MAXRULE; i++)
{
ao_cmd[i] = NULL;
ao_tgt[i] = NULL;
}
/* initialize message buffer */
memset(ao_msgbuf, 0, sizeof(ao_msgbuf));
/* Start message monitoring thread */
rc = create_thread (&haotid, JOINABLE, hao_thread, NULL, "hao_thread");
if(rc)
{
i = FALSE;
WRMSG(HHC00102, "E", strerror(rc));
}
else
i = TRUE;
release_lock(&ao_lock);
return(i);
}
示例3: sys_sem_create
/***************************************************************************
Function: sys_sem_create
Description:
Parameters:
Returns: boolean indicating success or failure
***************************************************************************/
mrapi_boolean_t sys_sem_create(int key,int num_locks,int* id) {
int i;
/* critical section:
We don't want anyone else creating/deleting while we are creating */
acquire_lock(&mrapi_db->global_lock);
/* first make sure it doesn't already exist */
for (i = 0; i < MRAPI_MAX_SEMS; i++) {
if ((mrapi_db->sys_sems[i].key == key) &&
(mrapi_db->sys_sems[i].valid)) {
break;
}
}
if (i == MRAPI_MAX_SEMS) {
/* we didn't find it so create it */
for (i = 0; i < MRAPI_MAX_SEMS; i++) {
if (!mrapi_db->sys_sems[i].valid) {
memset(&mrapi_db->sys_sems[i],0,sizeof(mrapi_sys_sem_t));
mrapi_db->sys_sems[i].valid = MRAPI_TRUE;
mrapi_db->sys_sems[i].key = key;
mrapi_db->sys_sems[i].num_locks = num_locks;
}
}
}
release_lock(&mrapi_db->global_lock);
if (i == MRAPI_MAX_SEMS) {
*id = -1;
return MRAPI_FALSE;
} else {
*id = i;
return MRAPI_TRUE;
}
}
示例4: hao_initialize
/*---------------------------------------------------------------------------*/
DLL_EXPORT int hao_initialize(void)
{
int i = 0;
initialize_lock(&ao_lock);
/* serialize */
obtain_lock(&ao_lock);
/* initialize variables */
for(i = 0; i < HAO_MAXRULE; i++)
{
ao_cmd[i] = NULL;
ao_tgt[i] = NULL;
}
/* initialize message buffer */
memset(ao_msgbuf, 0, sizeof(ao_msgbuf));
/* Start message monitoring thread */
if ( create_thread (&sysblk.haotid, JOINABLE,
hao_thread, NULL, "hao_thread") )
{
i = FALSE;
}
else
i = TRUE;
release_lock(&ao_lock);
return(i);
}
示例5: add_socket_devices_to_fd_set
/*-------------------------------------------------------------------*/
int add_socket_devices_to_fd_set (int maxfd, fd_set* readset)
{
DEVBLK* dev;
bind_struct* bs;
LIST_ENTRY* pListEntry;
obtain_lock(&bind_lock);
pListEntry = bind_head.Flink;
while (pListEntry != &bind_head)
{
bs = CONTAINING_RECORD(pListEntry,bind_struct,bind_link);
if (bs->sd != -1) /* if listening for connections, */
{
dev = bs->dev;
FD_SET(bs->sd, readset); /* then add file to set */
if (bs->sd > maxfd)
maxfd = bs->sd;
}
pListEntry = pListEntry->Flink;
}
release_lock(&bind_lock);
return maxfd;
}
示例6: quit_handler
static void quit_handler(int signo, siginfo_t *info, void *context)
{
cl_log(LOG_INFO, "quit_handler called. now releasing lock\n");
release_lock();
cl_log(LOG_INFO, "Shutdown sfex_daemon with EXIT_SUCCESS\n");
exit(EXIT_SUCCESS);
}
示例7: cleanup
static void
cleanup(debug_context_t * dc)
{
dc->stop_reason = CTX_STOP_NONE;
release_lock();
}
示例8: main
main() {
char *mem_ptr, *ctime();
long now;
int n;
seg_id = shmget(TIME_MEM_KEY, SEG_SIZE, IPC_CREAT|0777);
if( seg_id == -1 )
oops("shmget", 1);
mem_ptr = shmat(seg_id, NULL, 0);
if (mem_ptr == (void *) -1)
oops("shmat", 2);
semset_id = semget(TIME_SEM_KEY, 2, (0666|IPC_CREAT|IPC_EXCL));
if (semset_id == -1)
oops("segget", 3);
set_sem_value(semset_id, 0, 0);
set_sem_value(semset_id, 1, 0);
signal(SIGINT, cleanup);
for (n = 0; n < 60; n++) {
time(&now);
printf("\t shm_ts2 waiting for lock\n");
wait_and_lock(semset_id);
printf("\t shm_ts2 updateing memory\n");
strcpy(mem_ptr, ctime(&now));
sleep(5);
release_lock(semset_id);
printf("\t shm_ts released lock\n");
sleep(1);
}
cleanup(0);
}
示例9: TAS_backoff__main
void TAS_backoff__main(){
while(1){
acquire_lock();
c++; assert(c == 1); c--;
release_lock();
}
}
示例10: log_event
void log_event(char *message)
{
FILE *file;
struct tm *current_info;
time_t current;
char times[50];
int filedes;
time(¤t);
current_info = localtime(¤t);
current = mktime(current_info);
strftime(times,25,"%b %d %Y %H:%M",localtime(¤t));
filedes = open("event.log", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
if (filedes < 0) {
fprintf(stderr, "Cannot Get Event Log File Descriptor\n");
exit(EXIT_FAILURE);
}
if(get_lock(filedes) < 0) {
fprintf(stderr, "Cannot Obtain Event Log File Lock\n");
exit(EXIT_FAILURE);
}
file = fdopen(filedes, "a");
fprintf(file, "%s %s\n", times,message);
release_lock(filedes);
fclose(file);
close(filedes);
}
示例11: hao_clear
/*---------------------------------------------------------------------------*/
static void hao_clear(void)
{
int i;
/* serialize */
obtain_lock(&ao_lock);
/* clear all defined rules */
for(i = 0; i < HAO_MAXRULE; i++)
{
if(ao_tgt[i])
{
free(ao_tgt[i]);
ao_tgt[i] = NULL;
regfree(&ao_preg[i]);
}
if(ao_cmd[i])
{
free(ao_cmd[i]);
ao_cmd[i] = NULL;
}
}
release_lock(&ao_lock);
logmsg(HHCAO022I);
}
示例12: RLock_release
static PyObject *
RLock_release(RLock *self, PyObject *args)
{
long tid = PyThread_get_thread_ident();
if (self->count == 0 || self->owner != tid) {
PyErr_SetString(PyExc_RuntimeError,
"cannot release un-acquired lock");
return NULL;
}
if (self->count > 1) {
--self->count;
Py_RETURN_NONE;
}
assert(self->count == 1);
if (release_lock(&self->sem) != 0)
return NULL;
self->count = 0;
self->owner = 0;
Py_RETURN_NONE;
}
示例13: nrnbbs_post_string
void nrnbbs_post_string(const char* key, const char* sval) {
history("post", key, sval);
get_lock();
FILE* f = fopen(fname(NRNBBS), "a");
fprintf(f, "%s\n%s\n", key, sval);
FILE* f2 = fopen(fname(NOTIFY), "r");
char name[256];
int i, n, id[10];
n = 0;
if (f2) {
while( fgets(name, 256, f2) && n < 10) {
name[strlen(name) - 1] = '\0';
fscanf(f2, "%d\n", &i);
if (strcmp(name, key) == 0) {
id[n++] = i;
fprintf(f, "nrnbbs_notifying %s\n\n", key);
}
}
fclose(f2);
}
fclose(f);
release_lock();
for (i=0; i < n; ++i) {
history(" notify", id[i]);
kill(id[i], NOTIFY_SIGNAL);
}
}
示例14: release_lock
/** Close the project (reclaiming all memory) */
bool
Project::close ( void )
{
if ( ! open() )
return true;
if ( ! save() )
return false;
Loggable::close();
// write_info();
_is_open = false;
*Project::_name = '\0';
*Project::_created_on = '\0';
release_lock( &_lockfd, ".lock" );
delete engine;
engine = NULL;
return true;
}
示例15: lockfile_unlock
static int lockfile_unlock(lockfile_t *lf)
{
if (!lf || lf->fd == -1) {
return ERROR;
}
if (release_lock(lf->fd, 0, SEEK_SET, 0) == ERROR) {
/* Unlock entire file */
logger.error("Failed to unlock %s: %s",
lf->file, strerror(errno));
return ERROR;
}
close(lf->fd);
logger.info("Released PID file lock");
lf->fd = -1;
if (remove(lf->file) == ERROR) {
logger.warn("Failed to remove %s: %s",
lf->file, strerror(errno));
return ERROR;
}
return OK;
}