Exemplo n.º 1
0
/* JAVADOC COMMENT ELIDED */
KNIEXPORT KNI_RETURNTYPE_VOID
    Java_com_sun_j2me_location_PlatformLocationProvider_resetImpl() {

    MidpReentryData *info = NULL;
    ProviderInfo *pInfo = NULL;
    jint provider = KNI_GetParameterAsInt(1);
    jsr179_result res;

    info = (MidpReentryData*)SNI_GetReentryData(NULL);
    if (info == NULL) {
        /* reset provider */
        res = jsr179_update_cancel((jsr179_handle)provider);
        switch (res) {
            case JSR179_STATUSCODE_OK:
            case JSR179_STATUSCODE_FAIL:
                break;
            case JSR179_STATUSCODE_INVALID_ARGUMENT:
                /* wrong provider name */
                KNI_ThrowNew(midpIllegalArgumentException, "wrong provider");
                break;
            case JSR179_STATUSCODE_WOULD_BLOCK:
                /* wait for javanotify */
                pInfo = getProviderInfo(provider);
                if(pInfo != NULL) {
                    pInfo->locked = KNI_FALSE;
                }
                lock_thread(JSR179_EVENT_UPDATE_ONCE, provider);
                break;
            default:
                break;
        }
    }

    KNI_ReturnVoid();
}
Exemplo n.º 2
0
void		*malloc(int size)
{
  t_header	*tmp;
  int		total_size;

  if (size <= 0)
    return (NULL);
  lock_thread();
  if ((size % sizeof(int)) != 0)
    size += (sizeof(int) - (size % sizeof(int)));
  if ((tmp = (t_header *)findFreeBlock(size)) == NULL)
    tmp = (t_header *)getMoreMem(size + sizeof(*tmp));
  else
    {
      if (tmp->size - size >= THRESHOLD)
	{
	  total_size = tmp->size + sizeof(*tmp);
	  tmp->size = size;
	  split_mid(tmp, total_size);
	}
      deleteFromFreeList(tmp);
    }
  unlock_thread();
  if (tmp == NULL)
    return (NULL);
  return ((void *)((int)tmp + sizeof(*tmp)));
}
Exemplo n.º 3
0
int64_t xpl_thread_get_and_reset_calls(xpl_thread_id tid) {
    assert(ctx);
    assert(tid);
    assert(tid < ctx->thread_pool_size);
    
    int64_t result = 0L;
    
    lock_thread(tid);
    result = ctx->thread_pool[tid].calls;
    ctx->thread_pool[tid].calls = 0L;
    unlock_thread(tid);
    
    return result;
}
Exemplo n.º 4
0
int test_and_set_thread_state(xpl_thread_id tid, int condition, int value) {
    assert(ctx);
    assert(tid >= 0);
    assert(tid < ctx->thread_pool_size);

    lock_thread(tid);
    
    int result = ctx->thread_pool[tid].state;
    if (result & condition) {
        ctx->thread_pool[tid].state = value;
        result = value;
    }
    
    unlock_thread(tid);
    return result;
}
Exemplo n.º 5
0
/* JAVADOC COMMENT ELIDED */
KNIEXPORT KNI_RETURNTYPE_BOOLEAN
    Java_com_sun_j2me_location_PlatformLocationProvider_waitForNewLocation() {

    jboolean ret = KNI_FALSE;
    MidpReentryData *info = NULL;
    ProviderInfo *pInfo = NULL;
    jsr179_result res;
    jint provider;
    jlong timeout;
    KNI_StartHandles(1);
    provider = KNI_GetParameterAsInt(1);
    timeout = KNI_GetParameterAsLong(2);
    pInfo = getProviderInfo(provider);
    if(pInfo != NULL) {
        info = (MidpReentryData*)SNI_GetReentryData(NULL);
        if (info == NULL) {
            /* First call -request */
            if(pInfo->locked == KNI_TRUE) {
                lock_thread(JSR179_EVENT_UPDATE_ONCE, provider);
            } else {
                /* request new location */
                res = jsr179_update_set((jsr179_handle)provider, timeout);
                switch (res) {
                    case JSR179_STATUSCODE_WOULD_BLOCK:
                        /* wait for javanotify */
                        pInfo->locked = KNI_TRUE;
                        lock_thread(JSR179_EVENT_UPDATE_ONCE, provider);
                        break;
                    case JSR179_STATUSCODE_OK:
                        /* location updated successfully */
                        pInfo->locked = KNI_FALSE;
			            pInfo->newLocationAvailable = KNI_TRUE;
                        ret = KNI_TRUE;
                        break;
                    case JSR179_STATUSCODE_FAIL:
                        /* fail */
                        pInfo->locked = KNI_FALSE;
                        /* wrong provider name */
                        KNI_ThrowNew(midpIllegalArgumentException, 
                                    "wrong provider");
                        break;
                    default:
                        /* fail */
                        pInfo->locked = KNI_FALSE;
                        break;
                }
            }
        } else {
            /* Response */
            if (info->status == JSR179_STATUSCODE_OK) {
                /* location updated successfully */
				pInfo->newLocationAvailable = KNI_TRUE;
                ret = KNI_TRUE;
            } else {
                /* location updated failed */
                ret = KNI_FALSE;
            }
            pInfo->locked = KNI_FALSE;
        }
    }
    KNI_EndHandles();
    KNI_ReturnBoolean(ret);
}
Exemplo n.º 6
0
/* JAVADOC COMMENT ELIDED */
KNIEXPORT KNI_RETURNTYPE_INT
    Java_com_sun_j2me_location_PlatformLocationProvider_open() {

    MidpReentryData *info = NULL;
    ProviderInfo *pInfo = NULL;
    jsr179_result res;
    jsr179_handle pProvider = NULL;
    jint provider = 0;
    
    KNI_StartHandles(1);
    GET_PARAMETER_AS_PCSL_STRING(1, name)
    info = (MidpReentryData*)SNI_GetReentryData(NULL);
    if (info == NULL) {
        res = jsr179_provider_open(name, &pProvider);
        switch (res) {
            case JSR179_STATUSCODE_OK:
                /* handler returned immediatelly */
                provider = (jint)pProvider;
                register_provider(provider);
                break;
            case JSR179_STATUSCODE_INVALID_ARGUMENT:
                /* wrong provider name */
                KNI_ThrowNew(midpIllegalArgumentException, 
                            "wrong provider name");
                break;
            case JSR179_STATUSCODE_FAIL:
                /* fail */
                KNI_ThrowNew(midpIOException, "open failed");
                break;
            case JSR179_STATUSCODE_WOULD_BLOCK:
                /* wait for javanotify */
                provider = (jint)pProvider;
                pInfo = register_provider(provider);
                if (pInfo != NULL) {
                    pInfo->locked = KNI_TRUE;
                }
                lock_thread(JSR179_EVENT_OPEN_COMPLETED, provider);
                break;
            default:
                break;
        }
    } else {
        /* Second call for this thread - finish open */
        if (info->status == JSR179_STATUSCODE_OK) {
            /* Provider opened successfully */
            provider = info->descriptor;
            pInfo = getProviderInfo(provider);
            if (pInfo != NULL) {
                pInfo->locked = KNI_FALSE;
            }
        } else {
            /* Provider open failed*/
            unregister_provider(provider);
            provider = 0;
        }
    }

    RELEASE_PCSL_STRING_PARAMETER
    KNI_EndHandles();
    KNI_ReturnInt(provider);
}