本文整理汇总了C++中sem_p函数的典型用法代码示例。如果您正苦于以下问题:C++ sem_p函数的具体用法?C++ sem_p怎么用?C++ sem_p使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sem_p函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: doTerminateInstance
static int
doTerminateInstance( struct nc_state_t *nc,
ncMetadata *meta,
char *instanceId,
int *shutdownState,
int *previousState)
{
ncInstance *instance, *vninstance;
virConnectPtr *conn;
int err;
sem_p (inst_sem);
instance = find_instance(&global_instances, instanceId);
sem_v (inst_sem);
if (instance == NULL)
return NOT_FOUND;
/* try stopping the KVM domain */
conn = check_hypervisor_conn();
if (conn) {
sem_p(hyp_sem);
virDomainPtr dom = virDomainLookupByName(*conn, instanceId);
sem_v(hyp_sem);
if (dom) {
/* also protect 'destroy' commands, just in case */
sem_p (hyp_sem);
err = virDomainDestroy (dom);
sem_v (hyp_sem);
if (err==0) {
logprintfl (EUCAINFO, "destroyed domain for instance %s\n", instanceId);
}
sem_p(hyp_sem);
virDomainFree(dom); /* necessary? */
sem_v(hyp_sem);
} else {
if (instance->state != BOOTING)
logprintfl (EUCAWARN, "warning: domain %s to be terminated not running on hypervisor\n", instanceId);
}
}
/* change the state and let the monitoring_thread clean up state */
sem_p (inst_sem);
if (instance->state==BOOTING) {
change_state (instance, CANCELED);
} else {
change_state (instance, SHUTOFF);
}
sem_v (inst_sem);
*previousState = instance->stateCode;
*shutdownState = instance->stateCode;
return OK;
}
开发者ID:chrkl,项目名称:eucalyptus,代码行数:53,代码来源:handlers_default.c
示例2: main
int main(int argc, char *argv[])
{
//前面一大块4个人物其实都是一样的,就是看看semget是不是分配成功,共享区是不是分享成功
int i,item,shmid;
semaphore mutex,pan,orange;
union semun sem_union;
void *shared_memory = (void *)0;
struct shared_use_st *shared_stuff;
if ( (mutex=semget((key_t)KEY_MUTEX,1,0666|IPC_CREAT)) == -1 ) {
fprintf(stderr,"Failed to create semaphore!");
exit(EXIT_FAILURE);
}
if ( (pan = semget((key_t)KEY_PAN,1,0666|IPC_CREAT)) == -1 ) {
fprintf(stderr,"Failed to create semaphore!");
exit(EXIT_FAILURE);
}
if ( (orange = semget((key_t)KEY_ORANGE,1,0666|IPC_CREAT)) == -1 ) {
fprintf(stderr,"Failed to create semaphore!");
exit(EXIT_FAILURE);
}
if ( (shmid = shmget((key_t)KEY_SHM,sizeof(struct shared_use_st),0666|IPC_CREAT)) == -1 ) {
fprintf(stderr,"Failed to create shared memory!");
exit(EXIT_FAILURE);
}
if ( (shared_memory = shmat(shmid,(void *)0,0) ) == (void *)-1) {
fprintf(stderr,"shmat failed\n");
exit(EXIT_FAILURE);
}
shared_stuff = (struct shared_use_st *)shared_memory;
//这个是模仿老师的30个,其实通过sleep的时间调整,能让dad和mother经常拿到不同盘子,比较接近的话,会一直拿到一样的盘子的
for(i=0;i<30;i++)
{
sleep(0.9);
sem_p(pan);
sem_p(mutex);
(shared_stuff->hi) = ((shared_stuff->hi)+1) % BUFFER_SIZE;
item = ((int)shared_stuff->hi)+1;
printf("Mother use pan %d put the orange\n",item);
sem_v(mutex);
sem_v(orange);
}
if (shmdt(shared_memory) == -1) {
fprintf(stderr, "shmdt failed\n");
exit(EXIT_FAILURE);
}
printf("Finish!\n");
getchar();
exit(EXIT_SUCCESS);
}
开发者ID:wwxFromTju,项目名称:tju_OperatingSystem,代码行数:52,代码来源:mother.c
示例3: diskutil_loop
int diskutil_loop (const char * path, const long long offset, char * lodev, int lodev_size)
{
int found = 0;
int done = 0;
int ret = OK;
char * output;
// we retry because we cannot atomically obtain a free loopback
// device on all distros (some versions of 'losetup' allow a file
// argument with '-f' options, but some do not)
for (int i=0; i<LOOP_RETRIES; i++) {
sem_p (loop_sem);
output = pruntf (TRUE, "%s %s -f", helpers_path[ROOTWRAP], helpers_path[LOSETUP]);
sem_v (loop_sem);
if (output==NULL) // there was a problem
break;
if (strstr (output, "/dev/loop")) {
strncpy (lodev, output, lodev_size);
char * ptr = strrchr (lodev, '\n');
if (ptr) {
*ptr = '\0';
found = 1;
}
}
free (output);
if (found) {
boolean do_log = ((i+1)==LOOP_RETRIES); // log error on last try only
logprintfl (EUCADEBUG, "{%u} attaching file %s\n", (unsigned int)pthread_self(), path);
logprintfl (EUCADEBUG, "{%u} to %s at offset %lld\n", (unsigned int)pthread_self(), lodev, offset);
sem_p (loop_sem);
output = pruntf (do_log, "%s %s -o %lld %s %s", helpers_path[ROOTWRAP], helpers_path[LOSETUP], offset, lodev, path);
sem_v (loop_sem);
if (output==NULL) {
logprintfl (EUCADEBUG, "{%u} cannot attach to loop device %s (will retry)\n", (unsigned int)pthread_self(), lodev);
} else {
free (output);
done = 1;
break;
}
}
sleep (1);
found = 0;
}
if (!done) {
logprintfl (EUCAINFO, "{%u} error: cannot find free loop device or attach to one\n", (unsigned int)pthread_self());
ret = ERROR;
}
return ret;
}
开发者ID:EucalyptusSystems,项目名称:eucalyptus,代码行数:52,代码来源:diskutil.c
示例4: doAttachSystemDisk
static int
doAttachSystemDisk ( struct nc_state_t *nc,
ncMetadata *meta,
char *instanceId,
char *isoPath)
{
ncInstance *instance;
virConnectPtr *conn;
virDomainPtr dom = NULL;
char xml[MAX_PATH]={'\0'};
int err;
snprintf (xml, sizeof(xml), "<disk type='block' device='cdrom'><source dev='%s'/><target dev='hdc' bus='ide'/><readonly/></disk>", isoPath);
//logprintfl(EUCAINFO, "doAttachSystemDisk(): founded %s [%s---%s---%d]\n", instanceId,__FILE__, __FUNCTION__, __LINE__);
sem_p(inst_sem);
instance = find_instance(&global_instances, instanceId);
sem_v(inst_sem);
if (instance == NULL || (instance->state != RUNNING&& instance->state != BLOCKED&& instance->state !=PAUSED)) {
logprintfl(EUCAINFO, "doAttachSystemDisk(): found %s failed or instance->state!=RUNNING||BLOCKED||PAUSED [file:%s---line:%d]\n", instanceId, __FILE__, __LINE__);
return NOT_FOUND;
}
conn = check_hypervisor_conn();
if (conn) {
/*
snprintf(cmd, sizeof(cmd), "virsh attach-disk %s %s hdc --type cdrom --mode readonly",instanceId, isoPath);
logprintfl(EUCAINFO, "xiongm: cmd=%s [%s---%s---%d]\n",cmd, __FILE__, __FUNCTION__, __LINE__);
system(cmd);
*/
dom = NULL;
sem_p(hyp_sem);
dom = virDomainLookupByName(*conn, instanceId);
sem_v(hyp_sem);
if (dom) {
sem_p (hyp_sem);
err = virDomainAttachDevice (dom, xml);
sem_v (hyp_sem);
if(err != 0) {
logprintfl(EUCAINFO,"virDomainAttachDevice failed. err=%d\n",err);
return 1;
}
}
logprintfl(EUCAINFO,"doAttachSystemDisk success.\n");
return 0;
}
else {
logprintfl(EUCAINFO, "doAttachSystemDisk(): no connect hypervisior [file:%s---line:%d]\n",__FILE__, __LINE__);
return 1;
}
}
开发者ID:donhall,项目名称:shijiemori-dev,代码行数:48,代码来源:handlers_kvm.c
示例5: disconnect_ebs_volume
//!
//! Detach a local device that is iSCSI and disconnect the session.
//!
//! @param[in] sc_url - The URL to reach the cluster's SC at.
//! @param[in] use_ws_sec - boolean to determine use of WS-SEC.
//! @param[in] ws_sec_policy_file - Policy file path for WS-SEC
//! @param[in] attachment_token - The volume/token string received in the request that will be used
//! @param[in] connect_string - The connect string used for attachment, to be re-used on disconnect
//! @param[in] local_ip - The local host's external IP
//! @param[in] local_iqn - The local host's IQN
//!
//! @return
//!
//! @pre
//!
//! @post
//!
//! @note should only be invoked after detachment from the guest
//!
int disconnect_ebs_volume(char *sc_url, int use_ws_sec, char *ws_sec_policy_file, char *attachment_token, char *connect_string, char *local_ip, char *local_iqn)
{
int ret = EUCA_ERROR;
int norescan = 0; //send a 0 to indicate no rescan requested
ebs_volume_data *vol_data = NULL;
if (attachment_token == NULL || connect_string == NULL || local_ip == NULL || local_iqn == NULL) {
LOGERROR("Cannont disconnect ebs volume. Got NULL input parameters.\n");
return EUCA_ERROR;
}
LOGTRACE("Disconnecting an EBS volume\n");
if (deserialize_volume(attachment_token, &vol_data) != EUCA_OK) {
LOGERROR("Could not deserialize attachment token string %s\n", attachment_token);
return EUCA_ERROR;
}
LOGTRACE("Requesting volume lock\n");
sem_p(vol_sem);
{
LOGTRACE("Got volume lock\n");
ret = cleanup_volume_attachment(sc_url, use_ws_sec, ws_sec_policy_file, vol_data, connect_string, local_ip, local_iqn, norescan);
LOGTRACE("cleanup_volume_attachment returned: %d\n", ret);
LOGTRACE("Releasing volume lock\n");
}
sem_v(vol_sem);
LOGTRACE("Released volume lock\n");
EUCA_FREE(vol_data);
return ret;
}
开发者ID:AsherBond,项目名称:eucalyptus,代码行数:51,代码来源:ebs_utils.c
示例6: doRebootInstance
static int
doRebootInstance( struct nc_state_t *nc,
ncMetadata *meta,
char *instanceId)
{
sem_p (inst_sem);
ncInstance *instance = find_instance (&global_instances, instanceId);
sem_v (inst_sem);
if ( instance == NULL ) {
logprintfl (EUCAERROR, "cannot find instance %s\n", instanceId);
return ERROR;
}
pthread_t tcb;
// since shutdown/restart may take a while, we do them in a thread
if ( pthread_create (&tcb, NULL, rebooting_thread, (void *)instance) ) {
logprintfl (EUCAERROR, "failed to spawn a reboot thread\n");
return ERROR_FATAL;
}
if (pthread_detach(tcb)) {
logprintfl (EUCAERROR, "failed to detach the rebooting thread\n");
return ERROR_FATAL;
}
return OK;
}
开发者ID:donhall,项目名称:shijiemori-dev,代码行数:26,代码来源:handlers_kvm.c
示例7: diskutil_unloop
int diskutil_unloop (const char * lodev)
{
int ret = OK;
char * output;
int retried = 0;
logprintfl (EUCADEBUG, "{%u} detaching from loop device %s\n", (unsigned int)pthread_self(), lodev);
// we retry because we have seen spurious errors from 'losetup -d' on Xen:
// ioctl: LOOP_CLR_FD: Device or resource bus
for (int i=0; i<LOOP_RETRIES; i++) {
boolean do_log = ((i+1)==LOOP_RETRIES); // log error on last try only
sem_p (loop_sem);
output = pruntf (do_log, "%s %s -d %s", helpers_path[ROOTWRAP], helpers_path[LOSETUP], lodev);
sem_v (loop_sem);
if (!output) {
ret = ERROR;
} else {
ret = OK;
free (output);
break;
}
logprintfl (EUCADEBUG, "{%u} cannot detach loop device %s (will retry)\n", (unsigned int)pthread_self(), lodev);
retried++;
sleep (1);
}
if (ret == ERROR) {
logprintfl (EUCAWARN, "{%u} error: cannot detach loop device\n", (unsigned int)pthread_self());
} else if (retried) {
logprintfl (EUCAINFO, "{%u} succeeded to detach %s after %d retries\n", (unsigned int)pthread_self(), lodev, retried);
}
return ret;
}
开发者ID:EucalyptusSystems,项目名称:eucalyptus,代码行数:34,代码来源:diskutil.c
示例8: sem_down
int sem_down(struct proc *p, int sem)
{
if (sem < 0) {
fprintf(stderr, "sem_down: Invalid semaphor (pid %u)\n", p->pid);
return 1;
}
switch (sem_p(sem)) {
case -1:
fprintf(stderr, "sem_down: error putting semaphor down (pid %u)\n", p->pid);
return 1;
case 0:
return 0;
case 1:
if (retry_op(p) != 0) {
fprintf(stderr, "sem_down: error resetting IC (pid %u)\n", p->pid);
return 1;
}
sched_suspend(p->pid);
if (insert_proc(&sem_wq[sem], p) != 0) {
fprintf(stderr, "sem_down: error adding self to wait queue (pid %u)\n", p->pid);
return 1;
}
return 0;
default:
fprintf(stderr, "sem_down: unexpected value returned from p() (pid %u)\n", p->pid);
return 1;
}
}
开发者ID:mtstickney,项目名称:BRAIN-Project-4,代码行数:28,代码来源:sem.c
示例9: doRebootInstance
//!
//! Handles the reboot request of an instance.
//!
//! @param[in] nc a pointer to the NC state structure to initialize
//! @param[in] pMeta a pointer to the node controller (NC) metadata structure
//! @param[in] instanceId the instance identifier string (i-XXXXXXXX)
//!
//! @return EUCA_OK on success or proper error code. Known error code returned include:
//! EUCA_ERROR, EUCA_NOT_FOUND_ERROR, and EUCA_FATAL_ERROR.
//!
static int doRebootInstance(struct nc_state_t *nc, ncMetadata * pMeta, char *instanceId)
{
pthread_t tcb = { 0 };
ncInstance *instance = NULL;
rebooting_thread_params *params = NULL;
sem_p(inst_sem);
{
instance = find_instance(&global_instances, instanceId);
}
sem_v(inst_sem);
if (instance == NULL) {
LOGERROR("[%s] cannot find instance\n", instanceId);
return (EUCA_NOT_FOUND_ERROR);
}
params = EUCA_ZALLOC(1, sizeof(rebooting_thread_params));
memcpy(&(params->instance), instance, sizeof(ncInstance));
memcpy(&(params->nc), nc, sizeof(struct nc_state_t));
// since shutdown/restart may take a while, we do them in a thread
if (pthread_create(&tcb, NULL, rebooting_thread, params)) {
LOGERROR("[%s] failed to spawn a reboot thread\n", instanceId);
return (EUCA_FATAL_ERROR);
}
set_corrid_pthread(get_corrid() != NULL ? get_corrid()->correlation_id : NULL, tcb);
if (pthread_detach(tcb)) {
LOGERROR("[%s] failed to detach the rebooting thread\n", instanceId);
return (EUCA_FATAL_ERROR);
}
return (EUCA_OK);
}
开发者ID:dkavanagh,项目名称:eucalyptus,代码行数:43,代码来源:handlers_kvm.c
示例10: disconnect_iscsi_target
int disconnect_iscsi_target (const char *dev_string)
{
int pid, retval, status;
assert (strlen (home));
logprintfl (EUCAINFO, "disconnect_iscsi_target invoked (dev_string=%s)\n", dev_string);
sem_p (iscsi_sem);
pid = fork();
if (!pid) {
if ( dev_string && strlen(dev_string) ) logprintfl(EUCADEBUG, "disconnect_iscsi_target(): running command: %s %s,%s\n", disconnect_storage_cmd_path, home, dev_string);
if (vrun("%s %s,%s", disconnect_storage_cmd_path, home, dev_string) != 0) {
logprintfl (EUCAERROR, "ERROR: disconnect_iscsi_target failed\n");
exit(1);
}
exit(0);
} else {
retval = timewait(pid, &status, 90);
if (retval) {
retval = WEXITSTATUS(status);
} else {
kill(pid, SIGKILL);
retval = -1;
}
}
sem_v (iscsi_sem);
return retval;
}
开发者ID:EucalyptusSystems,项目名称:eucalyptus,代码行数:29,代码来源:iscsi.c
示例11: main
int main()
{
int semid, shmid;
char *shmaddr;
if ((shmid = createshm(".", 'm', SHM_SIZE)) == -1){
exit (1);
}
if((shmaddr = shmat (shmid, (char *)0, 0)) == (char *)-1){
perror ("attach shared memory error!\n");
exit (1);
}
if((semid = opensem("." ,'s')) == -1){
exit (1);
}
while(1){
printf("reader: ");
sem_p(semid,0); /* P操作 */
printf("%s", shmaddr);
sem_v(semid,0); /* V操作 */
}
}
开发者ID:Ccodelernen,项目名称:AUP_exam,代码行数:27,代码来源:shmSem_reader.c
示例12: wait_for_file
/* wait for file 'appear' to appear or for file 'disappear' to disappear */
static int wait_for_file (const char * appear, const char * disappear, const int iterations, const char * name)
{
int done, i;
if (!appear && !disappear) return 1;
for ( i=0, done=0; i<iterations && !done; i++ ) {
struct stat mystat;
sem_p (sc_sem);
int check = ( (appear && (stat (appear, &mystat)==0)) ||
(disappear && (stat (disappear, &mystat)!=0)) );
sem_v (sc_sem);
if (check) {
done++;
} else {
if (i==0) {
logprintfl (EUCAINFO, "waiting for %s to become ready...\n", name);
}
sleep (10);
}
}
if (!done) {
logprintfl (EUCAERROR, "ERROR: timed out waiting for %s to become ready\n", name);
return 1;
}
return 0;
}
开发者ID:chrkl,项目名称:eucalyptus,代码行数:28,代码来源:storage.c
示例13: create_instance_backing
int create_instance_backing (ncInstance * instance)
{
int ret = ERROR;
virtualMachine * vm = &(instance->params);
artifact * sentinel = NULL;
// ensure instance directory exists
set_path (instance->instancePath, sizeof (instance->instancePath), instance, NULL);
if (ensure_directories_exist (instance->instancePath, 0, NULL, "root", BACKING_DIRECTORY_PERM) == -1)
goto out;
// set various instance-directory-relative paths in the instance struct
set_path (instance->xmlFilePath, sizeof (instance->xmlFilePath), instance, "instance.xml");
set_path (instance->libvirtFilePath, sizeof (instance->libvirtFilePath), instance, "libvirt.xml");
set_path (instance->consoleFilePath, sizeof (instance->consoleFilePath), instance, "console.log");
if (strstr (instance->platform, "windows")) {
// generate the floppy file for windows instances
if (makeWindowsFloppy (nc_state.home, instance->instancePath, instance->keyName, instance->instanceId)) {
logprintfl (EUCAERROR, "[%s] error: could not create windows bootup script floppy\n", instance->instanceId);
goto out;
} else {
set_path (instance->floppyFilePath, sizeof (instance->floppyFilePath), instance, "floppy");
}
}
char work_prefix [1024]; // {userId}/{instanceId}
set_id (instance, NULL, work_prefix, sizeof (work_prefix));
// compute tree of dependencies
sentinel = vbr_alloc_tree (vm, // the struct containing the VBR
FALSE, // for Xen and KVM we do not need to make disk bootable
TRUE, // make working copy of runtime-modifiable files
(instance->do_inject_key)?(instance->keyName):(NULL), // the SSH key
instance->instanceId); // ID is for logging
if (sentinel == NULL) {
logprintfl (EUCAERROR, "[%s] error: failed to prepare backing for instance\n", instance->instanceId);
goto out;
}
sem_p (disk_sem);
// download/create/combine the dependencies
int rc = art_implement_tree (sentinel, work_bs, cache_bs, work_prefix, INSTANCE_PREP_TIMEOUT_USEC);
sem_v (disk_sem);
if (rc != OK) {
logprintfl (EUCAERROR, "[%s] error: failed to implement backing for instance\n", instance->instanceId);
goto out;
}
if (save_instance_struct (instance)) // update instance checkpoint now that the struct got updated
goto out;
ret = OK;
out:
if (sentinel)
art_free (sentinel);
return ret;
}
开发者ID:gcloudpaulwang,项目名称:eucalyptus,代码行数:58,代码来源:backing.c
示例14: processor
/**
Searches the processor state array for a free processor (state <= 0).
@param states The array of processor states. Each cell <i>i</i> contains a
key such that:<br>
<ul><li>If <b>key < 0</b>, processor has completed the |key|-th operation
<li>If <b>key == 0</b>, processor has not received an operation yet
<li>If <b>key > 0</b>, processor is currently working on the key-th operation</ul>
@return The ID of a free processor
*/
static int find_proc(int *states) {
int i = 0;
sem_p(2 * processors);
write_to_fd(1, "Looking for a free processor\n");
while(states[i++] > 0);
sem_v(2 * processors);
write_with_int(1, "Found processor ", i);
return i - 1;
}
开发者ID:dmazzoni,项目名称:ElaboratoIPC,代码行数:19,代码来源:main.c
示例15: staebchen_weglegen
void staebchen_weglegen(int my_id, int pos) {
printf("%i legt %i weg\n", my_id, pos);
if (staebchen[pos]!=0) {
printf("Fehler: staebchen[%i]=%i statt 0\n", pos, staebchen[pos]);
exit(1);
}
sem_p(sem[pos]);
staebchen[pos]++; // ergibt 1, gibt aber chance zur fehlererkennung
sem_v(sem[pos]);
}
开发者ID:nastye,项目名称:gdbslab,代码行数:10,代码来源:fuenf_phil.c
示例16: main
int
main() {
int i, item, shmid;
semaphore mutex;
semaphore dif1;
semaphore dif2;
void* shared_memory = NULL;
struct shared_use_st* shared_stuff = NULL;
if ((mutex = semget((key_t)KEY_MUTEX, 1, 0666|IPC_CREAT)) == -1) {
fprintf(stderr, "Failed to create semaphore!\n");
exit(EXIT_FAILURE);
}
if ((dif1 = semget((key_t)KEY_EMPTY, 1, 0666|IPC_CREAT)) == -1) {
fprintf(stderr, "Failed to create semaphore!\n");
exit(EXIT_FAILURE);
}
if ((dif2 = semget((key_t)KEY_FULL, 1, 0666|IPC_CREAT)) == -1) {
fprintf(stderr, "Failed to create semaphore!\n");
exit(EXIT_FAILURE);
}
if ((shmid = shmget((key_t)KEY_SHM, 1, 0666|IPC_CREAT)) == -1) {
fprintf(stderr, "Failed to create semaphore!\n");
exit(EXIT_FAILURE);
}
if ((shared_memory = shmat(shmid, NULL, 0)) == (void*)(-1)) {
fprintf(stderr, "shmat failed!\n");
exit(EXIT_FAILURE);
}
shared_stuff = (struct shared_use_st*)shared_memory;
for (i = 0; i < 30; ++i) {
sleep(1);
sem_p(dif2);
sem_p(mutex);
shared_stuff->high++;
print(shared_stuff);
sem_v(dif1);
sem_v(mutex);
}
exit(EXIT_SUCCESS);
}
开发者ID:3013216027,项目名称:OS2015,代码行数:43,代码来源:putA.c
示例17: doRestoreAInstance
static int doRestoreAInstance(struct nc_state_t *nc, ncMetadata *meta, char *instanceId) {
sem_p(inst_sem);
ncInstance *instance = find_instance(&global_instances, instanceId);
sem_v(inst_sem);
if (instance == NULL || (instance->state != SHUTOFF && instance->state != TRASHED)) {
logprintfl(EUCAINFO, "doRestoreAInstance: found instance %s in global_instances error or instance->state!=SHUTOFF||TRASHED \n", instanceId);
return NOT_FOUND;
}
if(instance->state == SHUTOFF) {
pthread_t tcb;
if(pthread_create(&tcb, NULL, restoring_thread, (void *)instance)) {
logprintfl (EUCAERROR, "failed to spawn a restore thread\n");
return ERROR_FATAL;
}
if (pthread_detach(tcb)) {
logprintfl (EUCAERROR, "failed to detach the restoring thread\n");
return ERROR_FATAL;
}
} else { //instance->state == TRASHED
sem_p (inst_sem);
change_state(instance,SHUTOFF);
save_instance_struct(instance);
sem_v (inst_sem);
logprintfl(EUCAINFO, "doRestoreAInstance restore instance form TRASHED TO SHUTOFF success next to running it instanceId=%s \n", instanceId);
//add 20130106-xm
pthread_t tcb;
if(pthread_create(&tcb, NULL, restoring_thread, (void *)instance)) {
logprintfl (EUCAERROR, "failed to spawn a restore thread\n");
return ERROR_FATAL;
}
if (pthread_detach(tcb)) {
logprintfl (EUCAERROR, "failed to detach the restoring thread\n");
return ERROR_FATAL;
}
// end 20130106-xm
}
return OK;
}
开发者ID:donhall,项目名称:shijiemori-dev,代码行数:42,代码来源:handlers_kvm.c
示例18: busy_child_routine_2
//----------------------------------------------------------------------------------------------------------------
void busy_child_routine_2(int child_id){
// attende che abbia finito il calcolo
print_parent_info(""PARENT" waiting that child %d finish to process the operation\n", child_id);
sem_p(sem_computing, child_id);
// richiede eventuali dati precedenti
print_parent_info(""PARENT" request the result to child %d\n", child_id);
sem_v(sem_request_result, child_id);
//aspetta che i dati siano pronti da leggere
print_parent_info(""PARENT" waiting for result from child %d ...\n", child_id);
sem_p(sem_parent, 1);
//print_parent_info(""PARENT" saving the result of opration processed from child %d...\n", child_id);
}
开发者ID:SimoGira,项目名称:ipc,代码行数:21,代码来源:parent.c
示例19: main
int main(int argc, char *argv[])
{
int opt;
opt = getopt(argc, argv, "cdpvs:gfm:");
if (opt == '?')
exit(EXIT_FAILURE);
if (opt == -1)
{
usage();
exit(EXIT_FAILURE);
}
key_t key = ftok(".", 's');
int semid;
switch (opt)
{
case 'c':
sem_create(key);
break;
case 'p':
semid = sem_open(key);
sem_p(semid);
sem_getval(semid);
break;
case 'v':
semid = sem_open(key);
sem_v(semid);
sem_getval(semid);
break;
case 'd':
semid = sem_open(key);
sem_d(semid);
break;
case 's':
semid = sem_open(key);
sem_setval(semid, atoi(optarg));
break;
case 'g':
semid = sem_open(key);
sem_getval(semid);
break;
case 'f':
semid = sem_open(key);
sem_getmode(semid);
break;
case 'm':
semid = sem_open(key);
sem_setmode(semid, argv[2]);
break;
}
return 0;
}
开发者ID:hzsunzixiang,项目名称:programming,代码行数:54,代码来源:semtool.c
示例20: OptLogGet
int OptLogGet(ST_OptLogCfgData *val)
{
if (!val || !gendata.cfg)
{
return -1;
}
sem_p(gendata.semid);
memcpy(val,gendata.cfg,sizeof(ST_OptLogCfgData));
sem_v(gendata.semid);
return 0;
}
开发者ID:xuqi1987,项目名称:18.Car,代码行数:11,代码来源:OperationLog.c
注:本文中的sem_p函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论