Exemplo n.º 1
0
void Yap_init_local(void) {
#ifdef YAPOR
    /* local data related to or-parallelism */
    LOCAL = REMOTE + worker_id;
    Set_LOCAL_top_cp((choiceptr) Yap_LocalBase);
    LOCAL_top_or_fr = GLOBAL_root_or_fr;
    LOCAL_load = 0;
    LOCAL_share_request = MAX_WORKERS;
    LOCAL_reply_signal = worker_ready;
#ifdef ENV_COPY
    INIT_LOCK(LOCAL_lock_signals);
#endif /* ENV_COPY */
    Set_LOCAL_prune_request(NULL);
#endif /* YAPOR */
    INIT_LOCK(LOCAL_lock);
#ifdef TABLING
    /* local data related to tabling */
    LOCAL_next_free_ans_node = NULL;
    LOCAL_top_sg_fr = NULL;
    LOCAL_top_dep_fr = GLOBAL_root_dep_fr;
#ifdef YAPOR
    Set_LOCAL_top_cp_on_stack((choiceptr) Yap_LocalBase); /* ??? */
    LOCAL_top_susp_or_fr = GLOBAL_root_or_fr;
#endif /* YAPOR */
#endif /* TABLING */
    return;
}
Exemplo n.º 2
0
int main (int argc, char *argv[])
{
	uint8_t ret, cnt;
	pthread_t tid[numThreads];

	printf("\t %s: Start\n", __func__);

	createFreeList(numListElm, &gFreeList);

	INIT_LOCK(freeListLock);
	INIT_LOCK(list1Lock);
	INIT_LOCK(list2Lock);

	for (cnt = 0; cnt < numThreads; cnt++) {
		ret = pthread_create(&tid[cnt], NULL, fptr[cnt], NULL);
		assert(ret == 0);
	}

	printf("\t %s: End\n", __func__);

	for (cnt = 0; cnt < numThreads; cnt++) {
		ret = pthread_join(tid[cnt], NULL);
		assert(ret == 0);
	}

	return 0;
}
Exemplo n.º 3
0
static copy_on_write_t*
copy_on_write_new_init(size_t num_buckets)
{
  copy_on_write_t* cow;
  cow = ssalloc_aligned(CACHE_LINE_SIZE, sizeof(copy_on_write_t));
  assert(cow != NULL);
  
  cow->num_buckets = num_buckets;
  cow->hash = cow->num_buckets - 1;

#if defined(LL_GLOBAL_LOCK)
  cow->lock = ssalloc_aligned(CACHE_LINE_SIZE, sizeof(ptlock_t));
  assert(cow->lock != NULL);
  GL_INIT_LOCK(cow->lock);
#else
  cow->lock = ssalloc_aligned(CACHE_LINE_SIZE, cow->num_buckets * sizeof(ptlock_t));
  assert(cow->lock != NULL);
#endif

  cow->array = ssalloc_aligned(CACHE_LINE_SIZE, cow->num_buckets * sizeof(array_ll_t*));
  assert(cow->array != NULL);

  int i;
  for (i = 0; i < cow->num_buckets; i++)
    {
      INIT_LOCK(cow->lock + i);
      cow->array[i] = array_ll_new_init(0);
    }

  return cow;
}
Exemplo n.º 4
0
cmd_queue::cmd_queue(void)
{
	
	if (INIT_LOCK(self.q_lock)) {
        return;
    }
}
Exemplo n.º 5
0
int remove_indicationObject (void *obj, CMPIUint32 ctx_id)
{
    ind_object **tmp;
    indication_objects *curr;
    CMPIUint64 id = ( (ind_object*)obj)->id;

    TRACE_NORMAL(("Deleting Indication Object."));

    INIT_LOCK(_indication_objects_lock);
    CMPI_BrokerExt_Ftab->lockMutex(_indication_objects_lock);
    curr = __indication_objects;
    while (curr)
    {
        if (curr->ctx_id == ctx_id)
        {
            break;
        }
        curr = curr->next;
    }
    for (tmp = &curr->objects; *tmp != NULL; *tmp = (*tmp)->next)
    {
        if ((*tmp)->id == id)
        {
            ind_object *r = (*tmp);
            (*tmp) = r->next;
            __free_ind_object (r);
            TRACE_INFO(("Deleted Indication Object with ID: %llu", id));
            CMPI_BrokerExt_Ftab->unlockMutex(_indication_objects_lock);
            return 0;
        }
    }
    CMPI_BrokerExt_Ftab->unlockMutex(_indication_objects_lock);
    return -1;
}
Exemplo n.º 6
0
/*!
  The function maintains a list of previously loaded comm-layers locally.
  A mutex is used to ensure proper access to this list. If a comm-layer
  is found within the list, it is being unloaded.

  \param comm_id the name of the communication layer to be looked up.
  \param broker broker handle as passed to the init function.
  \param ctx context as passed to the cleanup function.

 */
void unload_provider_comms ( void )
{
	provider_comm * tmp;
	provider_comm * next;
	TRACE_VERBOSE(("entered function."));
	TRACE_NORMAL(("unloading remote communication layers"));

        INIT_LOCK(__mutex);
        CMPI_BrokerExt_Ftab->lockMutex(__mutex);

	for ( tmp = __comm_layers; tmp != NULL; tmp = next ) {
		TRACE_INFO(("unloading comm-layer: %s.", tmp->id));
		next = tmp->next;
	    	// IBMKR: Call the cleanup function of comm library.
	    	tmp->terminate();
		// IBMKR: free the library name.
		free (tmp->id); tmp->id = 0;
		unload_comm_library(tmp);
	}

	__comm_layers = NULL;
        CMPI_BrokerExt_Ftab->unlockMutex(__mutex);

	TRACE_VERBOSE(("leaving function."));
}
/**************************************************************************
 * public functions
 **************************************************************************/
int
initLazyUpload (lazyUploadConfig_t *lazyUploadConfig, rodsEnv *myLazyUploadRodsEnv, rodsArguments_t *myLazyUploadRodsArgs) {
    rodsLog (LOG_DEBUG, "initLazyUpload: MyLazyUploadConfig.lazyUpload = %d", lazyUploadConfig->lazyUpload);
    rodsLog (LOG_DEBUG, "initLazyUpload: MyLazyUploadConfig.bufferPath = %s", lazyUploadConfig->bufferPath);
    rodsLog (LOG_DEBUG, "initLazyUpload: empty space = %lld", getEmptySpace(lazyUploadConfig->bufferPath));

    // copy given configuration
    memcpy(&LazyUploadConfig, lazyUploadConfig, sizeof(lazyUploadConfig_t));
    LazyUploadRodsEnv = myLazyUploadRodsEnv;
    LazyUploadRodsArgs = myLazyUploadRodsArgs;

    // init hashtables
    LazyUploadBufferedFileTable_Created = newHashTable(NUM_LAZYUPLOAD_FILE_HASH_SLOT);
    LazyUploadBufferedFileTable_Opened = newHashTable(NUM_LAZYUPLOAD_FILE_HASH_SLOT);

    // init lock
    INIT_LOCK(LazyUploadLock);

    _prepareBufferDir(lazyUploadConfig->bufferPath);

    // remove lazy-upload Buffered files
    _removeAllBufferedFiles();

    return (0);
}
Exemplo n.º 8
0
/**************************************************************************
 * public functions
 **************************************************************************/
int
initPreload (preloadConfig_t *preloadConfig, rodsEnv *myPreloadRodsEnv, rodsArguments_t *myPreloadRodsArgs) {
    rodsLog (LOG_DEBUG, "initPreload: MyPreloadConfig.preload = %d", preloadConfig->preload);
    rodsLog (LOG_DEBUG, "initPreload: MyPreloadConfig.clearCache = %d", preloadConfig->clearCache);
    rodsLog (LOG_DEBUG, "initPreload: MyPreloadConfig.cachePath = %s", preloadConfig->cachePath);
    rodsLog (LOG_DEBUG, "initPreload: MyPreloadConfig.cacheMaxSize = %lld", preloadConfig->cacheMaxSize);
    rodsLog (LOG_DEBUG, "initPreload: MyPreloadConfig.preloadMinSize = %lld", preloadConfig->preloadMinSize);

    // copy given configuration
    memcpy(&PreloadConfig, preloadConfig, sizeof(preloadConfig_t));
    PreloadRodsEnv = myPreloadRodsEnv;
    PreloadRodsArgs = myPreloadRodsArgs;

    // init hashtables
    PreloadThreadTable = newHashTable(NUM_PRELOAD_THREAD_HASH_SLOT);
    PreloadFileHandleTable = newHashTable(NUM_PRELOAD_FILEHANDLE_HASH_SLOT);

    // init lists
    PreloadThreadList = newConcurrentList();

    // init lock
    INIT_LOCK(PreloadLock);

    _preparePreloadCacheDir(preloadConfig->cachePath);

    if(preloadConfig->clearCache) {
        // clear all cache
        _removeAllCaches();
    } else {
        // remove incomplete preload caches
        _removeAllIncompleteCaches(preloadConfig->cachePath);
    }

    return (0);
}
Exemplo n.º 9
0
void mr_init_global(uint8_t nthreads) {
    int i;
    
    nthreads_ = nthreads;
    qg = (struct qsbr_globals *) malloc(sizeof(struct qsbr_globals));
    qg->global_epoch = 1;
    INIT_LOCK(&(qg->update_lock));

    shtd = (shared_thread_data_t *) malloc(nthreads * sizeof(shared_thread_data_t));

    for (i = 0; i < nthreads; i++) {
        shtd[i].epoch = 0;
        shtd[i].in_critical = 1;
        shtd[i].process_callbacks_count = 0;
        shtd[i].scan_count = 0;

    }

    HP = (hazard_pointer_t *)malloc(sizeof(hazard_pointer_t) * K*nthreads);

    for (i = 0; i < K*(nthreads); i++) {
        HP[i].p = NULL;
    }

    is_present_vect = (uint8_t*) malloc(sizeof(uint8_t) * nthreads);
    for (i = 0; i < nthreads; i++) {
        is_present_vect[i] = 1;
    }

    fallback.flag = 0;

    //create sleeper threads
    init_sleeper_threads(nthreads, reset_presence);
    
}
Exemplo n.º 10
0
void make_root_frames(void) {
#ifdef YAPOR
    /* root or frame */
    or_fr_ptr or_fr;

    ALLOC_OR_FRAME(or_fr);
    INIT_LOCK(OrFr_lock(or_fr));
    OrFr_alternative(or_fr) = NULL;
    BITMAP_copy(OrFr_members(or_fr), GLOBAL_bm_present_workers);
    SetOrFr_node(or_fr, (choiceptr) Yap_LocalBase);
    OrFr_nearest_livenode(or_fr) = NULL;
    OrFr_depth(or_fr) = 0;
    Set_OrFr_pend_prune_cp(or_fr, NULL);
    OrFr_nearest_leftnode(or_fr) = or_fr;
    OrFr_qg_solutions(or_fr) = NULL;
#ifdef TABLING_INNER_CUTS
    OrFr_tg_solutions(or_fr) = NULL;
#endif /* TABLING_INNER_CUTS */
#ifdef TABLING
    OrFr_owners(or_fr) = number_workers;
    OrFr_next_on_stack(or_fr) = NULL;
    OrFr_suspensions(or_fr) = NULL;
    OrFr_nearest_suspnode(or_fr) = or_fr;
#endif /* TABLING */
    OrFr_next(or_fr) = NULL;
    GLOBAL_root_or_fr = or_fr;
#endif /* YAPOR */

#ifdef TABLING
    /* root dependency frame */
    if (!GLOBAL_root_dep_fr) {
        new_dependency_frame(GLOBAL_root_dep_fr, FALSE, NULL, NULL, NULL, NULL, NULL);
    }
#endif /* TABLING */
}
Exemplo n.º 11
0
/*!
  The function maintains a list of previously loaded comm-layers locally.
  A mutex is used to ensure proper access to this list. If a comm-layer
  cannot be found within the list, it is being loaded and inserted at
  the begininng.

  \param comm_id the name of the communication layer to be looked up.
  \param broker broker handle as passed to the init function.
  \param ctx context as passed to the init function.

  \return the comm-layer matching the id or NULL if it cannot be loaded.
 */
provider_comm * load_provider_comm ( const char * comm_id,
				     CONST CMPIBroker * broker,
				     CONST CMPIContext * ctx )
{
	provider_comm * tmp;

	TRACE_VERBOSE(("entered function."));
	TRACE_NORMAL(("loading remote communication layer: %s", comm_id ));

        INIT_LOCK(__mutex);
        CMPI_BrokerExt_Ftab->lockMutex(__mutex);

	for ( tmp = __comm_layers; tmp != NULL; tmp = tmp->next ) {

		if ( strcmp ( tmp->id, comm_id ) == 0 ) {
                        CMPI_BrokerExt_Ftab->unlockMutex(__mutex);

			TRACE_INFO(("found previously loaded comm-layer."));
			TRACE_VERBOSE(("leaving function."));
			return tmp;
		}
	}

	tmp = load_comm_library ( comm_id, broker, ctx );

	if ( tmp != NULL ) {
		tmp->next     = __comm_layers;
		__comm_layers = tmp;
	}

        CMPI_BrokerExt_Ftab->unlockMutex(__mutex);

	TRACE_VERBOSE(("leaving function."));
  	return tmp;
}
Exemplo n.º 12
0
static struct writer_context_s *
create_writer (HANDLE fd)
{
    struct writer_context_s *c;
    SECURITY_ATTRIBUTES sec_attr;
    DWORD tid;

    DEBUG1 ("creating new write thread for file handle %p", fd );
    memset (&sec_attr, 0, sizeof sec_attr );
    sec_attr.nLength = sizeof sec_attr;
    sec_attr.bInheritHandle = FALSE;

    c = calloc (1, sizeof *c );
    if (!c)
        return NULL;

    c->file_hd = fd;
    c->have_data = CreateEvent (&sec_attr, TRUE, FALSE, NULL);
    c->is_empty  = CreateEvent (&sec_attr, TRUE, TRUE, NULL);
    c->stopped = CreateEvent (&sec_attr, TRUE, FALSE, NULL);
    if (!c->have_data || !c->is_empty || !c->stopped ) {
        DEBUG1 ("** CreateEvent failed: ec=%d\n", (int)GetLastError ());
        if (c->have_data)
            CloseHandle (c->have_data);
        if (c->is_empty)
            CloseHandle (c->is_empty);
        if (c->stopped)
            CloseHandle (c->stopped);
        free (c);
        return NULL;
    }

    c->is_empty = set_synchronize (c->is_empty);
    INIT_LOCK (c->mutex);

    c->thread_hd = CreateThread (&sec_attr, 0, writer, c, 0, &tid );
    if (!c->thread_hd) {
        DEBUG1 ("** failed to create writer thread: ec=%d\n",
                 (int)GetLastError ());
        DESTROY_LOCK (c->mutex);
        if (c->have_data)
            CloseHandle (c->have_data);
        if (c->is_empty)
            CloseHandle (c->is_empty);
        if (c->stopped)
            CloseHandle (c->stopped);
        free (c);
        return NULL;
    }    
    else {
      /* We set the priority of the thread higher because we know that
         it only runs for a short time.  This greatly helps to increase
         the performance of the I/O. */
      SetThreadPriority (c->thread_hd, get_desired_thread_priority ());
    }

    return c;
}
Exemplo n.º 13
0
PRIVATE void init_trampolines(void)
{
	INIT_LOCK(trampoline_lock);
	char *tmp = getenv("TMPDIR");
	if (NULL == tmp)
	{
		tmp = "/tmp/";
	}
	if (0 > asprintf(&tmpPattern, "%s/objc_trampolinesXXXXXXXXXXX", tmp))
	{
		abort();
	}
}
Exemplo n.º 14
0
node_t *new_node(val_t val, node_t *next)
{
    /* allocate node */
    node_t *node = malloc(sizeof(node_t));
    /* allocate lock */
    node->lock = malloc(sizeof(ptlock_t));
    /* let's initialize the lock */
    INIT_LOCK(node->lock);

    node->data = val;
    node->next = next;
    return node;
}
Exemplo n.º 15
0
iFuseConn_t *newIFuseConn(int *status) {
    iFuseConn_t *tmpIFuseConn = (iFuseConn_t *) malloc (sizeof (iFuseConn_t));
    if (tmpIFuseConn == NULL) {
        *status = SYS_MALLOC_ERR;
        return NULL;
    }
    bzero (tmpIFuseConn, sizeof (iFuseConn_t));

    INIT_STRUCT_LOCK(*tmpIFuseConn);
    INIT_LOCK(tmpIFuseConn->inuseLock);

    *status = ifuseConnect (tmpIFuseConn, &MyRodsEnv);
	/*rodsLog(LOG_ERROR, "[ NEW IFUSE CONN] %s:%d %p", __FILE__, __LINE__, tmpIFuseConn);*/
    return tmpIFuseConn;

}
Exemplo n.º 16
0
int pcan_fifo_init(register FIFO_MANAGER *anchor, void *bufferBegin, void *bufferEnd, int nCount, u16 wCopySize)
{
  anchor->wCopySize   = wCopySize;
  anchor->wStepSize   = (bufferBegin == bufferEnd) ? 0 : ((bufferEnd - bufferBegin) / (nCount - 1));
  anchor->nCount      = nCount;
  anchor->bufferBegin = bufferBegin;
  anchor->bufferEnd   = bufferEnd;

  // check for fatal program errors
  if ((anchor->wStepSize < anchor->wCopySize) || (anchor->bufferBegin > anchor->bufferEnd) || (nCount <= 1))
    return -EINVAL;

  INIT_LOCK(&anchor->lock);

  return pcan_fifo_reset(anchor);
}
Exemplo n.º 17
0
void* get_indicationObject (CMPIUint64 id, CMPIUint32 ctx_id)
{
    indication_objects *curr;
    ind_object *tmp;
    int global_context = 0;

    TRACE_NORMAL(("Getting the  Indication Object."));

    INIT_LOCK(_indication_objects_lock);
    CMPI_BrokerExt_Ftab->lockMutex(_indication_objects_lock);

    do
    {
        curr = __indication_objects;
        while (curr)
        {
            if (curr->ctx_id == ctx_id)
            {
                break;
            }
            curr = curr->next;
        }
        if (!curr && !global_context)
        {
            global_context = 1;
            ctx_id = PEGASUS_INDICATION_GLOBAL_CONTEXT;
        }
        else
        {
            break;
        }
    }while (global_context);

    for (tmp = curr ? curr->objects : NULL; tmp != NULL; tmp = tmp->next)
    {
        if (tmp->id == id)
        {
            TRACE_INFO(("Got the Indication Object with ID: %llu", id));
            CMPI_BrokerExt_Ftab->unlockMutex(_indication_objects_lock);
            return tmp->ptr;
        }
    }
    CMPI_BrokerExt_Ftab->unlockMutex(_indication_objects_lock);

    return NULL;

}
Exemplo n.º 18
0
/*
    This function creates reference to the Object created in MB.
    This reference is passed to Remote Daemon, any changes or any
    calls made on this object on daemon side, will make UP calls
    to MB and uses this object.
*/
CMPIUint64 create_indicationObject (
    void *obj,
    CMPIUint32 ctx_id,
    CMPIUint8 type)
{
    indication_objects *tmp;
    ind_object *ind_obj;

    TRACE_NORMAL(("Creating Indication Object."));

    INIT_LOCK(_indication_objects_lock);
    CMPI_BrokerExt_Ftab->lockMutex(_indication_objects_lock);

    tmp = __indication_objects;
    while (tmp)
    {
        if (tmp->ctx_id == ctx_id)
        {
            break;
        }
        tmp = tmp->next;
    }
    if (!tmp)
    {
        tmp = (indication_objects *)
        malloc ( sizeof ( indication_objects ) );
        tmp->ctx_id = ctx_id;
        tmp->next = __indication_objects;
        __indication_objects = tmp;
        tmp->objects = NULL;
    }
    ind_obj = (ind_object*) malloc ( sizeof ( ind_object ) );
    ind_obj->id = (ssize_t) obj;
    ind_obj->ptr = obj;
    ind_obj->type = type;
    ind_obj->next = tmp->objects;
    tmp->objects = ind_obj;

    CMPI_BrokerExt_Ftab->unlockMutex(_indication_objects_lock);

    TRACE_INFO(("Created object with id: %llu", ind_obj->id ));

    return ind_obj->id;
}
Exemplo n.º 19
0
void cleanup_indicationObjects (CMPIUint32 ctx_id)
{
    indication_objects *tmp, *prev;
    ind_object *obj;

    TRACE_NORMAL(("Cleaning all Indication Objects."));

    INIT_LOCK(_indication_objects_lock);
    CMPI_BrokerExt_Ftab->lockMutex(_indication_objects_lock);
    tmp = __indication_objects;
    while (tmp)
    {
        if (tmp->ctx_id == ctx_id)
        {
            break;
        }
        prev = tmp;
        tmp = tmp->next;
    }
    if (!tmp)
    {
        TRACE_CRITICAL(("Indication context id (%u) not found.", ctx_id));
        return;
    }
    while (tmp->objects)
    {
        obj = tmp->objects;
        tmp->objects = tmp->objects->next;
        __free_ind_object (obj);
    }
    if (tmp == __indication_objects)
    {
        __indication_objects = __indication_objects->next;
    }
    else
    {
        prev->next = tmp->next;
    }
    free (tmp);
    CMPI_BrokerExt_Ftab->unlockMutex(_indication_objects_lock);
}
Exemplo n.º 20
0
void Yap_init_root_frames(void) {
  CACHE_REGS

#ifdef YAPOR
  /* root or frame */
  or_fr_ptr or_fr = GLOBAL_root_or_fr;
  INIT_LOCK(OrFr_lock(or_fr));
  OrFr_alternative(or_fr) = NULL;
  BITMAP_copy(OrFr_members(or_fr), GLOBAL_bm_present_workers);
  SetOrFr_node(or_fr, (choiceptr)LOCAL_LocalBase);
  OrFr_nearest_livenode(or_fr) = NULL;
  OrFr_depth(or_fr) = 0;
  Set_OrFr_pend_prune_cp(or_fr, NULL);
  OrFr_nearest_leftnode(or_fr) = or_fr;
  OrFr_qg_solutions(or_fr) = NULL;
#ifdef TABLING_INNER_CUTS
  OrFr_tg_solutions(or_fr) = NULL;
#endif /* TABLING_INNER_CUTS */
#ifdef TABLING
  OrFr_owners(or_fr) = GLOBAL_number_workers;
  OrFr_next_on_stack(or_fr) = NULL;
  OrFr_suspensions(or_fr) = NULL;
  OrFr_nearest_suspnode(or_fr) = or_fr;
#endif /* TABLING */
  OrFr_next(or_fr) = NULL;
#endif /* YAPOR */

#ifdef TABLING
  /* root global trie node */
  new_global_trie_node(GLOBAL_root_gt, 0, NULL, NULL, NULL);
/* root dependency frame */
#ifdef YAPOR
  DepFr_cons_cp(GLOBAL_root_dep_fr) = B; /* with YAPOR, at that point,
                                            LOCAL_top_dep_fr shouldn't be the
                                            same as GLOBAL_root_dep_fr ? */
#else
  new_dependency_frame(LOCAL_top_dep_fr, FALSE, NULL, NULL, B, NULL, FALSE,
                       NULL);
#endif /* YAPOR */
#endif /* TABLING */
}
Exemplo n.º 21
0
node_l_t*
new_node_l(skey_t key, sval_t val, node_l_t* next, int initializing)
{
  volatile node_l_t *node;
#if GC == 1
  if (initializing)		/* for initialization AND the coupling algorithm */
    {
      node = (volatile node_l_t *) ssalloc(sizeof(node_l_t));
    }
  else
    {
      node = (volatile node_l_t *) ssmem_alloc(alloc, sizeof(node_l_t));
    }
#else
  node = (volatile node_l_t *) ssalloc(sizeof(node_l_t));
#endif
  
  if (node == NULL) 
    {
      perror("malloc @ new_node");
      exit(1);
    }

  node->key = key;
  node->val = val;
  node->next = next;
  node->marked = 0;

  INIT_LOCK(ND_GET_LOCK(node));

#if defined(__tile__)
  /* on tilera you may have store reordering causing the pointer to a new node
     to become visible, before the contents of the node are visible */
  MEM_BARRIER;
#endif	/* __tile__ */

  return (node_l_t*) node;
}
Exemplo n.º 22
0
void Yap_init_global_optyap_data(int max_table_size, int n_workers,
                                 int sch_loop, int delay_load) {
  int i;

/* global data related to memory management */
#ifdef USE_PAGES_MALLOC
  INIT_GLOBAL_PAGE_ENTRY(GLOBAL_pages_alloc, void *);
  INIT_GLOBAL_PAGE_ENTRY(GLOBAL_pages_void, void *);
#endif /* USE_PAGES_MALLOC */
#ifdef TABLING
  INIT_GLOBAL_PAGE_ENTRY(GLOBAL_pages_tab_ent, struct table_entry);
#if defined(THREADS_FULL_SHARING) || defined(THREADS_CONSUMER_SHARING)
  INIT_GLOBAL_PAGE_ENTRY(GLOBAL_pages_sg_ent, struct subgoal_entry);
#endif
  INIT_GLOBAL_PAGE_ENTRY(GLOBAL_pages_sg_fr, struct subgoal_frame);
  INIT_GLOBAL_PAGE_ENTRY(GLOBAL_pages_dep_fr, struct dependency_frame);
  INIT_GLOBAL_PAGE_ENTRY(GLOBAL_pages_sg_node, struct subgoal_trie_node);
  INIT_GLOBAL_PAGE_ENTRY(GLOBAL_pages_sg_hash, struct subgoal_trie_hash);
  INIT_GLOBAL_PAGE_ENTRY(GLOBAL_pages_ans_node, struct answer_trie_node);
  INIT_GLOBAL_PAGE_ENTRY(GLOBAL_pages_ans_hash, struct answer_trie_hash);
#if defined(THREADS_FULL_SHARING)
  INIT_GLOBAL_PAGE_ENTRY(GLOBAL_pages_ans_ref_node, struct answer_ref_node);
#endif
  INIT_GLOBAL_PAGE_ENTRY(GLOBAL_pages_gt_node, struct global_trie_node);
  INIT_GLOBAL_PAGE_ENTRY(GLOBAL_pages_gt_hash, struct global_trie_hash);
#endif /* TABLING */
#ifdef YAPOR
  INIT_GLOBAL_PAGE_ENTRY(GLOBAL_pages_or_fr, struct or_frame);
  INIT_GLOBAL_PAGE_ENTRY(GLOBAL_pages_qg_sol_fr,
                         struct query_goal_solution_frame);
  INIT_GLOBAL_PAGE_ENTRY(GLOBAL_pages_qg_ans_fr,
                         struct query_goal_answer_frame);
#ifdef TABLING
  INIT_GLOBAL_PAGE_ENTRY(GLOBAL_pages_susp_fr, struct suspension_frame);
#endif
#ifdef TABLING_INNER_CUTS
  INIT_GLOBAL_PAGE_ENTRY(GLOBAL_pages_tg_sol_fr,
                         struct table_subgoal_solution_frame);
  INIT_GLOBAL_PAGE_ENTRY(GLOBAL_pages_tg_ans_fr,
                         struct table_subgoal_answer_frame);
#endif
#endif /* YAPOR */

#ifdef YAPOR
  /* global static data */
  GLOBAL_number_workers = n_workers;
  GLOBAL_worker_pid(0) = getpid();
  for (i = 1; i < GLOBAL_number_workers; i++)
    GLOBAL_worker_pid(i) = 0;
  GLOBAL_scheduler_loop = sch_loop;
  GLOBAL_delayed_release_load = delay_load;

  /* global data related to or-parallelism */
  ALLOC_OR_FRAME(GLOBAL_root_or_fr);
  BITMAP_clear(GLOBAL_bm_present_workers);
  for (i = 0; i < GLOBAL_number_workers; i++)
    BITMAP_insert(GLOBAL_bm_present_workers, i);
  BITMAP_copy(GLOBAL_bm_idle_workers, GLOBAL_bm_present_workers);
  BITMAP_clear(GLOBAL_bm_root_cp_workers);
  BITMAP_clear(GLOBAL_bm_invisible_workers);
  BITMAP_clear(GLOBAL_bm_requestable_workers);
  BITMAP_copy(GLOBAL_bm_finished_workers, GLOBAL_bm_present_workers);
  INIT_LOCK(GLOBAL_locks_bm_idle_workers);
  INIT_LOCK(GLOBAL_locks_bm_root_cp_workers);
  INIT_LOCK(GLOBAL_locks_bm_invisible_workers);
  INIT_LOCK(GLOBAL_locks_bm_requestable_workers);
  INIT_LOCK(GLOBAL_locks_bm_finished_workers);
#ifdef TABLING_INNER_CUTS
  INIT_LOCK(GLOBAL_locks_bm_pruning_workers);
#endif /* TABLING_INNER_CUTS */
  GLOBAL_locks_who_locked_heap = MAX_WORKERS;
  INIT_LOCK(GLOBAL_locks_heap_access);
  INIT_LOCK(GLOBAL_locks_alloc_block);
  if (GLOBAL_number_workers == 1)
    GLOBAL_parallel_mode = PARALLEL_MODE_OFF;
  else
    GLOBAL_parallel_mode = PARALLEL_MODE_ON;
#endif /* YAPOR */

#ifdef TABLING
  /* global data related to tabling */
  GLOBAL_root_gt = NULL;
  GLOBAL_root_tab_ent = NULL;
#ifdef LIMIT_TABLING
  if (max_table_size)
    GLOBAL_max_pages = ((max_table_size - 1) * 1024 * 1024 / SHMMAX + 1) *
                       SHMMAX / Yap_page_size;
  else
    GLOBAL_max_pages = -1;
  GLOBAL_first_sg_fr = NULL;
  GLOBAL_last_sg_fr = NULL;
  GLOBAL_check_sg_fr = NULL;
#endif /* LIMIT_TABLING */
#ifdef YAPOR
  new_dependency_frame(GLOBAL_root_dep_fr, FALSE, NULL, NULL, NULL, NULL, FALSE,
                       NULL);
#endif /* YAPOR */
  for (i = 0; i < MAX_TABLE_VARS; i++) {
    CELL *pt = GLOBAL_table_var_enumerator_addr(i);
    RESET_VARIABLE(pt);
  }
#ifdef TRIE_LOCK_USING_GLOBAL_ARRAY
  for (i = 0; i < TRIE_LOCK_BUCKETS; i++)
    INIT_LOCK(GLOBAL_trie_locks(i));
#endif /* TRIE_LOCK_USING_GLOBAL_ARRAY */
#endif /* TABLING */

  return;
}
Exemplo n.º 23
0
/* Execute LINE as a shell command, returning its status.  */
static int
do_system (const char *line)
{
  int status, save;
  pid_t pid;
  struct sigaction sa;
#ifndef _LIBC_REENTRANT
  struct sigaction intr, quit;
#endif
  sigset_t omask;

  sa.sa_handler = SIG_IGN;
  sa.sa_flags = 0;
  __sigemptyset (&sa.sa_mask);

  DO_LOCK ();
  if (ADD_REF () == 0)
    {
      if (__sigaction (SIGINT, &sa, &intr) < 0)
	{
	  (void) SUB_REF ();
	  goto out;
	}
      if (__sigaction (SIGQUIT, &sa, &quit) < 0)
	{
	  save = errno;
	  (void) SUB_REF ();
	  goto out_restore_sigint;
	}
    }
  DO_UNLOCK ();

  /* We reuse the bitmap in the 'sa' structure.  */
  __sigaddset (&sa.sa_mask, SIGCHLD);
  save = errno;
  if (__sigprocmask (SIG_BLOCK, &sa.sa_mask, &omask) < 0)
    {
#ifndef _LIBC
      if (errno == ENOSYS)
	__set_errno (save);
      else
#endif
	{
	  DO_LOCK ();
	  if (SUB_REF () == 0)
	    {
	      save = errno;
	      (void) __sigaction (SIGQUIT, &quit, (struct sigaction *) NULL);
	    out_restore_sigint:
	      (void) __sigaction (SIGINT, &intr, (struct sigaction *) NULL);
	      __set_errno (save);
	    }
	out:
	  DO_UNLOCK ();
	  return -1;
	}
    }

#ifdef CLEANUP_HANDLER
  CLEANUP_HANDLER;
#endif

#ifdef FORK
  pid = FORK ();
#else
  pid = __fork ();
#endif
  if (pid == (pid_t) 0)
    {
      /* Child side.  */
      const char *new_argv[4];
      new_argv[0] = SHELL_NAME;
      new_argv[1] = "-c";
      new_argv[2] = line;
      new_argv[3] = NULL;

      /* Restore the signals.  */
      (void) __sigaction (SIGINT, &intr, (struct sigaction *) NULL);
      (void) __sigaction (SIGQUIT, &quit, (struct sigaction *) NULL);
      (void) __sigprocmask (SIG_SETMASK, &omask, (sigset_t *) NULL);
      INIT_LOCK ();

      /* Exec the shell.  */
      (void) __execve (SHELL_PATH, (char *const *) new_argv, __environ);
      _exit (127);
    }
  else if (pid < (pid_t) 0)
    /* The fork failed.  */
    status = -1;
  else
    /* Parent side.  */
    {
      /* Note the system() is a cancellation point.  But since we call
	 waitpid() which itself is a cancellation point we do not
	 have to do anything here.  */
      if (TEMP_FAILURE_RETRY (__waitpid (pid, &status, 0)) != pid)
	status = -1;
    }

#ifdef CLEANUP_HANDLER
  CLEANUP_RESET;
#endif

  save = errno;
  DO_LOCK ();
  if ((SUB_REF () == 0
       && (__sigaction (SIGINT, &intr, (struct sigaction *) NULL)
	   | __sigaction (SIGQUIT, &quit, (struct sigaction *) NULL)) != 0)
      || __sigprocmask (SIG_SETMASK, &omask, (sigset_t *) NULL) != 0)
    {
#ifndef _LIBC
      /* glibc cannot be used on systems without waitpid.  */
      if (errno == ENOSYS)
	__set_errno (save);
      else
#endif
	status = -1;
    }
  DO_UNLOCK ();

  return status;
}
Exemplo n.º 24
0
static
void share_private_nodes(int worker_q) {
  choiceptr sharing_node = B;

#ifdef DEBUG_OPTYAP
  OPTYAP_ERROR_CHECKING(share_private_nodes, YOUNGER_CP(LOCAL_top_cp, LOCAL_top_cp_on_stack));
  { choiceptr aux_cp = B;
    while (aux_cp != LOCAL_top_cp) {
      OPTYAP_ERROR_CHECKING(share_private_nodes, YOUNGER_CP(LOCAL_top_cp, aux_cp));
      OPTYAP_ERROR_CHECKING(share_private_nodes, EQUAL_OR_YOUNGER_CP(LOCAL_top_cp_on_stack, aux_cp));
      aux_cp = aux_cp->cp_b;
    }
  }
#endif /* DEBUG_OPTYAP */

#ifdef TABLING
  /* check if the branch is already shared */
  if (EQUAL_OR_YOUNGER_CP(LOCAL_top_cp_on_stack, sharing_node)) {
    or_fr_ptr or_frame;
    sg_fr_ptr sg_frame;
    dep_fr_ptr dep_frame;

#ifdef DEBUG_OPTYAP
    { or_fr_ptr aux_or_fr;
      aux_or_fr = LOCAL_top_or_fr;
      while (aux_or_fr != REMOTE_top_or_fr(worker_q)) {
	OPTYAP_ERROR_CHECKING(share_private_nodes, YOUNGER_CP(OrFr_node(REMOTE_top_or_fr(worker_q)), OrFr_node(aux_or_fr)));
        aux_or_fr = OrFr_next_on_stack(aux_or_fr);
      }
    }
#endif /* DEBUG_OPTYAP */

    /* update old shared nodes */
    or_frame = LOCAL_top_or_fr;
    while (or_frame != REMOTE_top_or_fr(worker_q)) {
      LOCK_OR_FRAME(or_frame);
      BRANCH(worker_q, OrFr_depth(or_frame)) = BRANCH(worker_id, OrFr_depth(or_frame));
      OrFr_owners(or_frame)++;
      if (BITMAP_member(OrFr_members(or_frame), worker_id))
        BITMAP_insert(OrFr_members(or_frame), worker_q);
      UNLOCK_OR_FRAME(or_frame);
      or_frame = OrFr_next_on_stack(or_frame);
    }

    /* update worker Q top subgoal frame */
    sg_frame = LOCAL_top_sg_fr;
    while (sg_frame && YOUNGER_CP(SgFr_gen_cp(sg_frame), sharing_node)) {
      sg_frame = SgFr_next(sg_frame);
    }
    REMOTE_top_sg_fr(worker_q) = sg_frame;

    /* update worker Q top dependency frame */
    dep_frame = LOCAL_top_dep_fr;
    while (YOUNGER_CP(DepFr_cons_cp(dep_frame), sharing_node)) {
      dep_frame = DepFr_next(dep_frame);
    }
    REMOTE_top_dep_fr(worker_q) = dep_frame;

    /* update worker Q top shared nodes */
    REMOTE_top_cp_on_stack(worker_q) = REMOTE_top_cp(worker_q) = LOCAL_top_cp;
    REMOTE_top_or_fr(worker_q) = LOCAL_top_or_fr;
  } else
#endif /* TABLING */
  {
    int depth;
    bitmap bm_workers;
    or_fr_ptr or_frame, previous_or_frame;
#ifdef TABLING
    choiceptr consumer_cp, next_node_on_branch;
    dep_fr_ptr dep_frame;
    sg_fr_ptr sg_frame;
    CELL *stack, *stack_limit;

    /* find top dependency frame above current choice point */
    dep_frame = LOCAL_top_dep_fr;
    while (EQUAL_OR_YOUNGER_CP(DepFr_cons_cp(dep_frame), sharing_node)) {
      dep_frame = DepFr_next(dep_frame);
    }
    /* initialize tabling auxiliary variables */ 
    consumer_cp = DepFr_cons_cp(dep_frame);
    next_node_on_branch = NULL;
    stack_limit = (CELL *)TR;
    stack = (CELL *)LOCAL_TrailTop;
#endif /* TABLING */

    /* initialize auxiliary variables */
    BITMAP_clear(bm_workers);
    BITMAP_insert(bm_workers, worker_id);
    BITMAP_insert(bm_workers, worker_q);
    previous_or_frame = NULL;
    depth = OrFr_depth(LOCAL_top_or_fr);

    /* sharing loop */
#ifdef TABLING
    while (YOUNGER_CP(sharing_node, LOCAL_top_cp_on_stack)) {
#else
    while (sharing_node != LOCAL_top_cp) {
#endif /* TABLING */

#ifdef DEBUG_OPTYAP
      if (next_node_on_branch) {
        choiceptr aux_cp = B;
        while (aux_cp != next_node_on_branch) {
	  OPTYAP_ERROR_CHECKING(share_private_nodes, sharing_node == aux_cp);
	  OPTYAP_ERROR_CHECKING(share_private_nodes, YOUNGER_CP(next_node_on_branch, aux_cp));
          aux_cp = aux_cp->cp_b;
        }
      } else {
        choiceptr aux_cp = B;
        while (aux_cp != sharing_node) {
	  OPTYAP_ERROR_CHECKING(share_private_nodes, YOUNGER_CP(sharing_node, aux_cp));
          aux_cp = aux_cp->cp_b;
        }
      }
#endif /* DEBUG_OPTYAP */

      ALLOC_OR_FRAME(or_frame);
      if (previous_or_frame) {
#ifdef TABLING
        OrFr_next_on_stack(previous_or_frame) =
#endif /* TABLING */
        OrFr_nearest_livenode(previous_or_frame) = OrFr_next(previous_or_frame) = or_frame;
      }
      previous_or_frame = or_frame;
      depth++;
      INIT_LOCK(OrFr_lock(or_frame));
      OrFr_node(or_frame) = sharing_node;
      OrFr_alternative(or_frame) = sharing_node->cp_ap;
      OrFr_pend_prune_cp(or_frame) = NULL;
      OrFr_nearest_leftnode(or_frame) = LOCAL_top_or_fr;
      OrFr_qg_solutions(or_frame) = NULL;
#ifdef TABLING_INNER_CUTS
      OrFr_tg_solutions(or_frame) = NULL;
#endif /* TABLING_INNER_CUTS */
#ifdef TABLING
      OrFr_suspensions(or_frame) = NULL;
      OrFr_nearest_suspnode(or_frame) = or_frame;
      OrFr_owners(or_frame) = 2;
      if (next_node_on_branch)
        BITMAP_clear(OrFr_members(or_frame));
      else
#endif /* TABLING */
        OrFr_members(or_frame) = bm_workers;

      YAPOR_ERROR_CHECKING(share_private_nodes, sharing_node->cp_ap == GETWORK || sharing_node->cp_ap == GETWORK_SEQ);
      if (sharing_node->cp_ap && YAMOP_SEQ(sharing_node->cp_ap)) {
        sharing_node->cp_ap = GETWORK_SEQ;
      } else {
        sharing_node->cp_ap = GETWORK;
      }
      sharing_node->cp_or_fr = or_frame;
      sharing_node = sharing_node->cp_b;

#ifdef TABLING
      /* when next_node_on_branch is not NULL the **
      ** sharing_node belongs to a frozen branch. */   
      if (YOUNGER_CP(consumer_cp, sharing_node)) {
        /* frozen stack segment */
        if (! next_node_on_branch)
          next_node_on_branch = sharing_node;
        STACK_PUSH_UP(or_frame, stack);
        STACK_CHECK_EXPAND(stack, stack_limit);
        STACK_PUSH_UP(sharing_node, stack);
        STACK_CHECK_EXPAND(stack, stack_limit);
        sharing_node = consumer_cp;
        dep_frame = DepFr_next(dep_frame);
        consumer_cp = DepFr_cons_cp(dep_frame);
      } else if (consumer_cp == sharing_node) {
        dep_frame = DepFr_next(dep_frame);
        consumer_cp = DepFr_cons_cp(dep_frame);
      }
      if (next_node_on_branch == sharing_node)
        next_node_on_branch = NULL;
#endif /* TABLING */
      OPTYAP_ERROR_CHECKING(share_private_nodes, next_node_on_branch && YOUNGER_CP(next_node_on_branch, sharing_node));
    }

    /* initialize last or-frame pointer */
    or_frame = sharing_node->cp_or_fr;
    if (previous_or_frame) {
#ifdef TABLING
      OrFr_next_on_stack(previous_or_frame) =
#endif /* TABLING */
      OrFr_nearest_livenode(previous_or_frame) = OrFr_next(previous_or_frame) = or_frame;
    }

#ifdef TABLING
    /* update or-frames stored in auxiliary stack */
    while (STACK_NOT_EMPTY(stack, (CELL *)LOCAL_TrailTop)) {
      next_node_on_branch = (choiceptr) STACK_POP_DOWN(stack);
      or_frame = (or_fr_ptr) STACK_POP_DOWN(stack);
      OrFr_nearest_livenode(or_frame) = OrFr_next(or_frame) = next_node_on_branch->cp_or_fr;
    }
#endif /* TABLING */

    /* update depth */
    if (depth >= MAX_BRANCH_DEPTH)
      Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "maximum depth exceded (share_private_nodes)");
    or_frame = B->cp_or_fr;
#ifdef TABLING
    previous_or_frame = LOCAL_top_cp_on_stack->cp_or_fr;
    while (or_frame != previous_or_frame) {
#else
    while (or_frame != LOCAL_top_or_fr) {
#endif /* TABLING */
      unsigned int branch;
      if (OrFr_alternative(or_frame)) {
        branch = YAMOP_OR_ARG(OrFr_alternative(or_frame)) + 1;
      } else {
        branch = 1;
      }
      branch |= YAMOP_CUT_FLAG;  /* in doubt, assume cut */
      BRANCH(worker_id, depth) = BRANCH(worker_q, depth) = branch;
      OrFr_depth(or_frame) = depth--;
      or_frame = OrFr_next_on_stack(or_frame);
    }

    YAPOR_ERROR_CHECKING(share_private_nodes, depth != OrFr_depth(LOCAL_top_or_fr));

#ifdef DEBUG_OPTYAP
    { or_fr_ptr aux_or_fr = B->cp_or_fr;
      choiceptr aux_cp;
      while (aux_or_fr != LOCAL_top_cp_on_stack->cp_or_fr) {
        aux_cp = OrFr_node(aux_or_fr);
	OPTYAP_ERROR_CHECKING(share_private_nodes, OrFr_next(aux_or_fr) != aux_cp->cp_b->cp_or_fr);
	OPTYAP_ERROR_CHECKING(share_private_nodes, OrFr_nearest_livenode(aux_or_fr) != aux_cp->cp_b->cp_or_fr);
        aux_or_fr = OrFr_next_on_stack(aux_or_fr);
      }
      aux_or_fr = B->cp_or_fr;
      while (aux_or_fr != LOCAL_top_cp_on_stack->cp_or_fr) {
        or_fr_ptr nearest_leftnode = OrFr_nearest_leftnode(aux_or_fr);
        aux_cp = OrFr_node(aux_or_fr);
        while (OrFr_node(nearest_leftnode) != aux_cp) {
	  OPTYAP_ERROR_CHECKING(share_private_nodes, YOUNGER_CP(OrFr_node(nearest_leftnode), aux_cp));
          aux_cp = aux_cp->cp_b;
        }
        aux_or_fr = OrFr_next_on_stack(aux_or_fr);
      }
    }
#endif /* DEBUG_OPTYAP */

    /* update old shared nodes */
    while (or_frame != REMOTE_top_or_fr(worker_q)) {
      LOCK_OR_FRAME(or_frame);
      BRANCH(worker_q, OrFr_depth(or_frame)) = BRANCH(worker_id, OrFr_depth(or_frame));
#ifdef TABLING
      OrFr_owners(or_frame)++;
      if (BITMAP_member(OrFr_members(or_frame), worker_id))
#endif /* TABLING */
        BITMAP_insert(OrFr_members(or_frame), worker_q);
      UNLOCK_OR_FRAME(or_frame);
      or_frame = OrFr_next_on_stack(or_frame);
    }

    LOCK_OR_FRAME(REMOTE_top_or_fr(worker_q));
    or_fr_ptr old_top = REMOTE_top_or_fr(worker_q);
    Set_REMOTE_top_cp(worker_q,B);
    Set_LOCAL_top_cp(B);
    REMOTE_top_or_fr(worker_q) = LOCAL_top_or_fr = Get_LOCAL_top_cp()->cp_or_fr;
    UNLOCK_OR_FRAME(old_top);  

#ifdef TABLING
    /* update subgoal frames in the maintained private branches */
    sg_frame = LOCAL_top_sg_fr;
    while (sg_frame && YOUNGER_CP(SgFr_gen_cp(sg_frame), B)) {
      choiceptr top_cp_on_branch;
      top_cp_on_branch = SgFr_gen_cp(sg_frame);
      while (YOUNGER_CP(top_cp_on_branch, B)) {
        top_cp_on_branch = top_cp_on_branch->cp_b;
      }
      SgFr_gen_top_or_fr(sg_frame) = top_cp_on_branch->cp_or_fr;
      sg_frame = SgFr_next(sg_frame);
    }
    /* update worker Q top subgoal frame */
    REMOTE_top_sg_fr(worker_q) = sg_frame;
    /* update subgoal frames in the recently shared branches */
    while (sg_frame && YOUNGER_CP(SgFr_gen_cp(sg_frame), LOCAL_top_cp_on_stack)) {
      SgFr_gen_worker(sg_frame) = MAX_WORKERS;
      SgFr_gen_top_or_fr(sg_frame) = SgFr_gen_cp(sg_frame)->cp_or_fr;
      sg_frame = SgFr_next(sg_frame);
    }

    /* update dependency frames in the maintained private branches */
    dep_frame = LOCAL_top_dep_fr;
    while (YOUNGER_CP(DepFr_cons_cp(dep_frame), B)) {
      choiceptr top_cp_on_branch;
      top_cp_on_branch = DepFr_cons_cp(dep_frame);
      while (YOUNGER_CP(top_cp_on_branch, B)) {
        top_cp_on_branch = top_cp_on_branch->cp_b;
      }
      DepFr_top_or_fr(dep_frame) = top_cp_on_branch->cp_or_fr;
      dep_frame = DepFr_next(dep_frame);
    }
    /* update worker Q top dependency frame */
    REMOTE_top_dep_fr(worker_q) = dep_frame;
    /* update dependency frames in the recently shared branches */
    while (YOUNGER_CP(DepFr_cons_cp(dep_frame), LOCAL_top_cp_on_stack)) {
      DepFr_top_or_fr(dep_frame) = DepFr_cons_cp(dep_frame)->cp_or_fr;
      dep_frame = DepFr_next(dep_frame);
    }
#endif /* TABLING */

#ifdef DEBUG_OPTYAP
    { dep_fr_ptr aux_dep_fr = LOCAL_top_dep_fr;
      while(aux_dep_fr != GLOBAL_root_dep_fr) {
        choiceptr top_cp_on_branch;
        top_cp_on_branch = DepFr_cons_cp(aux_dep_fr);
        while (YOUNGER_CP(top_cp_on_branch, B)) {
          top_cp_on_branch = top_cp_on_branch->cp_b;
        }
	OPTYAP_ERROR_CHECKING(share_private_nodes, top_cp_on_branch->cp_or_fr != DepFr_top_or_fr(aux_dep_fr));
        aux_dep_fr = DepFr_next(aux_dep_fr);
      }
    }
#endif /* DEBUG_OPTYAP */

    /* update top shared nodes */
#ifdef TABLING
    REMOTE_top_cp_on_stack(worker_q) = LOCAL_top_cp_on_stack = 
#endif /* TABLING */
    REMOTE_top_cp(worker_q) = LOCAL_top_cp = B;
    REMOTE_top_or_fr(worker_q) = LOCAL_top_or_fr = LOCAL_top_cp->cp_or_fr;
  }

#ifdef TABLING_INNER_CUTS
  /* update worker Q pruning scope */
  if (LOCAL_pruning_scope && EQUAL_OR_YOUNGER_CP(LOCAL_top_cp, LOCAL_pruning_scope)) {
    REMOTE_pruning_scope(worker_q) = LOCAL_pruning_scope;
    PUT_IN_PRUNING(worker_q);
  } else {
    PUT_OUT_PRUNING(worker_q);
    REMOTE_pruning_scope(worker_q) = NULL;
  }
#endif /* TABLING_INNER_CUTS */

  /* update worker Q prune request */
  if (LOCAL_prune_request) {
    CUT_send_prune_request(worker_q, LOCAL_prune_request);
  }

  /* update load and return */
  REMOTE_load(worker_q) = LOCAL_load = 0;
  return;
}
Exemplo n.º 25
0
static struct writer_context_s *
create_writer (HANDLE fd)
{
  struct writer_context_s *ctx;
  SECURITY_ATTRIBUTES sec_attr;
  DWORD tid;

  TRACE_BEG (DEBUG_SYSIO, "gpgme:create_writer", fd);

  memset (&sec_attr, 0, sizeof sec_attr);
  sec_attr.nLength = sizeof sec_attr;
  sec_attr.bInheritHandle = FALSE;

  ctx = calloc (1, sizeof *ctx);
  if (!ctx)
    {
      TRACE_SYSERR (errno);
      return NULL;
    }
  
  ctx->file_hd = fd;
  ctx->refcount = 1;
  ctx->have_data = CreateEvent (&sec_attr, TRUE, FALSE, NULL);
  if (ctx->have_data)
    ctx->is_empty  = CreateEvent (&sec_attr, TRUE, TRUE, NULL);
  if (ctx->is_empty)
    ctx->stopped = CreateEvent (&sec_attr, TRUE, FALSE, NULL);
  if (!ctx->have_data || !ctx->is_empty || !ctx->stopped)
    {
      TRACE_LOG1 ("CreateEvent failed: ec=%d", (int) GetLastError ());
      if (ctx->have_data)
	CloseHandle (ctx->have_data);
      if (ctx->is_empty)
	CloseHandle (ctx->is_empty);
      if (ctx->stopped)
	CloseHandle (ctx->stopped);
      free (ctx);
      /* FIXME: Translate the error code.  */
      TRACE_SYSERR (EIO);
      return NULL;
    }

  ctx->is_empty = set_synchronize (ctx->is_empty);
  INIT_LOCK (ctx->mutex);

  ctx->thread_hd = CreateThread (&sec_attr, 0, writer, ctx, 0, &tid );
  if (!ctx->thread_hd)
    {
      TRACE_LOG1 ("CreateThread failed: ec=%d", (int) GetLastError ());
      DESTROY_LOCK (ctx->mutex);
      if (ctx->have_data)
	CloseHandle (ctx->have_data);
      if (ctx->is_empty)
	CloseHandle (ctx->is_empty);
      if (ctx->stopped)
	CloseHandle (ctx->stopped);
      free (ctx);
      TRACE_SYSERR (EIO);
      return NULL;
    }    
  else
    {
      /* We set the priority of the thread higher because we know
	 that it only runs for a short time.  This greatly helps to
	 increase the performance of the I/O.  */
      SetThreadPriority (ctx->thread_hd, get_desired_thread_priority ());
    }

  TRACE_SUC ();
  return ctx;
}
Exemplo n.º 26
0
/* fe is supposed to be locked */
Prop Yap_NewPredPropByFunctor(FunctorEntry *fe, Term cur_mod) {
  PredEntry *p = (PredEntry *)Yap_AllocAtomSpace(sizeof(*p));

  if (p == NULL) {
    WRITE_UNLOCK(fe->FRWLock);
    return NULL;
  }
  if (cur_mod == TermProlog || cur_mod == 0L) {
    p->ModuleOfPred = 0L;
  } else
    p->ModuleOfPred = cur_mod;
// TRUE_FUNC_WRITE_LOCK(fe);
  INIT_LOCK(p->PELock);
  p->KindOfPE = PEProp;
  p->ArityOfPE = fe->ArityOfFE;
  p->cs.p_code.FirstClause = p->cs.p_code.LastClause = NULL;
  p->cs.p_code.NOfClauses = 0;
  p->PredFlags = 0L;
  p->src.OwnerFile = Yap_source_file_name();
  p->OpcodeOfPred = UNDEF_OPCODE;
  p->CodeOfPred = p->cs.p_code.TrueCodeOfPred = (yamop *)(&(p->OpcodeOfPred));
  p->cs.p_code.ExpandCode = EXPAND_OP_CODE;
  p->TimeStampOfPred = 0L;
  p->LastCallOfPred = LUCALL_ASSERT;
  if (cur_mod == TermProlog)
    p->ModuleOfPred = 0L;
  else
    p->ModuleOfPred = cur_mod;
  Yap_NewModulePred(cur_mod, p);

#ifdef TABLING
  p->TableOfPred = NULL;
#endif /* TABLING */
#ifdef BEAM
  p->beamTable = NULL;
#endif /* BEAM */
  /* careful that they don't cross MkFunctor */
  if (!trueGlobalPrologFlag(DEBUG_INFO_FLAG)) {
    p->PredFlags |= NoTracePredFlag;
  }
  p->FunctorOfPred = fe;
  if (fe->PropsOfFE) {
    UInt hsh = PRED_HASH(fe, cur_mod, PredHashTableSize);

    WRITE_LOCK(PredHashRWLock);
    if (10 * (PredsInHashTable + 1) > 6 * PredHashTableSize) {
      if (!ExpandPredHash()) {
        Yap_FreeCodeSpace((ADDR)p);
        WRITE_UNLOCK(PredHashRWLock);
        FUNC_WRITE_UNLOCK(fe);
        return NULL;
      }
      /* retry hashing */
      hsh = PRED_HASH(fe, cur_mod, PredHashTableSize);
    }
    PredsInHashTable++;
    if (p->ModuleOfPred == 0L) {
      PredEntry *pe = RepPredProp(fe->PropsOfFE);

      hsh = PRED_HASH(fe, pe->ModuleOfPred, PredHashTableSize);
      /* should be the first one */
      pe->NextPredOfHash = PredHash[hsh];
      PredHash[hsh] = pe;
      fe->PropsOfFE = AbsPredProp(p);
      p->NextOfPE = AbsPredProp(pe);
    } else {
      p->NextPredOfHash = PredHash[hsh];
      PredHash[hsh] = p;
      p->NextOfPE = fe->PropsOfFE->NextOfPE;
      fe->PropsOfFE->NextOfPE = AbsPredProp(p);
    }
    WRITE_UNLOCK(PredHashRWLock);
  } else {
    fe->PropsOfFE = AbsPredProp(p);
    p->NextOfPE = NIL;
  }
  FUNC_WRITE_UNLOCK(fe);
  {
    Yap_inform_profiler_of_clause(&(p->OpcodeOfPred), &(p->OpcodeOfPred) + 1, p,
                                  GPROF_NEW_PRED_FUNC);
    if (!(p->PredFlags & (CPredFlag | AsmPredFlag))) {
      Yap_inform_profiler_of_clause(&(p->cs.p_code.ExpandCode),
                                    &(p->cs.p_code.ExpandCode) + 1, p,
                                    GPROF_NEW_PRED_FUNC);
    }
  }
  return AbsPredProp(p);
}
Exemplo n.º 27
0
void __objc_init_dispatch_tables ()
{
	INIT_LOCK(initialize_lock);
}
Exemplo n.º 28
0
void Yap_init_global(int max_table_size, int n_workers, int sch_loop, int delay_load) {
    int i;

    /* global data related to memory management */
#ifdef LIMIT_TABLING
    if (max_table_size)
        GLOBAL_MAX_PAGES = ((max_table_size - 1) * 1024 * 1024 / SHMMAX + 1) * SHMMAX / Yap_page_size;
    else
        GLOBAL_MAX_PAGES = -1;
#endif /* LIMIT_TABLING */
    INIT_PAGES(GLOBAL_PAGES_void, void *);
#ifdef YAPOR
    INIT_PAGES(GLOBAL_PAGES_or_fr, struct or_frame);
    INIT_PAGES(GLOBAL_PAGES_qg_sol_fr, struct query_goal_solution_frame);
    INIT_PAGES(GLOBAL_PAGES_qg_ans_fr, struct query_goal_answer_frame);
#endif /* YAPOR */
#ifdef TABLING_INNER_CUTS
    INIT_PAGES(GLOBAL_PAGES_tg_sol_fr, struct table_subgoal_solution_frame);
    INIT_PAGES(GLOBAL_PAGES_tg_ans_fr, struct table_subgoal_answer_frame);
#endif /* TABLING_INNER_CUTS */
#ifdef TABLING
#ifdef GLOBAL_TRIE
    INIT_PAGES(GLOBAL_PAGES_gt_node, struct global_trie_node);
    INIT_PAGES(GLOBAL_PAGES_gt_hash, struct global_trie_hash);
#endif /* GLOBAL_TRIE */
    INIT_PAGES(GLOBAL_PAGES_tab_ent, struct table_entry);
    INIT_PAGES(GLOBAL_PAGES_sg_fr, struct subgoal_frame);
    INIT_PAGES(GLOBAL_PAGES_sg_node, struct subgoal_trie_node);
    INIT_PAGES(GLOBAL_PAGES_ans_node, struct answer_trie_node);
    INIT_PAGES(GLOBAL_PAGES_sg_hash, struct subgoal_trie_hash);
    INIT_PAGES(GLOBAL_PAGES_ans_hash, struct answer_trie_hash);
    INIT_PAGES(GLOBAL_PAGES_dep_fr, struct dependency_frame);
#endif /* TABLING */
#if defined(YAPOR) && defined(TABLING)
    INIT_PAGES(GLOBAL_PAGES_susp_fr, struct suspension_frame);
#endif /* YAPOR && TABLING */

#ifdef YAPOR
    /* global static data */
    number_workers = n_workers;
    worker_pid(0) = getpid();
    for (i = 1; i < number_workers; i++) worker_pid(i) = 0;
    SCHEDULER_LOOP = sch_loop;
    DELAYED_RELEASE_LOAD = delay_load;

    /* global data related to or-performance */
    GLOBAL_number_goals = 0;
    GLOBAL_best_times(0) = 0;
    GLOBAL_performance_mode = PERFORMANCE_OFF;

    /* global data related to or-parallelism */
    BITMAP_clear(GLOBAL_bm_present_workers);
    for (i = 0; i < number_workers; i++)
        BITMAP_insert(GLOBAL_bm_present_workers, i);
    BITMAP_copy(GLOBAL_bm_idle_workers, GLOBAL_bm_present_workers);
    BITMAP_clear(GLOBAL_bm_root_cp_workers);
    BITMAP_clear(GLOBAL_bm_invisible_workers);
    BITMAP_clear(GLOBAL_bm_requestable_workers);
    BITMAP_clear(GLOBAL_bm_executing_workers);
    BITMAP_copy(GLOBAL_bm_finished_workers, GLOBAL_bm_present_workers);
    INIT_LOCK(GLOBAL_LOCKS_bm_idle_workers);
    INIT_LOCK(GLOBAL_LOCKS_bm_root_cp_workers);
    INIT_LOCK(GLOBAL_LOCKS_bm_invisible_workers);
    INIT_LOCK(GLOBAL_LOCKS_bm_requestable_workers);
    INIT_LOCK(GLOBAL_LOCKS_bm_executing_workers);
    INIT_LOCK(GLOBAL_LOCKS_bm_finished_workers);
#ifdef TABLING_INNER_CUTS
    INIT_LOCK(GLOBAL_LOCKS_bm_pruning_workers);
#endif /* TABLING_INNER_CUTS */
    GLOBAL_LOCKS_who_locked_heap = MAX_WORKERS;
    INIT_LOCK(GLOBAL_LOCKS_heap_access);
    INIT_LOCK(GLOBAL_LOCKS_alloc_block);
#if defined(YAPOR_ERRORS) || defined(TABLING_ERRORS)
    INIT_LOCK(GLOBAL_LOCKS_stderr_messages);
#endif /* YAPOR_ERRORS || TABLING_ERRORS */
    if (number_workers == 1)
        PARALLEL_EXECUTION_MODE = FALSE;
    else
        PARALLEL_EXECUTION_MODE = TRUE;
#endif /* YAPOR */

#ifdef TABLING
    /* global data related to tabling */
    GLOBAL_root_tab_ent = NULL;
#ifdef GLOBAL_TRIE
    new_global_trie_node(GLOBAL_root_gt, 0, NULL, NULL, NULL);
#endif /* GLOBAL_TRIE */
#ifdef LIMIT_TABLING
    GLOBAL_first_sg_fr = NULL;
    GLOBAL_last_sg_fr = NULL;
    GLOBAL_check_sg_fr = NULL;
#endif /* LIMIT_TABLING */
    GLOBAL_root_dep_fr = NULL;
    for (i = 0; i < MAX_TABLE_VARS; i++) {
        CELL *pt = GLOBAL_table_var_enumerator_addr(i);
        RESET_VARIABLE(pt);
    }
#ifdef TABLE_LOCK_AT_WRITE_LEVEL
    for (i = 0; i < TABLE_LOCK_BUCKETS; i++)
        INIT_LOCK(GLOBAL_table_lock(i));
#endif /* TABLE_LOCK_AT_WRITE_LEVEL */
#endif /* TABLING */

    return;
}
Exemplo n.º 29
0
/**
 * Initialize or reinitialize a PRNG state.
 *
 * @param st The state to initialize or reinitialize.
 * @param prf The configuration to use. (Ignored for reinit)
 * @return An OTTERY_ERR_* value (zero on success, nonzero on failure).
 */
static int
ottery_st_initialize(struct ottery_state *st,
                     const struct ottery_config *config,
                     int locked)
{
  const struct ottery_prf *prf = NULL;
  struct ottery_config cfg_tmp;
  int err;
  /* We really need our state to be aligned. If it isn't, let's give an
   * error now, and not a crash when the SIMD instructions start to fail.
   */
  if (((uintptr_t)st) & 0xf)
    return OTTERY_ERR_STATE_ALIGNMENT;

  if (!config) {
    ottery_config_init(&cfg_tmp);
    config = &cfg_tmp;
  }

  prf = config->impl;

  if (!prf)
    prf = ottery_get_impl(NULL);

  memset(st, 0, sizeof(*st));

  if (locked) {
    /* Now set up the spinlock or mutex or hybrid thing. */
    if (INIT_LOCK(&st->mutex))
      return OTTERY_ERR_LOCK_INIT;
  }

  /* Check invariants for PRF, in case we wrote some bad code. */
  if ((prf->state_len > MAX_STATE_LEN) ||
      (prf->state_bytes > MAX_STATE_BYTES) ||
      (prf->state_bytes > prf->output_len) ||
      (prf->output_len > MAX_OUTPUT_LEN))
    return OTTERY_ERR_INTERNAL;

  /* Check whether some of our structure size assumptions are right. */
  if ((sizeof(struct ottery_state) > OTTERY_STATE_DUMMY_SIZE_) ||
      (sizeof(struct ottery_config) > OTTERY_CONFIG_DUMMY_SIZE_))
    return OTTERY_ERR_INTERNAL;

  memcpy(&st->entropy_config, &config->entropy_config,
         sizeof(struct ottery_entropy_config));

  /* Copy the PRF into place. */
  memcpy(&st->prf, prf, sizeof(*prf));

  if ((err = ottery_st_reseed(st)))
    return err;

  /* Set the magic number last, or else we might look like we succeeded
   * when we didn't */
  st->magic = MAGIC(st);

  st->pid = getpid();

  return 0;
}
Exemplo n.º 30
0
void Yap_init_local_optyap_data(int wid) {
#if defined(YAPOR_THREADS) || defined(THREADS_CONSUMER_SHARING)
  CACHE_REGS
#endif /* YAPOR_THREADS || THREADS_CONSUMER_SHARING */

#if defined(TABLING) && (defined(YAPOR) || defined(THREADS))
/* local data related to memory management */
#ifdef YAPOR
  REMOTE_next_free_ans_node(wid) = NULL;
#elif THREADS
#ifdef USE_PAGES_MALLOC
  INIT_LOCAL_PAGE_ENTRY(REMOTE_pages_void(wid), void *);
#endif
  INIT_LOCAL_PAGE_ENTRY(REMOTE_pages_tab_ent(wid), struct table_entry);
#if defined(THREADS_FULL_SHARING) || defined(THREADS_CONSUMER_SHARING)
  INIT_LOCAL_PAGE_ENTRY(REMOTE_pages_sg_ent(wid), struct subgoal_entry);
#endif
  INIT_LOCAL_PAGE_ENTRY(REMOTE_pages_sg_fr(wid), struct subgoal_frame);
  INIT_LOCAL_PAGE_ENTRY(REMOTE_pages_dep_fr(wid), struct dependency_frame);
  INIT_LOCAL_PAGE_ENTRY(REMOTE_pages_sg_node(wid), struct subgoal_trie_node);
  INIT_LOCAL_PAGE_ENTRY(REMOTE_pages_sg_hash(wid), struct subgoal_trie_hash);
  INIT_LOCAL_PAGE_ENTRY(REMOTE_pages_ans_node(wid), struct answer_trie_node);
  INIT_LOCAL_PAGE_ENTRY(REMOTE_pages_ans_hash(wid), struct answer_trie_hash);
#if defined(THREADS_FULL_SHARING)
  INIT_LOCAL_PAGE_ENTRY(REMOTE_pages_ans_ref_node(wid), struct answer_ref_node);
#endif
  INIT_LOCAL_PAGE_ENTRY(REMOTE_pages_gt_node(wid), struct global_trie_node);
  INIT_LOCAL_PAGE_ENTRY(REMOTE_pages_gt_hash(wid), struct global_trie_hash);
#endif
#endif /* TABLING && (YAPOR || THREADS) */

#ifdef YAPOR
  /* local data related to or-parallelism */
  Set_REMOTE_top_cp(wid, (choiceptr)LOCAL_LocalBase);
  REMOTE_top_or_fr(wid) = GLOBAL_root_or_fr;
  REMOTE_load(wid) = 0;
  REMOTE_share_request(wid) = MAX_WORKERS;
  REMOTE_reply_signal(wid) = worker_ready;
#ifdef YAPOR_COPY
  INIT_LOCK(REMOTE_lock_signals(wid));
#endif /* YAPOR_COPY */
  Set_REMOTE_prune_request(wid, NULL);
  INIT_LOCK(REMOTE_lock(wid));
#endif /* YAPOR */

#ifdef TABLING
  /* local data related to tabling */
  REMOTE_top_sg_fr(wid) = NULL;
  REMOTE_top_dep_fr(wid) = NULL;
#ifdef YAPOR
  REMOTE_top_dep_fr(wid) = GLOBAL_root_dep_fr;
  Set_REMOTE_top_cp_on_stack(wid, (choiceptr)LOCAL_LocalBase); /* ??? */
  REMOTE_top_susp_or_fr(wid) = GLOBAL_root_or_fr;
#endif /* YAPOR */
#ifdef THREADS_CONSUMER_SHARING
  ThDepFr_terminator(GLOBAL_th_dep_fr(wid)) = 0;
  ThDepFr_next(GLOBAL_th_dep_fr(wid)) = wid;
  ThDepFr_state(GLOBAL_th_dep_fr(wid)) = working;
  INIT_LOCK(ThDepFr_lock(GLOBAL_th_dep_fr(wid)));
#endif /* THREADS_CONSUMER_SHARING */
#endif /* TABLING */
  return;
}