how to set mutex can be shared between different process.

by waterblood » Tue, 03 Mar 2009 08:27:18 GMT


Sponsored Links
 Hi All,

   Usually we use  pthread_mutexattr_setpshared to share different
mutex with different process. But I have checked the bionic libc
implementation. It only support PTHREAD_PROCESS_PRIVATE setting.
Does it mean android does not support mutex shared between different
processes?

pthread.c in android/bionic/libc/bionic

772 int pthread_mutexattr_setpshared(pthread_mutexattr_t *attr, int
pshared)
 773 {
 774     if (!attr)
 775         return EINVAL;
 776
 777     return (pshared == PTHREAD_PROCESS_PRIVATE) ? 0 : ENOTSUP;
 778 }


Thanks
Guoyin Chen
--~--~---------~--~----~------------~-------~--~----~



how to set mutex can be shared between different process.

by Freepine » Wed, 04 Mar 2009 13:58:29 GMT


 Perhaps you can try to use a semaphore file instead?





--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


how to set mutex can be shared between different process.

by Dave Sparks » Thu, 05 Mar 2009 07:44:17 GMT


 What is the use case for a shared mutex?

We use shared mutex for IPC shared process memory. See AudioTrack/
AudioFlinger for sample code. In the case, the sharing works because
the mutex is in the shared memory and both process have access to it.



--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Failed binder transaction when passing byte[] (from camera) between intents

Hi, I have a problem with an app that lets the user take a picture.
I've posted it on some forums already, but nobody seems to recognize
the problem. Hopefully someone here knows a solution :)

I've put the code of taking a picture in a seperate activity. Then I
call the camera intent from my main activity using activityForResult.
In the camera intent, I use putExtra to return the camera image (as a
byte[] without doing anything to it). But when the program transitions
back from the camera intent to the parent intent that called it I get
a Failed Binder Transaction error in the logcat because the byte[] is
too big. But I don't understand this, because the image is not even
taken using the maximum resolution :S

The code of my camera intent is:

package example.imaging.ape;

import java.io.IOException;
import java.util.Iterator;
import java.util.Set;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.PixelFormat;
import android.hardware.Camera;
import android.hardware.Camera.AutoFocusCallback;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnTouchListener;

public class TakePicture extends Activity implements
SurfaceHolder.Callback{
     Camera mCamera;
     Boolean mPreviewRunning = false;
     int imageLayoutHeight;
     int imageLayoutWidth;

     @Override
     public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);

          //setup camera surface
          getWindow().setFormat(PixelFormat.TRANSLUCENT);
          requestWindowFeature(Window.FEATURE_NO_TITLE);
 
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
          setContentView(R.layout.cameralayout);

          SurfaceView mSurfaceView = (SurfaceView)
findViewById(R.id.hist_surface_camera);
          SurfaceHolder mSurfaceHolder = mSurfaceView.getHolder();
          mSurfaceHolder.addCallback(this);
 
mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
          Bundle extras = getIntent().getExtras();
          imageLayoutHeight = extras.getInt("layoutHeight");
          imageLayoutWidth = extras.getInt("layoutWidth");

          OnTouchListener touchListener = new View.OnTouchListener() {
               public boolean onTouch(View v, MotionEvent e) {

                    System.out.println("MAKING PICTURE");
                    mCamera.autoFocus(cb);
                    return false;
               }
          };

          //setup touch listener
          mSurfaceView.setOnTouchListener(touchListener);

     }

     AutoFocusCallback cb = new AutoFocusCallback() {
          public void onAutoFocus(boolean success, Camera c) {
               c.takePicture(null, null, mPictureCallback);
          }
     };

     Camera.PictureCallback mPictureCallback = new
Camera.PictureCallback() {
          public void onPictureTaken(byte[] imageData, Camera c) {
               System.out.println("Picture taken, now
returning");
               Intent resultIntent = new Intent();
               resultIntent.putExtra("cameraImage", imageData);
               System.out.println("put Extra");
               setResult(Activity.RESULT_OK, resultIntent);
               finish();
          }
     };

     //initialize camera
     public void surfaceCreated(SurfaceHolder holder) {
          mCamera = Camera.open();
     }

     public void surfaceChanged(SurfaceHolder holder, int format, int
w, int h) {
          if (mPreviewRunning) {
               mCamera.stopPreview();
          }

          Camera.Parameters p = mCamera.getParameters();

          p.setPreviewSize(h, w);
          System.out.println("PreviewSize: " + h + "," + w);
          p.setPictureSize(h*3,w*3); // is around 1200x900
          p.set("rotation", 90);
          mCamera.setParameters(p);

          try {
               mCamera.setPreviewDisplay(holder);
          } catch (IOException e) {
               e.printStackTrace();
          }

          mCamera.startPreview();
          mPreviewRunning = true;
     }

     public void surfaceDestroyed(SurfaceHolder holder) {
          mCamera.stopPreview();
          mPreviewRunning = false;
          mCamera.release();
     }

}

And this is how I call the camera activity:

Intent intent = new Intent(mainActivity.this, TakePicture.class);
intent.putExtra("layoutWidth",layoutWidth);
intent.putExtra("layoutHeight",layoutHeight);
startActivityForResult(intent,0);

The onActivityResult is never reached because the error occurs during
the transition between intents.

-- 

2. username and password for sample sync adapter

Hello,

I just got the sample sync adapter code running on the emulator, but
how do I add account in it when it asks for username and password?

And I have the following questions

1) SampleSyncAdapter is for 2.0 and in 2.0 emulator I don't see the
Accounts & Sync options in the Settings, am I missing anything?
 -- so for this I compiled this app in 2.1 and ran on 2.1 emulator

2) In 2.0 emulator when I launch Accounts option from Contact app, it
crashes? I saw this a raised bug, is this solved?

-- 

3. Help with sound app - optimizing

4. Italics clipped in widget

5. Detecting if there is a screen unlock pattern?

6. XMPP event synchronization for multiplayer game development

7. Android Emulator 2.1: Setting HTTP Proxy